$(document).ready(function() {
	$("div#collapse a").click(function() {
		$('#sidebar').toggle('slow');   
		$('#content').hasClass("contentBgShow") ? $('#content').addClass("contentBgHide").removeClass("contentBgShow") : $('#content').addClass("contentBgShow").removeClass("contentBgHide");
		$('#main').hasClass("mainWidthSmall") ? $('#main').addClass("mainWidthLarge").removeClass("mainWidthSmall") : $('#main').addClass("mainWidthSmall").removeClass("mainWidthLarge");
		$(this).toggleClass("hide");
	});
	
	$("#fontsize").css({display:"none"});
	
	$("#tools").click(function() {
		$("#fontsize").toggle('slow');
		return false;
	});
	
	// Reset Font Size
	 var originalFontSize = $('html').css('font-size');
	   $(".resetFont").click(function(){
	   $('html').css('font-size', originalFontSize);
	 });
	 
	   // Increase Font Size
	 $(".increaseFont").click(function(){
	   var currentFontSize = $('html').css('font-size');
	   var currentFontSizeNum = parseFloat(currentFontSize, 10);
	   var newFontSize = currentFontSizeNum*1.2;
	   $('html').css('font-size', newFontSize);
	   return false;
	 });
	 
	 // Decrease Font Size
	 $(".decreaseFont").click(function(){
	   var currentFontSize = $('html').css('font-size');
	   var currentFontSizeNum = parseFloat(currentFontSize, 10);
	   var newFontSize = currentFontSizeNum*0.8;
	   $('html').css('font-size', newFontSize);
	   return false;
	 });
	  
	 // push homepage
	 $("#myController").jFlow({
		 slides: "#mySlides",
		width: "99%",
		height: "280px",
		duration: 400
	  });
	  
	  // header message pour IE
		var Advert = LireCookie('avertissementIE');
		if (Advert != 1) {
			$("div#headerMessage").show();
			setTimeout("efface('#headerMessage')",20000);
			EcrireCookie("avertissementIE", "1");
		}	
		
		// sondage
		/*
		$('form#poll').submit(function(){
			
			$('form#poll').hide();
			$('#waitBloc').show();
			
			$(this).ajaxSubmit({
				success: function(responseText, responseCode) {				
					setTimeout(function(){
						$('#waitBloc').hide();
					}, 2000);
					$('#ajax-save-message').hide().html(responseText).fadeIn();
					setTimeout(function(){
						$('#ajax-save-message').fadeOut();
					}, 1000);					
					setTimeout(function(){
						$('#response').fadeIn();
					}, 2000);
				}
			});
			return false;
		});
		*/
		
		
		$('form#poll').submit(function(){
			$('#waitBloc').show();
			$(this).ajaxSubmit({
				success: function(responseText, responseCode) {				
					$('form#poll').hide();
					$('a#ShowPollResults').parent().hide();
					
					setTimeout(function(){
						$('#waitBloc').hide();
					}, 500);
					//$('#ajax-save-message').hide().html(responseText).fadeIn();
					setTimeout(function(){
						$('#ajax-save-message').hide().html(responseText).fadeIn();
					}, 1000);
				}
			});
			return false;
		});
		
		$('a#ShowPollResults').click(function(){
			$('form#poll').toggle();
			$('#results').toggle();
			if ($(this).html() == "Voir les stats") {
				$(this).html('Masquer');
			}
			else {
				$(this).html('Voir les stats');
			}
		});

});



function efface(id) {
	$(id).hide('slow');
}

// from http://www.actulab.com/
function EcrireCookie(nom, valeur) {
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function LireCookie(nom) {
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
	var j=i+alen;
	if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
	i=document.cookie.indexOf(" ",i)+1;
	if (i==0) break;
	
	}
	return null;
}

function EffaceCookie(nom) {
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	EcrireCookie(nom,null,date);
}
