/* ********************************************************************************* NECESSAIRE POUR LES PUB */
ord=Math.random()*10000000000000000;

/* ********************************************************************************* GOOGLE */
function google_ad_request_done(google_ads) {
	if (google_ads.length < 1 )
		return;
		var s = '';
		s += '<ul class="googleLinks cf">';
		if (google_ads[0].type == 'text') {
			for(i = 0; i < google_ads.length; ++i) {
				s += '<li class="googleAnnonce">' + '<span class="title"><a target="_blank" href=\'' + google_ads[i].url + '\'" onmouseover="window.status=\'Go to ' + google_ads[i].visible_url + '\'" onmouseout="window.status=\'\'">' + google_ads[i].line1 + '</a></span>' + '<span class="data">' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '<br></span>' + '<span class="link"><a style="" target="_blank" href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' + google_ads[i].visible_url + '\';return true">' + google_ads[i].visible_url + '</span></a></li>';
			}
		}
		s += '</ul>';
		document.write(s);
	return;
}

/* ********************************************************************************* HOVER CLASSE POUR IE6 */
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};


/* ********************************************************************************* OPEN/CLOSE NAV PROVISOIRE */
openNavProv = function() {
	$('.navProvOC a').click(function() {	
		if($(this).html()=='fermer la nav') {
			$(this).html('ouvrir la nav');	
		}
		else {
			$(this).html('fermer la nav');
		}		
		$('.navProvContent').animate({height: "toggle"}, 100);
		return false;		
	});
}

/* ********************************************************************************* FOCUS CHAMPS NEWSLETTER */
swapNews = function() { swapValues=[]; $(".swapValue").each(function(i){swapValues[i]=$(this).val();$(this).focus(function(){if($(this).val()==swapValues[i]){$(this).val("")}}).blur(function(){if($.trim($(this).val())==""){$(this).val(swapValues[i])}})});};


/* ********************************************************************************* SOUS MENU */
$(document).ready(function(){

  var isHttps = window.location.href;
  
	$("#menu-ul li").hover(function() {
  
    if (isHttps.indexOf('https://payment') == -1)	{
		  $(".sub", this).show();
		  }else{
      $(".sub", this).hide();
      }
		  
	}, function() { 
		$(".sub", this).hide();
	});
	if (document.all) {
		$("#menu-ul li").hoverClass ("current");
	}

});


/* ********************************************************************************* ACTU3 */
function switchActus() {
	if( jQuery("#actu3").length < 1 )
	return false;
	
	$('.actu3-a').show();
	$('.actu3-b').hide();
	$('.actu3-c').hide();
	
	var showCurrent = jQuery("#shows .current");
	$('#shows li').mouseover ( function(){
										
		if(showCurrent) {
			if(showCurrent.size()==1) {
				showCurrent.removeClass("current");
				$(this).addClass("current");
				showCurrent = $(this);
			}
		}
	});
	
	$('.show-a').mouseover( function() {
		$('.actu3-a').show();
		$('.actu3-b').hide();
		$('.actu3-c').hide();
	});
	$('.show-b').mouseover( function() {
		$('.actu3-a').hide();
		$('.actu3-b').show();
		$('.actu3-c').hide();
	});
	$('.show-c').mouseover( function() {
		$('.actu3-a').hide();
		$('.actu3-b').hide();
		$('.actu3-c').show();
	});
}

/* ********************************************************************************* PAGER TODAY */
function pagerToday() {		
    $('#today').pager('ul');
};

/* ********************************************************************************* PAGER PHOTO DECO */
function pagerPhotoUp() {		
    if( jQuery("#photoPagerUp").length < 1 )
		return false;

	$('#photoPagerUp').show();	
	$('.photoUp-2,.creditUp-2').hide();
	$('.photoUp-3,.creditUp-3').hide();
	$('.photoUp-1,.creditUp-1').show();	
	$('#photoPagerUp .nav').show();
	
	var showCurrent = jQuery(".nav .current");
	$('.nav a').mouseover ( function(){
										
		if(showCurrent) {
			if(showCurrent.size()==1) {
				showCurrent.removeClass("current");
				$(this).addClass("current");
				showCurrent = $(this);
			}
		}
	});
	
	$('.choice-1').mouseover( function() {
		$('.photoUp-1,.creditUp-1').show();
		$('.photoUp-2,.creditUp-2').hide();
		$('.photoUp-3,.creditUp-3').hide();
	});
	$('.choice-2').mouseover( function() {
		$('.photoUp-1,.creditUp-1').hide();
		$('.photoUp-2,.creditUp-2').show();
		$('.photoUp-3,.creditUp-3').hide();
	});
	$('.choice-3').mouseover( function() {
		$('.photoUp-1,.creditUp-1').hide();
		$('.photoUp-2,.creditUp-2').hide();
		$('.photoUp-3,.creditUp-3').show();
	});
};
/* ********************************************************************************* TABS PHOTO FICHE */
function tabsConst() {
	if( jQuery(".divTabs").length < 1 )
	return false;

	$('.divTabs').tabs(1);
	
}

/* ********************************************************************************* SCROLL PANE PHOTO FICHE */
function scrollProd() {
	if( jQuery("#scrollerProd").length < 1 )
		return false;	
	$('#scrollerProd').jScrollPane();	
}
/* ********************************************************************************* OUVERTURE NOTEZONE */
function note1() {
	if( jQuery(".notation").length < 1 )
	return false;
	
	$('.noteZone').hide();
	$('.noteClic').click( function() {
		$(this).parent().children('.noteZone').show();
        if($(this).html() == "notez cette photo")
        {
            val = LireCookie('photo_'+$('#id_photo_note').val());
            if(val == "1")
            {
                $(this).parent().children('.noteZone').html('Vous avez déjà voté pour cette photo !');
                
            }
        }
        if($(this).html() == "notez cet article")
        {
            val = LireCookie('article_'+$('#id_fiche').val());
            if(val == "1")
            {
                $(this).parent().children('.noteZone').html('Vous avez déjà voté pour cet article !');
                
            }
        }
		return false;
	});
	$('.closeNoteZone').click( function() {
		$(this).parent().hide();
		return false;
	});
};

/* ********************************************************************************* CURSEUR NOTE */
var clicked = false;
var clicked2 = false;
		//var clicked3 = false;
		//var clicked4 = false;


function jenote() {
	if( jQuery(".tetRight .noteZone").length < 1 )
	return false;

	$('.tetRight .note2 span a')
		.mouseout(function(){ 
			 if (clicked == false) { 
				$(this).parent().removeClass();
			 }
		})
		.mouseover(function(){ 
			if (clicked == false) {
				 var index = $(this).parent().children('a').index(this)+1;
				 $(this).parent().removeClass().addClass('note-'+index);
			}
		})
		.click(function(){
			 if (clicked == false) {								
				$(this).parents('.tetRight .noteZone').children('p').html('Merci pour votre vote,<br />la note attribuée est'); // ARTICLE
				var index = $('.tetRight .note2 span a').index(this)+1;
				$(this).parent().removeClass().addClass('note-'+index);
				valider_note(index);
			 }
			 clicked = true;
             EcrireCookie('article_'+$('#id_fiche').val(), 1);
			 return false;
		});
};

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 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 jenote2() {
	if( jQuery(".noteItemZone .noteZone").length < 1 )
	return false;

	$('.noteItemZone .note2 span a')
		.mouseout(function(){ 
			 if (clicked2 == false || clicked2 != $('#id_photo_note').val()) { 
				$(this).parent().removeClass();
			 }
		})
		.mouseover(function(){ 
			if (clicked2 == false || clicked2 != $('#id_photo_note').val()) {
				 var index2 = $(this).parent().children('a').index(this)+1;
				 $(this).parent().removeClass().addClass('note-'+index2);
			}
		})
		.click(function(){
			 if (clicked2 == false || clicked2 != $('#id_photo_note').val()) {								
				$(this).parents('.noteItemZone .noteZone').children('p:eq(0)').html('Merci pour votre vote,<br />la note de cette photo est'); // PHOTO
				var index2 = $('.noteItemZone .note2 span a').index(this)+1;
				$(this).parent().removeClass().addClass('note-'+index2);
				valider_note2(index2);
			 }
			 //clicked2 = true;
             clicked2 = $('#id_photo_note').val();
             EcrireCookie('photo_'+$('#id_photo_note').val(), 1);
			 return false;
		});
};


/* ********************************************************************************* CAROUSEL VIDEO UP */
function carVideoUp() {
	if( jQuery("#videoUp2 > ul").length < 1 )
		return false;
		
	jQuery('#videoUp2 > ul').jcarousel( { scroll: 1 } );
		/*{ initCallback: carousel1_init }*/	
	
	function carousel1_init() {
		$('.jcarousel-list').show()/*css("left","0px")*/;
	}
}

/* ********************************************************************************* CAROUSEL OBJET */

function itemLoadCallbackFunction(carousel, state) {
}

function carObjet() {
	if( jQuery("#carouObjet > ul").length < 1 )
		return false;
		
	if (document.all) {
		$("#carouObjet li a").hoverClass ("carouItemOver");
	}
	
	jQuery('#carouObjet > ul').jcarousel({
		scroll: 6,
		itemLoadCallback: itemLoadCallbackFunction
	});
}

/* ********************************************************************************* MORE OVER IE */
function moreOverIE() {
	if( jQuery(".forumReactLittle").length < 1 )
		return false;		
	if (document.all) {
		$(".forumReactLittle .more").hoverClass ("moreOver");
	}
}

/* ********************************************************************************* CAROUSEL PHOTO */
function carPhoto() {
	if( jQuery("#carouPhoto > ul").length < 1 )
		return false;
		
	if (document.all) {
		$("#carouPhoto li a").hoverClass ("carouItemOver");
	}
	
	jQuery('#carouPhoto > ul').jcarousel({
		scroll: 6,
		itemLoadCallback: itemLoadCallbackFunction
	});
}

function carListVideo() {
		if( jQuery(".videosListCarousel > ul").length < 1 )
		return false;
		jQuery('.videosListCarousel > ul').jcarousel({ vertical: true });
}

/* ********************************************************************************* FLASH VIDEO UP */
function flashVideoUp() {
	if( jQuery("#videoUp").length < 1 )
		return false;
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("/swf/300-261.swf", "videoUp", "300", "261", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);	
}

/* ********************************************************************************* CAROUSEL AVANT APRES */
function carAvantApres() {
	if( jQuery("#avantApres > ul").length < 1 )
		return false;
		
	jQuery('#avantApres > ul').jcarousel( { scroll: 2 } );
		/*{ initCallback: carousel1_init }*/
	
	function carousel1_init() {
		$('.jcarousel-list').show()/*css("left","0px")*/;
	}
}

/* ********************************************************************************* CAROUSEL EMI VIDEOS */
function carEmiVideos() {
	if( jQuery("#emiVideos > ul").length < 1 )
		return false;
		
	jQuery('#emiVideos > ul').jcarousel( { scroll: 4 } );
		/*{ scroll: 4, initCallback: carousel1_init }*/

	function carousel1_init() {
		$('.jcarousel-list').show()/*css("left","0px")*/;
	}
}

/* ********************************************************************************* PUB ALONE */
function pubAlone() {
	
	if( jQuery("#biz").length < 1 )
		return false;
		
	if (jQuery("#biz .partner").length == 0)
		jQuery("#biz .pub").addClass("alone");
}

/* ********************************************************************************* OVER MARQUE */
function overMarque() {
	if( jQuery("#marques").size() < 1 )
		return false;	
	
	jQuery(".blMarque li a").mouseover(function(){
		jQuery(this).parents(".blMarque").children(".inner").children(".cf").children(".visu").children("img").attr("src", jQuery( this ).attr("alt"));
	});	
}

/* ********************************************************************************* SAME HEIGHT 012 */
function setHeight() {
	if( jQuery("#emiList").size() < 1 )
		return false;
	                      
	var heightBlockMax=0;
	$('#emiList li').each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); }); // get max height
	$('#emiList li').each(function(){ $(this).css("height",heightBlockMax+"px"); }); // assign max height
	heightBlockMax=0;
}

/* ********************************************************************************* SAME HEIGHT 127 */
function setHeight2() {
	if( jQuery("#resultObjetZone").size() < 1 )
		return false;
	                      
	var heightBlockMax2=0;
	$('#resultObjetZone li').each(function(){ if( $(this).height() > heightBlockMax2 ) heightBlockMax2 = $(this).height(); }); // get max height
	$('#resultObjetZone li').each(function(){ $(this).css("height",heightBlockMax2+"px"); }); // assign max height
	heightBlockMax2=0;
}

/* ********************************************************************************* COMMENTAIRES */
function switchFormComment() {
	if( jQuery("#comment").size() < 1 )
		return false;
	
	$('#line2 .splitL').hide();
	$('#line2 .splitR').hide();
	$('#line3').hide();
	
	$('#compteYes').click(function(){
		$('#line2 .splitL, #line3').show();
		$('#line2 .splitR').hide();
	});
	$('#compteNo').click(function(){
		$('#line2 .splitR, #line3').show();
		$('#line2 .splitL').hide();
	});
}

/* ********************************************************************************* AJOUT A LA NEWSLETTER */
function addToNewsletter() {
	var email = $('#adress').val();
	
	$.ajax({
		type : 'GET',
		url : '/include/ajax.php',
		data : 'ajax=addToNewsletter&email='+escape(email),
		success : function(msg) {
			if(msg == 'ok') {
				$('#adress').val('votre e-mail');
				alert('Merci, votre inscription à bien été prise en compte');
			} else {
				alert(msg);
			}
		}
	});
}



function count_fiche(id,type) {
    var dateheure = new Date();
	var tsad=dateheure.getTime();
	$('body').append('<img src="/fiche/fiche_count.php?id='+id+'&type='+type+'&x='+tsad+'" />');
}

function affiche_dossier_sommaire(id_dossier) {
	$('.greyZone').load('/include/ajax.php?ajax=affiche_dossier_sommaire',{id_dossier:id_dossier});
}

/* ********************************************************************************* APPEL DES FONCTIONS */
$(document).ready(function() {	
	initCarObjet = carObjet();								// carousel objet
	initCarPhoto = carPhoto();								// carousel photo
	initScrollProd = scrollProd();							// scroll pane produits
	/*initNavProv = openNavProv();							// navigation provisoire - a supprimer en ligne*/
	initSwapNews = swapNews();								// champs newsletter
	initSwitchActus = switchActus();						// switch actus (page accueil)
	initPagerToday = pagerToday();							// pager bloc aujourd'hui (page accueil)
	initPubAlone = pubAlone();								// class alone sur la pub du header
	initFlashVideoUp = flashVideoUp();						// flash vidéo up
	initCarAvantApres = carAvantApres();					// carousel avant après
	initCarEmiVideos = carEmiVideos();						// carousel videos de l'emission
	initPagerPhotoUp = pagerPhotoUp();						// pager photo
	initOverMarque = overMarque();							// over marque
	initCarVideoUp = carVideoUp();							// carousel vidéo up
	initSetHeight = setHeight();							// meme hauteur D012
	initSetHeight2 = setHeight2();							// meme hauteur D127
	initSwitchFormComment = switchFormComment();			// switch formulaire content
	initNote1 = note1();									// open notation tetiere
	initJeNote = jenote();									// je note
	initJeNote2 = jenote2();								// je note 2
		//	initJeNote3 = jenote3();								// je note 3
		//	initJeNote4 = jenote4();								// je note 4

initTabsConst = tabsConst();							// tabs
	initMoreOverIE = moreOverIE();							// bug ie6 lien over dans little forum
	goM6();
});

/**
 * Permet l'affichage du logo de retour à m6.fr en fonction
 */ 
function goM6() {
	if(/m6\.fr/.test(document.referrer)) {
		setCookie(document, 'goM6', document.referrer);
	}

	if(link = getCookie('goM6')) {
		$('#goM6').attr('href', link).show();
	}
}

setCookie=function(document, name, value, expire) {
    document.cookie = name + '=' + escape(value) + '; path=/;' +((expire == null) ? '' : ('; expires=' + expire.toGMTString()));
};
getCookie=function(name) {
	var search = name + '=', defcook= '';
	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{
			offset += search.length;
			end = document.cookie.indexOf(';', offset);
			if (end == -1){end = document.cookie.length;}
			defcook= unescape(document.cookie.substring(offset, end))
			if (defcook!=''){return defcook;}
		}
	}
};

/************************************************************

Javascript de la nouvelle Metabarre avec menu deroulant

Creation : 12/10/2006
Derniere modifications : 21/12/2007

************************************************************/

metabarre_sfHover = function() {
	if (document.getElementById("navMetabarre") != null) {
		var sfEls = document.getElementById("navMetabarre").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", metabarre_sfHover);
