$(document).ready(function(){

	cookie_posts_visited = GetCookie("visited_posts");
	if(!cookie_posts_visited){
		SetCookie("visited_posts", 0 , 0, "/", "www.espace-blanc.ch");
	}else{
		id_post = $("#post_id").html();
		if(id_post){
			cookie_posts_visited = GetCookie("visited_posts");
			new_cookie_posts_visited = ""+cookie_posts_visited+","+id_post+"";
			SetCookie("visited_posts", new_cookie_posts_visited , 0, "/", "www.espace-blanc.ch");
		}
	} 
	
	$(".cookyable").each(function() {
		cookie_posts_visited = GetCookie("visited_posts");
		if(cookie_posts_visited){
			array_id = cookie_posts_visited.split(",");
			post_id = $(this).attr("id");
		 	array_id_element = post_id.split("_");
		   	the_id = array_id_element[1];
			for(id_visited in array_id){
				if(array_id[id_visited] == the_id){
					$(this).children(".hover_project_home").addClass("hover_project_home_block");
					$(this).children(".hover_project_home").removeClass("hover_project_home");
					$(this).children("img").attr("src","http://www.espace-blanc.ch/wp-content/themes/eb/images/hover.png");
				}
			}
		}
  	});
    	
  	$("a.habitation_project").hover(
	  function () {
	    $(this).children(".hover_project_home").fadeIn(200);
	  }, 
	  function () {
	    $(this).children(".hover_project_home").fadeOut(200);
	  }
	);

	
	cat = $("#cat").html();
	if(cat == "R"){
		$(".page-item-8").addClass("current_page_item");
	}
	if(cat == "P"){
		$(".page-item-10").addClass("current_page_item");
	}
	
	$('#page_description').jScrollPane({
			showArrows: true,
			maintainPosition: true,
			stickToBottom: false,
			stickToRight: false,
			autoReinitialise: true,
			autoReinitialiseDelay: 500,
			verticalDragMinHeight: 0,
			verticalDragMaxHeight: 99999,
			horizontalDragMinWidth: 0,
			horizontalDragMaxWidth: 99999,
			contentWidth: 'undefined',
			animateScroll: false,
			animateDuration: 300,
			animateEase: 'linear',
			hijackInternalLinks: false,
			verticalGutter: 0,
			horizontalGutter: 0,
			mouseWheelSpeed: 16,
			arrowButtonSpeed: 16,
			arrowRepeatFreq: 100,
			arrowScrollOnHover: false,
			verticalArrowPositions: 'split',
			horizontalArrowPositions: 'split',
			enableKeyboardNavigation: true,
			hideFocus: false,
			clickOnTrack: true,
			trackClickSpeed: 30,
			trackClickRepeatFreq: 100
		}
	);

});

function SetCookie ( name, value, expires, path, domain, secure) {
	szCookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = szCookie;
}

function GetCookie (name) {
	if ( document.cookie) {
		index_cookie = document.cookie.indexOf(name);
		if ( index_cookie != -1) {
			nDeb = (document.cookie.indexOf( "=", index_cookie) + 1);
			nFin = document.cookie.indexOf( ";", index_cookie);
			if (nFin == -1) {nFin = document.cookie.length;}
			return unescape(document.cookie.substring(nDeb, nFin));
		}
	}
	return null;
}
