/* ********************************* APPEL DES FONCTIONS */
$(document).ready(function() {	
	initswitchFormComment = switchFormComment();					// formulaire commentaire
	initopenNavProv = openNavProv();								// navigation provisoire
	initsetHeightSub = setHeightSub();								// ul sub meme hauteur
	inittabsConst = tabsConst();									// tabs quotidien
	initup3 = up3();												// up3
	//initpagerNews = pagerNews();									// pager news homepage
	initflashHome = flashHome();									// flash homepage
	initflashVideo = flashVideo();									// flash post video
	initcarOnglets = carOnglets();									// carousel idee bonheur
	initcarShopping = carShopping();								// carousel shopping homepage
	initcarPhoto = carPhoto();										// carousel photo
	initcarShopping2 = carShopping2();								// carousel shopping colonne droite
	initflashMyVideos = flashMyVideos();							// mes videos (col droite)
	initnote1 = note1();											// ouverture / fermeture noteZone
	initreco = reco();												// ouverture / fermeture recoZone
	initjenote = jenote();											// notation
	initjenote2 = jenote2();										// notation
	initjenote3 = jenote3();										// notation
    initjenote4 = jenote4();										// notation
    initjenote5 = note_video();										// notation Vidéo
	initcrochet = crochet();										// ouverture / fermeture bloc key word
	initswapInput = swapInput();									// swap input
	listSelectClick();						// liste menu perso
	scrollPane();							// scrollPane liste menu perso
	plusDetail();							// toggle plus/moins de detail
	carousel3Dhome();						// carousel3D home page
	carousel3D();							// carousel3D
	programmes();	
	goM6();
});

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

/* ********************************* SWAP INPUT */
swapInput = 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])}})});};

/* ********************************* CROCHETS KEY WORD */
crochet = function() {
	if( jQuery(".blocKeyWord").length < 1 )
	return false;
	
	$('.blocKeyWord').hide();
	$('.crochets').click( function() {
		$(this).parent().children('.blocKeyWord').show();
		return false;
	});
	$('.blocKeyWord .close').click( function() {
		$(this).parent().hide();
		return false;
	});
};

/**
 * 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();
	}
}

/* ********************************* 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()=='ouvrir la nav') {
			$(this).html('fermer la nav');	
		}
		else {
			$(this).html('ouvrir la nav');
		}		
		$('.navProvContent').animate({height: "toggle"}, 100);
		return false;		
	});
}
/* ********************************************************************************* OUVERTURE NOTEZONE */
note1 = function() {
	if( jQuery(".notation").length < 1 )
	return false;
	
	$('.noteZone').hide();
	
	$('.noteClic').click(function() {
        if($(this).html() == "notez cette image") {
            val = LireCookie('photo_'+$('#id_photo').val());
            if(val == "1") {
                $(this).parent().children('.noteZone').html('<a href="#" class="closeNoteZone" onclick="$(\'.noteZone\').hide()"><img src="/style/skins/btn-close-noteZone.gif" alt="fermer la fenêtre" /></a>Vous avez déjà voté pour cette photo !');
            }
        }
        
        if($(this).html() == "notez cet article") {
            val = LireCookie('actu_'+$('#id_actu').val());
            if(val == "1") {
                $(this).parent().children('.noteZone').html('<a href="#" class="closeNoteZone" onclick="$(\'.noteZone\').hide()"><img src="/style/skins/btn-close-noteZone.gif" alt="fermer la fenêtre" /></a>Vous avez déjà voté pour cet article !');
                
            }
        }
        
        if($(this).html() == "notez cette vidéo") {
            val = LireCookie('video_'+$('#id_video').val());
            if(val == "1") {
                $(this).parent().find('p').empty();
                $(this).parent().find('.noteZone .note2').html('<a href="#" class="closeNoteZone" onclick="$(\'.noteZone\').hide()"><img src="/style/skins/btn-close-noteZone.gif" alt="fermer la fenêtre" /></a>Vous avez déjà voté pour cette vidéo !');
                
            }
        }
        
		$(this).parent().children('.noteZone').show();
		return false;
	});
    $('.noteClicRecette').click( function() {
        val = LireCookie('recette_'+$('#id_recette').val());
        if(val == "1") {
        
            $(this).parent().children('.noteZoneRecette').html('<a href="#" class="closeNoteZone" onclick="$(\'.noteZone\').hide()"><img src="/style/skins/btn-close-noteZone.gif" alt="fermer la fenêtre" /></a>Vous avez déjà voté pour cette recette !');
        }
      
        
            $(this).parent().children('.noteZoneRecette').show();
        
		return false;
	});
	$('.closeNoteZone').click( function() {
		$(this).parent().hide();
		return false;
	});
}
/* ********************************************************************************* OUVERTURE RECOZONE */
reco = function() {
	if( jQuery(".recoZone").length < 1 )
	return false;
	
	$('.recoZone').hide();
	$('.recoClic').click( function() {
		$('.recoZone').show();
		return false;
	});
	$('.closeRecoZone').click( function() {
		$(this).parent().hide();
		return false;
	});
}

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

jenote4 = function() {
	if( jQuery("#dossierTitle .noteZoneRecette").length < 1 )
	return false;
	
	$('#dossierTitle .note2 span a')
		.mouseout(function(){ 
			 if (clicked4 == false) { 
				$(this).parent().removeClass();
			 }
		})
		.mouseover(function(){ 
			if (clicked4 == false) {
				 var index = $(this).parent().children('a').index(this)+1;
				 $(this).parent().removeClass().addClass('note-'+index);
			}
		})
		.click(function(){
			 if (clicked4 == false) {								

                $(this).parents('.noteZoneRecette').children('p').html('Merci pour votre vote,<br />la note de cette recette est');
                var index = $('#dossierTitle .noteZoneRecette .note2 span a').index(this)+1;
                $(this).parent().removeClass().addClass('note-'+index);
                EcrireCookie('recette_'+$('#id_recette').val(), 1);
                valider_note_recette(index);
			 }
			 clicked4 = true;
			 return false;
		});
};

function valider_note_recette (note) {
    $.ajax( {
		url:'/include/ajax.php?ajax=notation_recette',
		type:'POST',
		data:{id_publier:''+$('#id_recette').val()+'',note:note},
		success:function() {
			$('#notation-recette').load('/include/ajax.php?ajax=maj_div_note_recette',{id:''+$('#id_recette').val()+''});
            $('#notation-recette2').load('/include/ajax.php?ajax=maj_div_note_recette2', {id:''+$('#id_recette').val()+''});
		}
	} );
	
}


jenote = function() {
	if( jQuery("#dossierTitle.dossierTitle .noteZone").length < 1 )
	return false;
	
	$('#dossierTitle.dossierTitle .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('.noteZone').children('p').html('Merci pour votre vote,<br />la note de cet article est');
				var index = $('#dossierTitle.dossierTitle .note2 span a').index(this)+1;
				$(this).parent().removeClass().addClass('note-'+index);
                EcrireCookie('actu_'+$('#id_actu').val(), 1);
                valider_note(index);
			 }
			 clicked = true;
			 return false;
		});
};

function valider_note(note) {
    $.ajax( {
		url:'/include/ajax.php?ajax=notation_actu',
		type:'POST',
		data:{id_publier:''+$('#id_actu').val()+'',note:note},
		success:function() {
			$('#notation-actu').load('/include/ajax.php?ajax=maj_div_note_actu',{id:''+$('#id_actu').val()+''});
            $('#notation-actu2').load('/include/ajax.php?ajax=maj_div_note_actu2', {id:''+$('#id_actu').val()+''});
		}
	} );
	
}

jenote2 = function() {
   
    if( jQuery(".article-photo .noteZone").length < 1 )
	return false;

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

function valider_note2(note) {
    $.ajax( {
		url:'/include/ajax.php?ajax=notation_photo',
		type:'POST',
		data:{id_publier:''+$('#id_photo').val()+'',note:note},
		success:function() {
			$('#note-photo').load('/include/ajax.php?ajax=maj_div_note_photo',{id:''+$('#id_photo').val()+''});
		}
	} );
	
}

jenote3 = function() {
	if( jQuery(".article-video .noteZone").length < 1 )
	return false;

	$('.article-video .note2 span a')
		.mouseout(function(){ 
			 if (clicked3 == false) { 
				$(this).parent().removeClass();
			 }
		})
		.mouseover(function(){ 
			if (clicked3 == false) {
				 var index3 = $(this).parent().children('a').index(this)+1;
				 $(this).parent().removeClass().addClass('note-'+index3);
			}
		})
		.click(function(){
			 if (clicked3 == false) {								
				$(this).parents('.noteZone').children('p').html('Merci pour votre vote,<br />la note de cette vidéo est');
				var index3 = $('.article-video .note2 span a').index(this)+1;
				$(this).parent().removeClass().addClass('note-'+index3);
			 }
			 clicked3 = true;
			 return false;
		});
};



/**
 * -----------------------------------------------------------------
 * NOTATION DES VIDÉOS
 */ 
function note_video() {
	if($("#dossierTitle.videoTitle .noteZone").length < 1) {
		return false;
	}

	$('#dossierTitle.videoTitle .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('.noteZone').children('p').html('Merci pour votre vote,<br />votre note pour cette vidéo est');
				var index = $('#dossierTitle.videoTitle .note2 span a').index(this)+1;
				$('#dossierTitle.videoTitle .note2 span').empty();
				$('#dossierTitle.videoTitle .note2 span').removeClass().addClass('note-'+index);
				EcrireCookie('video_'+$('#id_video').val(), 1);
				valider_note_video(index);
			}
			
			clicked5 = true;
			return false;
		});
};

function valider_note_video(note) {
    $.ajax( {
		url : '/include/ajax.php?ajax=notation_video',
		type : 'POST',
		data : {
			id_fiche : ''+$('#id_video').val()+'',
			note : note
		},
		success : function(msg) {
			datas = msg.split('|');
			var note = Math.round(datas[1]*2);
			
			$('#notation-video span#note').text(datas[0]+' note'+(datas[0]>1 ? 's' : ''));
			$('#notation-video2 span').removeClass().addClass('note note-'+note);
		}
	});
}
/**
 * -----------------------------------------------------------------
 * FIN : NOTATION DES VIDÉOS
 */ 
 
 
/* ********************************************************************************* SOUS MENU */
$(document).ready(function(){
	$("#menu-ul li").hover(function() { 
		$(".sub", this).show();
	}, function() { 
		$(".sub", this).hide();
	});
	if (document.all) {
		$("#menu-ul li").hoverClass ("current");
	}
});

/* ********************************************************************************* SAME HEIGHT SUB */
function setHeightSub() {
	if( jQuery(".subIn2").size() < 1 )
		return false;
	                      
	var heightBlockMax=0;
	$('.subIn2 ul').each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); }); // get max height
	$('.subIn2 ul').each(function(){ $(this).css("height",heightBlockMax+"px"); }); // assign max height
	heightBlockMax=0;
}
/* ********************************************************************************* TABS QUOTIDIEN */
function tabsConst() {
	if(jQuery("#tabsContainer").length < 1) {
		return false;
	}
	
	$('#tabsContainer').tabs(1);
	$('#tabsContainer').show();	
}


function programmes() {
	if($('#quotidien').length) {
		$('#quotidien').load('/include/ajax.php?ajax=programmes', function() {
			tabsConst();
			$('#quotidien').show();
		});
	}
}
/* ********************************************************************************* up3 */
function up3() {		
    if( jQuery("#up3").length < 1 )
	return false;

	$('#up3').show();	
	$('.up3-2').hide();
	$('.up3-3').hide();
	$('.up3-1').show();	
	$('#up3 .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() {
		$('.up3-1').show();
		$('.up3-2').hide();
		$('.up3-3').hide();
	});
	$('.choice-2').mouseover( function() {
		$('.up3-1').hide();
		$('.up3-2').show();
		$('.up3-3').hide();
	});
	$('.choice-3').mouseover( function() {
		$('.up3-1').hide();
		$('.up3-2').hide();
		$('.up3-3').show();
	});
};
/* ********************************************************************************* PAGER TODAY */
function pagerNews() {		
    if( jQuery("#news").length < 1 )
	return false;

	$('#news').pager('ul');
};
/* ********************************************************************************* FLASH HOMEPAGE */
function flashHome() {
	if( jQuery("#flashId1").length < 1 )
		return false;
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("swf/674x291.swf", "flashId1", "674", "291", "9.0.0", "_swf/expressInstall.swf", flashvars, params, attributes);	
}
/* ********************************************************************************* FLASH POST VIDEO */
function flashVideo() {
	if( jQuery("#flashId3").length < 1 )
		return false;
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("swf/650x576.swf", "flashId3", "650", "576", "9.0.0", "_swf/expressInstall.swf", flashvars, params, attributes);	
}
/* ********************************************************************************* FLASH COL DROITE MY VIDEOS */
function flashMyVideos() {
	if( jQuery("#flashId2").length < 1 )
		return false;
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("swf/300x216.swf", "flashId2", "300", "216", "9.0.0", "_swf/expressInstall.swf", flashvars, params, attributes);	
}

/* ********************************************************************************* CAROUSEL IDEE BONHEUR */
function carOnglets() {
	
	
	
	if( jQuery("#carouOnglets > ul").length < 1 )
		return false;
	
	jQuery('#carouOnglets > ul').jcarousel();
}

/* ********************************************************************************* CAROUSEL SHOPPING HOMEPAGE */
function carShopping() {
	if( jQuery("#carouShop > ul").length < 1 )
		return false;
	
	if (document.all) {
		$("#carouShop li a").hoverClass ("carouShopOver");
	}
	
	jQuery('#carouShop > ul').jcarousel();
}
/* ********************************************************************************* CAROUSEL PHOTO */
function carPhoto() {
	if( jQuery("#carouPhoto > ul").length < 1 )
		return false;
	
	if (document.all) {
		$("#carouPhoto li a").hoverClass ("carouPhotoOver");
	}
	
	jQuery('#carouPhoto > ul').jcarousel({initCallback:onInitCarPhoto});
}
var myCarPhoto = null;
function onInitCarPhoto(carousel,state) {
	if(state=='init') {
		myCarPhoto=carousel;
	}
}
/* ********************************************************************************* CAROUSEL SHOPPING COLONNE DROITE */
function carShopping2() {
	if( jQuery("#carouShopColR > ul").length < 1 )
		return false;
	
	if (document.all) {
		$("#carouShopColR li a").hoverClass ("carouShopOver");
	}
	
	jQuery('#carouShopColR > ul').jcarousel();
}
/* ********************************************************************************* 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();
	});
}
/* ********************************************************************************* JQUERY.PAGER.JS */
$.fn.pager = function(clas, options) {
	
	var settings = {		
		navId: 'nav',
		navClass: 'nav',
		navAttach: 'append',
		highlightClass: 'highlight',
		prevText: ' ',
		nextText: ' ',
		linkText: null,
		linkWrap: null,
		height: null
	}
	if(options) $.extend(settings, options);
	
		
	return this.each( function () {
		
		var me = $(this);
		var size;
	  	var i = 0;		
		var navid = '#'+settings.navId;
		
		function init () {
			size = $(clas, me).not(navid).size();
			if(settings.height == null) {			
				settings.height = getHighest();
			}
			if(size > 1) {
				makeNav();
				show();
				highlight();
			}			
			sizePanel();
			if(settings.linkWrap != null) {
				linkWrap();
			}
		}
		function makeNav () {		
			var str = '<div id="'+settings.navId+'" class="'+settings.navClass+'">';
			str += '<a href="#" class="prev" rel="prev">'+settings.prevText+'</a>';
			for(var i = 0; i < size; i++) {
				var j = i+1;
				str += '<a href="#" class="navPager'+j+'" rel="'+j+'">';
				str += (settings.linkText == null) ? j : settings.linkText[j-1];				
				str += '</a>';
			}
			str += '<a href="#" class="next" rel="next">'+settings.nextText+'</a>';
			str += '</div>';
			switch (settings.navAttach) {		
				case 'before':
					$(me).before(str);
					break;
				case 'after':		
					$(me).after(str);
					break;
				case 'prepend':
					$(me).prepend(str);
					break;
				default:
					$(me).append(str);
					break;
			}
		}
		function show () {
			$(me).find(clas).not(navid).hide();
			var show = $(me).find(clas).not(navid).get(i);
			$(show).show();
		}		
		function highlight () {
			$(me).find(navid).find('a').removeClass(settings.highlightClass);
			var show = $(me).find(navid).find('a').get(i+1);			
			$(show).addClass(settings.highlightClass);
		}

		function sizePanel () {
			if($.browser.msie) {
				$(me).find(clas).not(navid).css( {
					height: settings.height
				});	
			} else {
				$(me).find(clas).not(navid).css( {
					minHeight: settings.height
				});
			}
		}
		function getHighest () {
			var highest = 0;
			$(me).find(clas).not(navid).each(function () {
				
				if(this.offsetHeight > highest) {
					highest = this.offsetHeight;
				}
			});
			highest = highest + "px";
			return highest;
		}
		function getNavHeight () {
			var nav = $(navid).get(0);
			return nav.offsetHeight;
		}
		function linkWrap () {
			$(me).find(navid).find("a").wrap(settings.linkWrap);
		}
		init();
		$(this).find(navid).find("a").click(function () {

			if($(this).attr('rel') == 'next') {
				if(i + 1 < size) {
					i = i+1;
				}
			} else if($(this).attr('rel') == 'prev') { 
				if(i > 0) {	
					i = i-1;
				}
			} else {		
				var j = $(this).attr('rel');	
				i = j-1;		
			}
			show();
			highlight();
			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" : "");
}


/* ****************************************************************************** LIST SELECT CLICK */
function listSelectClick(){
	if($("div.select").length < 1 ) return false;

	$("div.select")
		.find("li a")
			.click(function(){
				var texteTag = $(this).text();
				$(this)
					.parents(".scroll-pane").find("a").removeClass("current").end().end()
					.addClass("current")
					.parents(".jScrollPaneContainer").next().show("slow").find('.tag').text(texteTag);
				return false;
			})
		.end()
		.find("a.closeTag")
			.click(function(){	
				$(this)
					.parent().hide("slow")
					.prev().find("a").removeClass("current").end().end();
				return false;
			})
		.end();
}

/* ****************************************************************************** KAMASUTRA */

function kamasutra(){
	changePosition();

	$('#btkama').click(function(){
		changePosition();
		return false;
    });
		
	function changePosition() {
		$.getJSON('/include/ajax.php?ajax=kamasutra', {
			'saison' : $('#selectSaison').val(),
			'difficulte' : $('#selectDifficulte').val()
		}, function(datas) {
			if(datas.error) {
				alert(datas.error);
				return;
			}
			
			datas.position = -1*datas.position;
			
	      	$('#kama1')
			  	.css({ backgroundPosition : '0 269px' })
				.animate({backgroundPosition: '(0% '+ datas.position +')'}, function(){ 
					var laposition= $(this).css('backgroundPosition');
					
					$(this)
						.next()
						.css({ backgroundPosition : '50% 269px' })
						.animate({
							backgroundPosition : '(50% '+ datas.position +')'
						}, function(){
							$(this).next()
								.css({backgroundPosition: '100% 269px'})
								.animate({backgroundPosition: '(100% '+ datas.position +')'});		
						});			
				});
				
			$('#kamasutra_nom').html(datas.nom);
			$('#kamasutra_description').html(datas.description);
			$('#kamasutra_saison').html(datas.saison);
			$('#kamasutra_difficulte').html(datas.difficulte);
		});
	}
}

/**
 * Background-Position Animations
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');

                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);



/* ****************************************************************************** SCROLL PANE */
function scrollPane(){
	if($(".scroll-pane").length < 1 ) return false;
	$(".scroll-pane").jScrollPane({showArrows:true, scrollbarMargin :1, dragMaxHeight : 10});
}

/* ****************************************************************************** PLUS DE DETAIL */

function plusDetail() {
	if( $("#plusDetail").length < 1 )	return false;
	
	 var texte = $('#plusDetail span').html();
	 $("#plusDetail").toggle(
      function () {
		$('#plusDetail span').html("- de détails");
        $('table .bis').show();
      },
      function () {
		$('#plusDetail span').html(texte);
        $('table .bis').hide();
      }
    );
};

/* ***************************************************************************** CAROUSEL 3D Home page */
function carousel3Dhome() {
	if( $(".carousel3Dhome").length < 1 ) return false;
	$(".carousel3Dhome").each(function(i){
		$(this)
			.attr("id", "carousel3Dhome-" + i)
			.find(".prev")
				.attr("id", "prev" + i)
				.click(function() {
					if(pos1[i] > 0) {pos1[i]--;} else {pos1[i] = nbListe[i]-1;}
					if(pos2[i] > 0) {pos2[i]--;} else {pos2[i] = nbListe[i]-1;}
					if(pos3[i] > 0) {pos3[i]--;} else {pos3[i] = nbListe[i]-1;}
					if(pos4[i] > 0) {pos3[i]--;} else {pos4[i] = nbListe[i]-1;}
					if(pos5[i] > 0) {pos3[i]--;} else {pos5[i] = nbListe[i]-1;}
					move($(this));
					return false;
				})
			.end()
			.find(".next")
				.attr("id", "prev" + i)
				.click(function() {
					if(pos1[i]< nbListe[i]-1) {pos1[i]++;} else {pos1[i] = 0;}
					if(pos2[i]< nbListe[i]-1) {pos2[i]++;} else {pos2[i] = 0;}
					if(pos3[i]< nbListe[i]-1) {pos3[i]++;} else {pos3[i] = 0;}
					if(pos4[i]< nbListe[i]-1) {pos4[i]++;} else {pos4[i] = 0;}
					if(pos5[i]< nbListe[i]-1) {pos5[i]++;} else {pos5[i] = 0;}
					move($(this));
					return false;
				})
			.end()
			.find(".linkLeftLeft")
				.attr("id", "linkLeftLeft" + i)
			.end()
			.find(".linkLeft")
				.attr("id", "linkLeft" + i)
			.end()
			.find(".linkCenter")
				.attr("id", "linkCenter" + i)
			.end()
			.find(".linkRight")
				.attr("id", "linkRight" + i)
			.end()
			.find(".linkRightRight")
				.attr("id", "linkRightRight" + i)
			.end()
			.find(".legende")
				.attr("id", "legende" + i)
			.end()
		
		
		function move(object) {
			imgLeftLeftSrc = $(object).parent().find("li img:eq(" + pos4[i] + ")").attr("src");
			imgLeftSrc = $(object).parent().find("li img:eq(" + pos1[i] + ")").attr("src");
			imgCenterSrc = $(object).parent().find("li img:eq(" + pos2[i] + ")").attr("src");
			imgRightSrc = $(object).parent().find("li img:eq(" + pos3[i] + ")").attr("src");
			imgRightRightSrc = $(object).parent().find("li img:eq(" + pos5[i] + ")").attr("src");
			
			imgLeftLeftLink =   $(object).parent().find("li a:eq(" + pos4[i] + ")").attr("href");
			imgLeftLink =   $(object).parent().find("li a:eq(" + pos1[i] + ")").attr("href");
			imgCenterLink = $(object).parent().find("li a:eq(" + pos2[i] + ")").attr("href");
			imgRightLink =  $(object).parent().find("li a:eq(" + pos3[i] + ")").attr("href");
			imgRightRightLink =  $(object).parent().find("li a:eq(" + pos5[i] + ")").attr("href");
			
			legende = $(object).parent().find("li span:eq(" + pos2[i] + ")").text();
						
			$("#carousel3Dhome-"+i).find('#linkLeftLeft' + i ).attr("href", imgLeftLeftLink).find("img").attr("src", imgLeftLeftSrc);
			$("#carousel3Dhome-"+i).find('#linkLeft' + i ).attr("href", imgLeftLink).find("img").attr("src", imgLeftSrc);
			$("#carousel3Dhome-"+i).find('#linkCenter' + i).attr("href", imgCenterLink).find("img").attr("src", imgCenterSrc);
			$("#carousel3Dhome-"+i).find('#linkRight' + i).attr("href", imgRightLink).find("img").attr("src", imgRightSrc);
			$("#carousel3Dhome-"+i).find('#linkRightRight' + i).attr("href", imgRightRightLink).find("img").attr("src", imgRightRightSrc);
			$("#carousel3Dhome-"+i).find('#legende' + i).text(legende).attr("href", imgCenterLink);
		}
		
		var nbListe = new Array();
		var pos1 = new Array();
		var pos2 = new Array();
		var pos3 = new Array();
		var pos4 = new Array();
		var pos5 = new Array();
		var imgLeftLeftSrc = new Array();
		var imgLeftSrc = new Array();
		var imgCenterSrc = new Array();
		var imgRightSrc = new Array();
		var imgRightRightSrc = new Array();
		
		var firstPos = 0;
		
		$(this).find('li').each(function(j,e) {
			if($(e).hasClass('selected')) {
				firstPos = j;
			}
		});
		
		nbListe[i] = $(this).find("li").length;
		
		
		pos1[i] = firstPos-1 < 0 ? nbListe[i]+firstPos-1 : firstPos-1;
		pos2[i] = firstPos;
		pos3[i] = firstPos > nbListe[i]-2 ? nbListe[i]-firstPos-1 : firstPos+1;
		pos4[i] = firstPos-2 < 0 ? nbListe[i]+firstPos-2 : firstPos-2;
		pos5[i] = firstPos > nbListe[i]-3 ? nbListe[i]-firstPos : firstPos+2;
		move($(this));
	});
}

/* ***************************************************************************** CAROUSEL 3D */
function carousel3D() {
	if( $(".carousel3D").length < 1 ) return false;
	$(".carousel3D").each(function(i){
		$(this)
			.attr("id", "carousel3D-" + i)
			.find(".prev")
				.attr("id", "prev" + i)
				.click(function() {
					if(pos1[i] > 0) {pos1[i]--;} else {pos1[i] = nbListe[i]-1;}
					if(pos2[i] > 0) {pos2[i]--;} else {pos2[i] = nbListe[i]-1;}
					if(pos3[i] > 0) {pos3[i]--;} else {pos3[i] = nbListe[i]-1;}
					move($(this));
					return false;
				})
			.end()
			.find(".next")
				.attr("id", "prev" + i)
				.click(function() {
					if(pos1[i]< nbListe[i]-1) {pos1[i]++;} else {pos1[i] = 0;}
					if(pos2[i]< nbListe[i]-1) {pos2[i]++;} else {pos2[i] = 0;}
					if(pos3[i]< nbListe[i]-1) {pos3[i]++;} else {pos3[i] = 0;}
					move($(this));
					return false;
				})
			.end()
			.find(".linkLeft")
				.attr("id", "linkLeft" + i)
			.end()
			.find(".linkCenter")
				.attr("id", "linkCenter" + i)
			.end()
			.find(".linkRight")
				.attr("id", "linkRight" + i)
			.end()
			.find(".legende")
				.attr("id", "legende" + i)
			.end()
		
		
		function move(object) {
			imgLeftSrc = $(object).parent().find("li img:eq(" + pos1[i] + ")").attr("src");
			imgCenterSrc = $(object).parent().find("li img:eq(" + pos2[i] + ")").attr("src");
			imgRightSrc = $(object).parent().find("li img:eq(" + pos3[i] + ")").attr("src");
			
			imgLeftLink =   $(object).parent().find("li a:eq(" + pos1[i] + ")").attr("href");
			imgCenterLink = $(object).parent().find("li a:eq(" + pos2[i] + ")").attr("href");
			imgRightLink =  $(object).parent().find("li a:eq(" + pos3[i] + ")").attr("href");
			
			legende = $(object).parent().find("li span:eq(" + pos2[i] + ")").text();
			
			$("#carousel3D-"+i).find('#linkLeft' + i ).attr("href", imgLeftLink).find("img").attr("src", imgLeftSrc);
			$("#carousel3D-"+i).find('#linkCenter' + i).attr("href", imgCenterLink).find("img").attr("src", imgCenterSrc);
			$("#carousel3D-"+i).find('#linkRight' + i).attr("href", imgRightLink).find("img").attr("src", imgRightSrc);
			$("#carousel3D-"+i).find('#legende' + i).text(legende).attr("href", imgCenterLink);
		}
		
		var nbListe = new Array();
		var pos1 = new Array();
		var pos2 = new Array();
		var pos3 = new Array();
		var imgLeftSrc = new Array();
		var imgCenterSrc = new Array();
		var imgRightSrc = new Array();
		
		nbListe[i] = $(this).find("li").length;
		pos1[i] = nbListe[i]-1;
		pos2[i] = 0;
		pos3[i] = 1;
		move($(this));
	});
}


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;}
		}
	}
};

/* ****************************************************************************** Stats fiche */
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+'" />');
}

