$(document).ready(function()
	{
	$(function () {
		
//////////Tell me where i'm going

		$("a[rel='3m4il']").each(function(){
		     var spaceShip = $(this).text();
		     var spaceStation = $(this).attr('href');
		
		     $(this).replaceWith('<a href="mailto:'+ spaceShip +'@'+ spaceStation +'">'+ spaceShip +'@'+
		spaceStation +'</a>');
		});
			
//////////When you pass over me, I'm shining like the sun
		$('#mainMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(350, 1);
			}, function () {
				$img.stop().fadeTo(750, 0);
			});
		});

//////////open links in external window
		$('A[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
   		 });
   		 
////////////Last one doesent get a piece of the cake
		$('.articleSeparator:last').remove();
		
////////////rollOvers des btn
		$("a.bgMout").hover(
			function () {
		  		$(this).toggleClass("bgMover");
			},
			function () {
				$(this).removeClass("bgMover");
				$(this).addClass("bgMout");
		});
		
		$("a.yellowBtn").hover(
			function () {
		  		$(this).addClass("hover");
				$(this).find('span').addClass("hover");
			},
			function () {
				$(this).removeClass("hover");
				$(this).find('span').removeClass("hover");
		});		
		
//////////// Faque jQuery Flash Banner
//////////slide me up and down
	$(".control").css('display','none');
		$("#flash-container-wrapper, #containerFlash").hover(function(){
				$(".control").css('display','none').slideDown('fast');
			},function(){
				$(".control").css('display','block').slideUp('fast');
			});
		
		var getSliderCookie = getCookie("sliderSize");
		if(getSliderCookie!=null && getSliderCookie!=""){
			var getSliderCookie = parseInt(getSliderCookie, 10);
			$('#flash-container-wrapper, #containerFlash').height(getSliderCookie);
		};
		
		var sizeOri = 290;
		var sizeNew = 172;
		var classOri = 'up';
		var classNew = 'down';
		
		if (getSliderCookie == 172) {
			var sizeOri = 172;
			var sizeNew = 290;
			var classOri = 'down';
			var classNew = 'up';
		};
		
		$(".toggle").addClass(classOri);
		$(".toggle").toggle(function(){
			$("#flash-container-wrapper, #containerFlash").animate({
       			height:sizeNew
			},
    		500,
    		"swing",
    		function(){
    			$(".toggle").removeClass(classOri);
    			$(".toggle").addClass(classNew);
    			setCookie('sliderSize',sizeNew,365);
			});
			
		},function(){
			$("#flash-container-wrapper, #containerFlash").animate({
       			height:sizeOri
			},
    		500,
    		"swing",
    		function(){
    			$(".toggle").removeClass(classNew);
    			$(".toggle").addClass(classOri);
    			setCookie('sliderSize',sizeOri,365);
			});
			
		});
		
		$('#bannerFlash').cycle({ 
		    fx:       'uncover', 
		    speed:    1000,
		    next:     '.next', 
    		prev:	  '.prev',
			pause:    1,
			timeout:  10000
		 });
		 
		 $('#snoopyNews').cycle({ 
		    fx:       'fade',
		    speed:    250,
		    next:     '.nextS', 
    		prev:	  '.prevS',
			pause:    0,
			timeout:  0
		 });


//////////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 = $('.resizableText').css('font-size');
		if ($.browser.msie) {
			var originalFontSize = parseInt(originalFontSize, 10);
		}
		$(".resetFont").click(function(){
			$('.resizableText').css('font-size', originalFontSize);
			setCookie('textSize',""+ originalFontSize + "",365);
			return false;
		});
		
		var getSizeCookie = getCookie("textSize");
		if(getSizeCookie!=null && getSizeCookie!=""){
			var getSizeCookieNum = parseInt(getSizeCookie, 10);
			$('.resizableText').css('font-size', getSizeCookieNum);
		};
		
		// Increase Font Size
		$(".increaseFont").click(function(){
			var currentFontSize = $('.resizableText').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('.resizableText').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		// Decrease Font Size
		$(".decreaseFont").click(function(){
			var currentFontSize = $('.resizableText').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('.resizableText').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});


////////////Print this page
		$("#print").click(function(){
			window.print();
		});

/////////////////Load la google map
		if ($('#contact-details-google-map').length != 0) {
		$.getScript(
			"/wp-content/themes/Construction_DJL/js/google-maps.js",
			function(){
				initialize();
			});
		};
		if ($('#nos-regions-google-map').length != 0) {
		$.getScript(
			"/wp-content/themes/Construction_DJL/js/google-maps.js",
			function(){
				initialize();
			});
		};
		
////////////////Scroll my paine

		$('#pane1').jScrollPane();
		
/////////////// Christophe colomb will now find me
		
		$("#siteMap").treeview({
			collapsed: false,
			animated: "medium",
			control:"#expandCollapse",
			persist: "location"
		});
		
///////////////// Am I even or Odd
		$(".liste-offres-demplois tr:even").css("background-color", "#F0ECE0");
		$('.offres-results tr:even').css("background-color", "#F0ECE0");
		$('.offres-results tr:last').css("background-color", "#fff");
				
//////////let's go snoopie can you get me the latest news
	if ($('#snoopyNews').length != 0) {
		
		//var newsUrl = 'http://www.djl.ca/newsajax-fr';
		//if ($('body').attr("id") == 'langue_en'){
		//	newsUrl = 'http://www.djl.ca/en/newsajax-en';
		//}
		
		//$.get('' + newsUrl + '', function(xml){
		//	
		// 	$(xml).find('news').each(function(){
		// 		var date = $(this).find('date').text();
		// 		var title = $(this).find('title').text();
		// 		var link = $(this).find('link').text();
		// 		var txt = $(this).find('txt').text();
		// 		
		// 		//alert('Date:'+ date);
		// 	});
		// 	
		//	//alert('data loaded ' + xml )//optional stuff to do after get;
		//},'xml');
		
		
		
//		var news = $('#snoopyNews');
//		
//		news.addClass('-1');
//		$.ajaxSetup ({  
//		    cache: false  
//		}); 
//		var currentId = news.attr('class');
//		var prevId = '';
//		var nextId = '';
//		var ajaxLoading = '<img src=""/>';
//		var newsUrl = 'http://www.djl.ca/newsajax-fr?offset=';
//		if ($('body').attr("id") == 'langue_en'){
//			newsUrl = 'http://www.djl.ca/en/newsajax-en?offset=';
//		}
//		
//		function checkValNews(){
//			currentId = news.attr('class');
//			prevId = parseInt(currentId,10) - 1;
//			nextId = parseInt(currentId,10) + 1;
//		};
//		
//		function updateValNews(whichOne){
//			if(whichOne == 'nextId') {
//				news.attr('class', nextId );
//			}else if(whichOne == 'prevId'){
//				news.attr('class', prevId );
//			}else{
//				return false;
//			};
//		};
//		
//		function getNews(id,whereIGo){
//
//			$.ajax({
//			  url: newsUrl+id+'',
//			  //type: 'GET',
//			  //dataType: 'html',
//			  //processData: false,
//			
//			  complete: function() {
//			  	//alert(html);
//			    //news.append(html);
//			  },
//			
//			  success: function(html) {
//			  	if (html !='') {
//			  		news.empty();
//			  		news.append(html);
//			    	updateValNews(whereIGo);
//					checkPreviousNews(id-2);
//					checkNextNews(id+1);
//			  	};
//			  	
//			 },
//			
//			  error: function() {
//			   // alert('sorry there\'s an error.');
//			  }
//			});
//			
//			
//			
//		};
//		
//		function checkPreviousNews(id){
//
//			$.ajax({
//			  url: newsUrl+id+'',
//			  //type: 'GET',
//			  //dataType: 'html',
//			  //processData: false,
//			
//			  complete: function() {
//			  	//alert(html);
//			    //news.append(html);
//			  },
//			
//			  success: function(html) {
//			  	if (html =='') {
//					$('#upArrow').css("visibility", "hidden");
//			  	}else{
//					$('#upArrow').css("visibility", "visible");
//				};
//			  	
//			 },
//			
//			  error: function() {
//			    alert('sorry there\'s an error.');
//			  }
//			});
//			
//		};
//		
//		function checkNextNews(id){
//
//			$.ajax({
//			  url: newsUrl+id+'',
//			  //type: 'GET',
//			  //dataType: 'html',
//			  //processData: false,
//			
//			  complete: function() {
//			  	//alert(html);
//			    //news.append(html);
//			  },
//			
//			  success: function(html) {
//			  	if (html =='') {
//					$('#downArrow').css("visibility", "hidden");
//			  	}else{
//					$('#downArrow').css("visibility", "visible");
//				};
//			  	
//			 },
//			
//			  error: function() {
//			    alert('sorry there\'s an error.');
//			  }
//			});
//			
//		};
//		
//		
//
//		
//		checkValNews();
//		getNews('0','nextId');
//		checkPreviousNews('1');
//		checkNextNews('1');
//
//		
//		$('#downArrow').click(function(){
//			checkValNews();
//			getNews(nextId+'','nextId');
//			return false;
//			
//
//		});
//		$('#upArrow').click(function(){
//			checkValNews();
//			if (currentId == 0) {
//				return false;
//			};
//			getNews(prevId+'','prevId');
//			return false;
//		});
		
			
		};
	});	
});
