$(document).ready(function(){
	
	$(function () {
			
	
//////////When you look at me ... I completely disappear
		$("#top").find("input").each(function(){
			$(this).focus(function () {
				$(this).val("");
			});
		});

//////////open links in external window
		$('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
   		 });

//////////Cookie monster just around the corner
		function setCookie(name,value,expiredays){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/;domains=";
		}
		
		function getCookie(c_name){
			if (document.cookie.length>0){
			  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){ 
				    c_start=c_start + c_name.length+1; 
				    c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
			    } 
			}
		return "";
		}
		

		 
		 
//////////Make me bigger or smaller, I don't care		
		
		// Original Font Size
		var originalFontSize = $('#mainContent').css('font-size');
		if ($.browser.msie) {
			var originalFontSize = parseInt(originalFontSize, 10);
		}
		$(".resetFont").click(function(){
			$('#mainContent').css('font-size', originalFontSize);
			setCookie('textSize',""+ originalFontSize + "",365);
			return false;
		});
		
		var getSizeCookie = getCookie("textSize");
		if(getSizeCookie!=null && getSizeCookie!=""){
			var getSizeCookieNum = parseInt(getSizeCookie, 10);
			$('#mainContent').css('font-size', getSizeCookieNum);
		};
		
		// Increase Font Size
		$(".increaseFont").click(function(){
			var currentFontSize = $('#mainContent').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('#mainContent').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		// Decrease Font Size
		$(".decreaseFont").click(function(){
			var currentFontSize = $('#mainContent').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('#mainContent').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		
		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});
			

		
//////////Tell me where i'm going
		$("a[rel='3m4il']").each(function(){
			var spaceShip = $(this).text();
			var spaceStation = $(this).attr('href');
			
			$(this).attr({
				href: 'mailto:'+ spaceShip +'@'+ spaceStation +'',
				rel: 'nofollow'
			});
			$(this).text(''+ spaceShip +'@'+ spaceStation +'');
		});
		
//////////Please help me J.J. Abrams i'm lost...
		if($("#siteMap").length !=0) {
			$("#siteMap").treeview({
				collapsed: false,
				animated: "medium",
				control:"#expandCollapse",
				persist: "location"
			});
		};

		
//////////// homepage slideshow
		$('.slideshow').cycle({
				fx: 'scrollLeft', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				timeout: 8000
			});
			
/////////// colobox
		$("a[rel='popup']").colorbox();


////////////////////////// equal height
/*function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

equalHeight($(".equalCol"));*/


///////////////// remplacement des liens
		//en
		$(".page-item-163 a:first, .page-item-32 a:first, .page-item-102 a:first, .page-item-146 a:first, .page-item-486 a:first").removeAttr('href');
		
		
////////////hide partners bos
		if ( $('body').attr('id') == 164 || $('body').attr('id') == 263){
			$('#partnerBox').css("display", "none");
		};	
		
		
////////////////////////////////////////// pop up partenaires
		function imagePreview (){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = -230;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' /></p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
	};
	
	
	// starting the script on page load
	$(document).ready(function(){
		imagePreview();
	});
		
		
		
		
	});	
});

