$(document).ready(function() {
	
	$(".blank").attr("target", "_blank");
		
	$('.nospam').each(function(){
		var sEmail = $(this).html();
		sEmail = sEmail.replace("[arobase]","@");
		sEmail = sEmail.replace("[point]",".");
		$(this).html("<a href=\"mailto:" + sEmail + "\">" + sEmail + "</a>");
	});
	
	//GESTION DU SYSTEME DE SCROOL
	
	//Affichage de l'ancre pour le haut de page
	$('<div class="go_top"><a href="#">top</a></div>').appendTo('body');
	$(window).scroll(function() {
		
		var iScrollTop = $(document).scrollTop();
		if(iScrollTop > 0) { $('.go_top').show(); } else { $('.go_top').hide(); }		 
	});
				
	var speed = 1000; //Vitesse de déplacement
	    
	$('a[href^="#"]').bind('click',function() {
	    		    
		var sAncre = $(this).attr('href');
	    
		if(sAncre == '#') { goTo('body'); }
	    else { goTo(sAncre); }
	    
		return(false);
	});
	
	function goTo(sAncre) {
	    	
		$('html,body').animate({scrollTop: $(sAncre).offset().top}, speed, 'swing', function() {
			
			if(sAncre != 'body') { window.location.hash = sAncre; }
			else { window.location.hash = '#'; }
			$(sAncre).attr('tabindex','-1');
	        $(sAncre).focus();
	        $(sAncre).removeAttr('tabindex');
		});
	}
	
	
	jQuery.extend({
		get_host: function() { 
	  		var sHost = window.location.host;
	  		var sHref = window.location.href;
	  		
	  		if(sHref.indexOf("/backoffice/", 0) > 0) { var sBack = "backoffice/"; } else { var sBack = ""; }	  		
	  		
	  		if(sHost == "127.0.0.1") { var sHostToReturn =  "http://" + sHost + "/www.besoin-de-conseils.com/" + sBack; }
	  		else { var sHostToReturn =  "http://" + sHost + "/" + sBack; }
	  			  		
	  		return sHostToReturn; 
		},
		is_back: function() { 
	  		var sHost = window.location.host;
	  		var sHref = window.location.href;
	  		
	  		if(sHref.indexOf("/backoffice/", 0) > 0) { return 1; } else { return 0; } 
		},
		get_surface_ecran: function() {
			
			var iScreenWidth, iPageHeight;
			
			// firefox is ok
			iPageHeight = document.documentElement.scrollHeight;
			iScreenWidth = document.documentElement.scrollWidth;
			
			// now IE 7 + Opera with "min window"
			if ( document.documentElement.clientHeight > iPageHeight ) { iPageHeight  = document.documentElement.clientHeight; }
			if ( document.documentElement.clientWidth > iScreenWidth ) { iScreenWidth  = document.documentElement.clientWidth; }
			
			// last for safari
			if ( document.body.scrollHeight > iPageHeight ) { iPageHeight = document.body.scrollHeight; }
			if ( document.body.scrollWidth > iScreenWidth ) { iScreenWidth = document.body.scrollWidth; }
			
			return  {
				screenWidth: iScreenWidth, 
				screenHeight: screen.height,
				pageHeight: iPageHeight
			};
		},
		same_height: function(oElement) {
			
			var aHeights = [];
			$(oElement).each(function(){ aHeights.push( $(this).height() ); });
			var iMaxHeight = Math.max.apply(null, aHeights);
			$(oElement).css( {'height': iMaxHeight + 'px'} );
		}
	});	
	
	$.fn.tagName = function() {
	   return this.get(0).tagName.toLowerCase();
	}
});
