(function ($){
	$.fn.scrolling = function(direction,options){
		var opts = $.extend({}, $.fn.scrolling.defaults, options);		
				
		return this.each(function() {		
			var $this = $(this);
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
			if(direction == 'down'){
				var dec = o.move;
			} else if(direction == 'up'){
				var dec = -o.move;	
			}
			var target = $this.scrollTop() + dec;					
			$this.animate({scrollTop: target}, o.speed, o.easing);      
		});				
	}
	
	$.fn.scrolling.defaults = {
		move: 40,
		speed: "normal",
		easing: "linear"
	}
	
})(jQuery); 




$(document).ready(function() {   	
	
   $("#global").append('<div class="clearfooter"></div>');        
   $(".center980").append('<div id="cadran"></div>');
   $("ul.menu-bas li:first").css('border-width',0);
   $("ul.menu-bas li:first").css('padding-left',0);
   
	$(".menuhaut li").hover(function(){    	
		$(".menuhaut li.current").addClass('excurrent');
		$(".menuhaut li.current").removeClass('current');
	},function(){
		$(".menuhaut li.excurrent").addClass('current');
		$(".menuhaut li.excurrent").removeClass('excurrent');
	});
	
	if($("#heb-p").height() < 250){
		$("#scrolldown").css('display','none');
		$("#scrollup").css('display','none');
	}    
		
	
	$("#scrolldown").click(function(){
		$("#heb-p").scrolling('down',{move:120});
		return false;
	});
	$("#scrollup").click(function(){
		$("#heb-p").scrolling('up',{move:120});
		return false;
	});
    
    $("a[rel='nofollow']").click(function(){
        if($(this).attr('href') != '#'){
            window.open($(this).attr('href'));
            return false;
        }
    });
	
	
	$(".box-redac").each(function(){		
		$(this).css("overflow",'hidden');
		$(this).css("height",$(this).parent().css("height"));		
	});
	
	
	//initialisation des pages
	var basehref = 'http://www.la-boite-immo.com/';
	
	//sites cle en main
	var firstitem_cle = 4;	
	var cle_table = new Array();
	var mod_table = new Array();
	var perso_table = new Array();
	var reso_table = new Array();
			
	$.ajax({
				type: "GET",
				url: basehref+"xml/references.xml",
				dataType: "xml",
				success: function(xml) {				
	
					var tabs1 = $('/references/site[type="cle"]',xml);
					tabs1.each(function(i){
						var tab = new Array($(this).find('nom').text(),$(this).find('url').text(),basehref+$(this).find('imgpath').text());				
						cle_table.push(tab);					
					});		
					
					var tabs2 = $('/references/site[type="mod"]',xml);

					tabs2.each(function(i){
						var tab = new Array($(this).find('nom').text(),$(this).find('url').text(),basehref+$(this).find('imgpath').text());				
						mod_table.push(tab);					
					});	
					
					var tabs3 = $('/references/site[type="perso"]',xml);

					tabs3.each(function(i){
						var tab = new Array($(this).find('nom').text(),$(this).find('url').text(),basehref+$(this).find('imgpath').text());				
						perso_table.push(tab);					
					});			
					
					
					var tabs4 = $('/references/site[type="reso"]',xml);

					tabs4.each(function(i){
						var tab = new Array($(this).find('nom').text(),$(this).find('url').text(),basehref+$(this).find('imgpath').text());				
						reso_table.push(tab);					
					});		
									
				}
			}); // fin ajax
	
	//fonction de modification des references
	$("#navig-cle").click(function(){		 
				
			var i = 1;
			while(i < 5){
				if(firstitem_cle >= cle_table.length) firstitem_cle = firstitem_cle - cle_table.length;				
				$("#pan-cle-"+i+" span.nom").text(cle_table[firstitem_cle][0]);
				$("#pan-cle-"+i+" a").attr('href',cle_table[firstitem_cle][1]);
				$("#pan-cle-"+i+" img").attr('src',cle_table[firstitem_cle][2]);
				firstitem_cle++;								
				i++;
			}

	});
	
	$("#navig-prev-cle").click(function(){		 		
		//on va chercher notre fichier xml		


			truefirst_cle = firstitem_cle - 4;
			var i = 4;
			while(i > 0){
				truefirst_cle--;
				firstitem_cle--;				
				if(truefirst_cle < 0){
					truefirst_cle = cle_table.length + truefirst_cle;
					firstitem_cle = truefirst_cle + 4;
				}				
				$("#pan-cle-"+i+" span.nom").text(cle_table[truefirst_cle][0]);
				$("#pan-cle-"+i+" a").attr('href',cle_table[truefirst_cle][1]);
				$("#pan-cle-"+i+" img").attr('src',cle_table[truefirst_cle][2]);				
				i--;
			}

	});
	
	//sites modulables
	var firstitem_mod = 4;	


	//fonction de modification des references
	$("#navig-mod").click(function(){		 
		//alert('origine:'+pagecle);
		//on va chercher notre fichier xml
			var i = 1;
			while(i < 5){
				if(firstitem_mod >= mod_table.length) firstitem_mod = firstitem_mod - mod_table.length;				
				$("#pan-mod-"+i+" span.nom").text(mod_table[firstitem_mod][0]);
				$("#pan-mod-"+i+" a").attr('href',mod_table[firstitem_mod][1]);
				$("#pan-mod-"+i+" img").attr('src',mod_table[firstitem_mod][2]);
				firstitem_mod++;								
				i++;
			}

	});
	
	$("#navig-prev-mod").click(function(){		 		
		//on va chercher notre fichier xml		


			truefirst_mod = firstitem_mod - 4;
			var i = 4;
			while(i > 0){
				truefirst_mod--;
				firstitem_mod--;				
				if(truefirst_mod < 0){
					truefirst_mod = mod_table.length + truefirst_mod;
					firstitem_mod = truefirst_mod + 4;
				}				
				$("#pan-mod-"+i+" span.nom").text(mod_table[truefirst_mod][0]);
				$("#pan-mod-"+i+" a").attr('href',mod_table[truefirst_mod][1]);
				$("#pan-mod-"+i+" img").attr('src',mod_table[truefirst_mod][2]);				
				i--;
			}

	});
	
	
	//sites persoulables
	var firstitem_perso = 4;	


	
	//fonction de persoification des references
	$("#navig-perso").click(function(){		 

			var i = 1;
			while(i < 5){
				if(firstitem_perso >= perso_table.length) firstitem_perso = firstitem_perso - perso_table.length;				
				$("#pan-perso-"+i+" span.nom").text(perso_table[firstitem_perso][0]);
				$("#pan-perso-"+i+" a").attr('href',perso_table[firstitem_perso][1]);
				$("#pan-perso-"+i+" img").attr('src',perso_table[firstitem_perso][2]);
				firstitem_perso++;								
				i++;
			}

	});
	
	$("#navig-prev-perso").click(function(){		 		
		//on va chercher notre fichier xml		

			truefirst_perso = firstitem_perso - 4;
			var i = 4;
			while(i > 0){
				truefirst_perso--;
				firstitem_perso--;				
				if(truefirst_perso < 0){
					truefirst_perso = perso_table.length + truefirst_perso;
					firstitem_perso = truefirst_perso + 4;
				}				
				$("#pan-perso-"+i+" span.nom").text(perso_table[truefirst_perso][0]);
				$("#pan-perso-"+i+" a").attr('href',perso_table[truefirst_perso][1]);
				$("#pan-perso-"+i+" img").attr('src',perso_table[truefirst_perso][2]);				
				i--;
			}

	});
	
	

	var firstitem_reso = 4;	
	//fonction de resoification des references
	$("#navig-reso").click(function(){		 

			var i = 1;
			while(i < 5){
				if(firstitem_reso >= reso_table.length) firstitem_reso = firstitem_reso - reso_table.length;				
				$("#pan-reso-"+i+" span.nom").text(reso_table[firstitem_reso][0]);
				$("#pan-reso-"+i+" a").attr('href',reso_table[firstitem_reso][1]);
				$("#pan-reso-"+i+" img").attr('src',reso_table[firstitem_reso][2]);
				firstitem_reso++;								
				i++;
			}

	});
	
	$("#navig-prev-reso").click(function(){		 		
		//on va chercher notre fichier xml		

			truefirst_reso = firstitem_reso - 4;
			var i = 4;
			while(i > 0){
				truefirst_reso--;
				firstitem_reso--;				
				if(truefirst_reso < 0){
					truefirst_reso = reso_table.length + truefirst_reso;
					firstitem_reso = truefirst_reso + 4;
				}				
				$("#pan-reso-"+i+" span.nom").text(reso_table[truefirst_reso][0]);
				$("#pan-reso-"+i+" a").attr('href',reso_table[truefirst_reso][1]);
				$("#pan-reso-"+i+" img").attr('src',reso_table[truefirst_reso][2]);				
				i--;
			}

	});
         
});