//fonctionnalite info-bulle
afficherInfoBulle = function(e){
	var text = $(this).next('.ipb');
	if(text.attr('class') != 'ipb') return false;
	text.fadeIn().css('top', e.pageY).css('left', e.pageX+10);
	return false;
};
cacherInfoBulle = function(e){
	var text = $(this).next('.ipb');
	if(text.attr('class') != 'ipb') return false;
	text.fadeOut();
};
installationInfoBulle = function(){
	$('.ipb').each( function(){
		$(this)
		.after($('<span>').attr('class', 'ipb_content').html($(this).attr('title')))
		.attr('title', '');
	}).hover(afficherInfoBulle, cacherInfoBulle);
};
closePopin = function(){
	var $popin	= $("div#popin");
	var $popinVoile	= $("div#popinVoile");
	
	$popin.fadeOut();													//fermeture de la popin
	$popinVoile.fadeOut();
	$("div#guide div").each( function(index){ $(this).show();});	//reaffiche les flash
};

 $(document).ready( function(){
	//installationInfoBulle();  
    
	//test du cookie sittomat
	var noCookie = true;
	var allCookies = document.cookie.split(";"); //alert(allCookies.length);
	for(var i=0; i<allCookies.length; i++){
		//alert("'"+allCookies[i]+"'");
		if(allCookies[i].replace(/^\s+|\s+$/g,"") == "popinSittomatCookie=psc") noCookie = false;
	}
	//alert($("div#popin"));
		
    if(noCookie) {
	//if($("div#popin") && $("div#popinVoile") && (	$(location).attr('href') == "http://www.sittomat.fr/" || $(location).attr('href') == "http://sittomat.fr/") && noCookie){
		
        //creation du cookie
		//document.cookie = 'popinSittomatCookie=psc; expires=Thu, 28 Nov 2012 23:59:59 UTC; path=/; domain=sittomat.fr';
        document.cookie = 'popinSittomatCookie=psc; expires=time()+3600*24; path=/; domain=sittomat.fr';
		
		//--- URL sur laquelle rediriger le visiteur
		//var $URL_REDIR = "http://www.sittomat.fr/actualites/a-la-une/avec-le-sittomat-amenez-votre-papier.html";
		var $popin	= $("div#popin");
		var $popinVoile	= $("div#popinVoile");

		$("div#guide div").each( function(index){ $(this).hide(); });	//masque les flash pour eviter toute superposition

		$popinVoile.show();
		$popin.fadeIn('slow');	// slow || fast
		
		$popin.mouseover( function(event){
			$popin.css( "cursor", "pointer");
		});
		
		$popin.click( function(event){
			var $target = $(event.target);
			
			closePopin();
			
			//else $(location).attr(	'href', $URL_REDIR);	//redirection vers le detail de l'info
		});

		$popinVoile.click( function(event){	closePopin();
			//$popin.hide();		//fermeture de la popin
			//$popinVoile.hide();	//fermeture de la popin
		});
        return false;
		
		//window.setTimeout('closePopin()', 8000);
	}
});

