/** Stylesheet switcher based on work by Kelvin Luck ( http://www.kelvinluck.com/ ) **/


// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
// /cookie functions



function switchStylestyle(styleName) {
  $('link[@rel*=style][title]').each(function(i) {
	 this.disabled = true;
	 if (this.getAttribute('title') == styleName) this.disabled = false;
  });
  createCookie('style', styleName, 365);
}

$(function(){
	$("#navtop li:last").addClass("last");
	$("#contenu a[href^=#p]").bind("click", function(){
		href = $(this).attr("href");
		href = href.substring(1);
		sp1.showPanel(href); 
		return false;												 
	})
	z = 10;
	$(".col_calendrier").each(function(){
		$(this).css("z-index", z)
		z--;
	});
	
	// ajoute le tooltip avec le contenu dans le em	
	
	// patchage
	/*$(".col_calendrier").addClass("calendrier");*/
	
	var ids = 0;
	$(".calendrier").each(function(){
		$(this).attr("rel", "id"+ids);
		ids++;
	});
	ids = 0;
	$(".tooltip").each(function(){
		$(this).attr("rel", "id"+ids);
		ids++;
	});
	
	$(".jours a", this).bind("mouseenter", function(){												
		var toolt = $("em span[class]",this).clone();
		var pos = $(this).position();
		var h = $(this).height();
		var w = $(this).width();
		
		var toolid = $(this).parents(".calendrier").attr("rel");	
		$(".tooltip[rel="+toolid+"]").html(toolt);
		$(".tooltip[rel="+toolid+"]").css("left", Math.round(pos.left+w));
		$(".tooltip[rel="+toolid+"]").css("top", Math.round(pos.top+h));
	});
	//enleve le tooltip
	$(".jours a").bind("mouseleave", function(){ $(".tooltip").css("left", "-99999px"); });



	$(".datagrid_calendrier tr td:first-child a").bind("mouseenter", function(){
	
		//$(this).after("<div id='tool2'>"+this.rel+"</div>");
		console.log("test");
	});









	$('.styleswitch').click(function() { switchStylestyle(this.getAttribute("rel")); return false; });
	var c = readCookie('style');
	if (c) switchStylestyle(c);
	
	$("#slider_contenu")
		.before('<a class="prevBtn" style="visibility: hidden;" href="#" onclick="sp1.showPreviousPanel(); return false;">Precedent</a>')
		.after('<a class="nextBtn" href="#" onclick="sp1.showNextPanel(); return false;">Suivant</a>');
	
	$("#slider_contenu .SlidingPanelsContent").css("float", "left");
	$("#calendrier_slider .SlidingPanelsContent").css("float", "left");
});

