///////////////////////////////////// NIVOSLIDER - tetiere ////////////////////////////

$(window).load(function() {
						
	$('#NivoSlider').nivoSlider({
		effect:'sliceUpDown',
		slices:20,
		animSpeed:1000,
		pauseTime:12000,
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false //Force manual transitions
		// beforeChange: function(){},
		//afterChange: function(){}						
	});
	
	
	$('#slider3').nivoSlider({
		slices:20,
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		/* 
		# sliceDown
		# sliceDownLeft
		# sliceUp
		# sliceUpLeft
		# sliceUpDown
		# sliceUpDownLeft
		# fold
		# fade
		*/
		animSpeed:800, //Slide transition speed
		pauseTime:2000,
		manualAdvance:false,
		pauseOnHover:true,
		controlNavThumbs:true,
		controlNavThumbsFromRel:false,
		controlNavThumbsReplace: '_thumb.JPG',
		captionOpacity:1 //Universal caption opacity
		// beforeChange: function(){},
		//afterChange: function(){}
	});	
	
	
});




$(document).ready(function(){
						   
/////////////////// ajout icone loupe + sur img nyromodal ////////////////////////////////////


$(".nyroModal").append('<img class="loupe" src="images/gabarit/v2/icone_loupe_video.png" width="36" height="36" />');


/////////////////// FIN ajout icone loupe + sur img nyromodal ////////////////////////////////	
						   
						   
						   
/////////////////// Roll over picto defile ////////////////////////////////////
		
		$('#picto_defiles_hover').css("opacity","0");
		
		$("#picto_defiles_hover").hover(function() {
			$(this).animate({opacity:1},600);
			$("#picto_defiles_normal").animate({opacity:0},600);
		},function(){
			$(this).animate({opacity:0},200);
			$("#picto_defiles_normal").animate({opacity:1},200);
		});


/////////////////// FIN Roll over picto defile ////////////////////////////////	






/////////////////////// tooltip lien membre ///////////////////////


$("#membres a").hover(function() {	
	$("#tooltip").fadeIn('fast');
},function(){
	$("#tooltip").fadeOut('slow');
});


//////////////////////////////////////////////////////////////////





						   
/////////////////// Message VIP pop up ////////////////////////////////	

// j'ai été obligé de le mettre ici car en echo dans le php, ca ne marchait pas !!!!!
		var api = $("#message_vip").expose({api: true});		
		$("#message_vip h1 a").click(function(){
			api.close();
			return false;
		});
						   
///////////////////////////////////////////////////////////
/////////////////// BREVES ////////////////////////////////
///////////////////////////////////////////////////////////

var hauteurbreve= 180;

$("#ControlDivBreves .droite").click(function(){
	StopBougebreves();
	Bougebreves(1);								
});

$("#ControlDivBreves .gauche").click(function(){
	StopBougebreves();
	Bougebreves(-1);								
});

var Bougebreves = function(sens){ // -1:bas 1:haut
	if(sens>0){$("#sliderbreves").scrollTo( '+='+hauteurbreve, 800);}
	else{$("#sliderbreves").scrollTo( '-='+hauteurbreve, 800);}
}

var IntervalKeyBreves;

var StartBougebreves = function(){
	IntervalKeyBreves = setInterval(Bougebrevesbas,11000);					
};

var StopBougebreves = function(){
	clearInterval(IntervalKeyBreves);					
};

var Bougebrevesbas = function(){
	Bougebreves(1);
}

StartBougebreves();

///////////////////////////// BREVES - EFFET VISUEL ///////////////////////////////
		
		
		$('#ControlDivBreves a').css("opacity","0.35");
		
		$("#ControlDivBreves a").hover(function() {
			$(this).animate({opacity:1},200);
		},function(){
			$(this).animate({opacity:0.5},200);
		});
		
		$("#ControlDivBreves a").click(function(){
			return false;
		});
		
///////////////////////////// FIN BREVES ///////////////////////////////	








////////////////////// Effets visuels sur bouton retourtop
		
		/*
		$('#article .retourtop a').css("opacity","0.35");
		
		$("#article .retourtop a").hover(function() {
			$(this).animate({opacity:1},200);						
		},function(){
			$(this).animate({opacity:0.5},200);
		});
		*/
		
		// contrôle bouton retourtop
		/*
		$("#article .retourtop a").click(function() {
			$('html,body').animate({scrollTop:0},1000,'easeOutQuint');
			return false;
		});
		*/
		
		
		$('.retourtop a').css("opacity","0.35");
		
		$(".retourtop a").hover(function() {
			$(this).animate({opacity:1},200);						
		},function(){
			$(this).animate({opacity:0.5},200);
		});
		
		// contrôle bouton retourtop
		$(".retourtop a").click(function() {
			$('html,body').animate({scrollTop:0},1000,'easeOutQuint');
			return false;
		});
		





////////////////////// Effets visuels sur boutons navigation news PREV / NEXT
		$('#nav_articles img').css("opacity","0.35");
		
		$("#nav_articles a img").hover(function() {
			$(this).animate({opacity:1},200);						
		},function(){
			$(this).animate({opacity:0.5},200);
		});






///////////////////////////// SLIDER ///////////////////////////////
		
		
		// Effets visuels sur boutons suivants et précédent portfolio
		
		$('#ControlDiv a').css("opacity","0.35");
		
		$("#ControlDiv a").hover(function() {
			$(this).animate({opacity:1},200);						
		},function(){
			$(this).animate({opacity:0.5},200);
		});	
		
				
		
		// la fonction principale avec son initialisation
		
		var Idx = 2;
		var IntervalKey;
		
		// Tous les reglages suivants sont obtenus en lisant le texte de la div ReglagesSliderPortfolio
		// la premiere image doit OBLIGATOIREMENT faire partie du dossier d'images à traiter pour le slideshow
		var chemin =  $("#ReglagesSliderPortfolio .chemin_visu").text() ;
		var IdxMax = parseInt($("#ReglagesSliderPortfolio .nbre_images").text()) ;
		
			
		// création des petits points correspondant au nombre de photos.
		// <div id="pointportfolio"><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em></div>
		var chaine = '';
		for(i=1; i<=IdxMax; i++){
			chaine += '<em>.</em>'; 
		}
		$("#pointportfolio").html(chaine);
		$("#pointportfolio em").eq(0).css({color:"#ffffff"});
		
		
		// les commentaire à injecter et le bloc qui doit recevoir les commentaires ne doivent pas porter la meme class... sinon ca merde
		if($("#ReglagesSliderPortfolio .commentaire_unique").text()=="true"){
			var commentaire_unique = true;
		}else{
			$("#texte_commentaire").html($("#commentaire .hide").eq(0).html());
			var commentaire_unique = false;
		};

		
		
		
		var ChangeImage = function(sens){
			//If the image still animating, stop it and start the new one
			$("#MainImage").ImageStop(true,true);
			if(sens){
				$("#MainImage").ImageSwitch({Type:"ScrollIn", NewImage: chemin+Idx+".jpg" });
			}else {
				$("#MainImage").ImageSwitch({Type:"ScrollOut", NewImage: chemin+Idx+".jpg" });
			}
			
			if(commentaire_unique!=true){Changelegende(Idx);}
			Changepoints(Idx);
			
			Idx++;
			if(Idx>IdxMax){Idx = 1;}
			//Start preload the next image
			$.ImagePreload(chemin+Idx+".jpg");
		};
		
		
		// gestion des points
		var Changepoints = function(nbre){
			nbre--;
			$("#pointportfolio em").css({color:"#666666"});
			$("#pointportfolio em").eq(nbre).css({color:"#ffffff"});
		}
		
		
		// gestion des légendes
		var Changelegende = function(numero){
			numero = numero-1;
			if(numero<0){numero=IdxMax;}
			
			var html = $("#commentaire .hide").eq(numero).html();
			if(commentaire_unique==false){
				$("#texte_commentaire").hide();
				$("#texte_commentaire").html(html);
				$("#texte_commentaire").fadeIn(1500);			
			}

		}
		
		
		// Gestion des boutons suivants et précédent portfolio
		
		$("#ControlDiv a.droite").click(function(){
			var valeur = $("#MainImage").attr("src").replace(chemin,"");
			var valeur = parseInt(valeur.replace(".jpg",""));
			Idx = valeur+1;
			if(Idx>IdxMax){Idx = 1;}
			ChangeImage();
			StopSlideShow();
			return false;
		});
		
		$("#ControlDiv a.gauche").click(function(){
			var valeur = $("#MainImage").attr("src").replace(chemin,"");
			var valeur = parseInt(valeur.replace(".jpg",""));
			Idx=valeur-1;
			if(Idx<1){Idx = IdxMax;}
			ChangeImage('qlqchose');
			StopSlideShow();
			return false;
		});		
		
		
		var StartSlideShow = function(){
			IntervalKey = setInterval(ChangeImage,9000);
			$("#SlideShow").text("Stoper le défilement");
			$("#SlideShow").unbind("click");
			$("#SlideShow").bind("click",StopSlideShow);					
		};
		
		var StopSlideShow = function(){
			clearInterval(IntervalKey);
			$("#SlideShow").text("Défilement automatique");
			$("#SlideShow").unbind("click");
			$("#SlideShow").bind("click",StartSlideShow);					
		};
		
		$("#SlideShow").bind("click",StartSlideShow);
		
		StartSlideShow();
		

///////////////////////////// FIN SLIDER ///////////////////////////////




///////////////////////////// SLIDER news - une seule news slider possible ///////////////////////////////
		var Idx2 = 2;
		var IntervalKey2;
		
		var chemin2 =  "images/articles/editionlimite/ricci/slider/" ;
		var IdxMax2 = 5 ;
		
		var ChangeImage2 = function(){
			//If the image still animating, stop it and start the new one
			$("#image_news_slider").ImageStop(true,true);
			
			$("#image_news_slider").ImageSwitch({Type:"FadeIn", NewImage: chemin2+Idx2+".jpg" });
			
			Idx2++;
			
			if(Idx2>IdxMax2){Idx2 = 1;}
			//Start preload the next image
			$.ImagePreload(chemin2+Idx2+".jpg");
		};


		var StartSlideShow2 = function(){
			IntervalKey2 = setInterval(ChangeImage2,2400);					
		};
		
		StartSlideShow2();
		
///////////////////////////// FIN SLIDER news ///////////////////////////////////////////////////////////




///////////////////////////// SLIDER news - uFonction - variables envoyées sous form de param //////////

		// var DefineSlideShow = function(chemin, IdxMax){
			
			var Idx3 = 2;
			// var IntervalKey3;
			
			// var chemin3 = "images/articles/news/vendanges2010/slider/" ;
			// var IdxMax3 = 5 ;
			
			var ChangeImage3 = function(cible,chemin3,IdxMax3){
				//If the image still animating, stop it and start the new one
				cible.ImageStop(true,true);
				
				cible.ImageSwitch({Type:"FadeIn", NewImage: chemin3+Idx3+".jpg" });
				
				Idx3++;
				
				if(Idx3>IdxMax3){Idx3 = 1;}
				//Start preload the next image
				$.ImagePreload(chemin3+Idx3+".jpg");
			};
	
	
			var StartSlideShow3 = function(cible,chemin,IdxMax){
				// chemin3 = chemin ;
				// var IdxMax3 = IdxMax ;
				// IntervalKey3 = setInterval(ChangeImage3,2400,(chemin3,IdxMax3));
				// IntervalKey3 = setInterval(function(){ChangeImage3(chemin3,IdxMax3);},2400);
				// IntervalKey3 = setInterval(function(){ChangeImage3(cible,chemin,IdxMax);},2400);
				setInterval(function(){ChangeImage3(cible,chemin,IdxMax);},2400);
				
			};
			
			StartSlideShow3($(".image_news_slider2"),"images/articles/news/vendanges2010/slider/",3);
			StartSlideShow3($(".image_news_slider3"),"images/articles/news/vendanges2010/slider/",5);
			
		// };
		
		

		
///////////////////////////// FIN SLIDER news ///////////////////////////////////////////////////////////




///////////////////////////// effet visuel FOND introraticle ///////////////////////////////



// syntaxe spéciale pour petit plugin backpos
$(".introarticle").css({backgroundPosition: "390px 83px"}).hover(function() {
	$(this).animate({
		// opacity:0.75,
		backgroundPosition:"(380px 73px)"
	},200);						
},function(){
	$(this).animate({
					// opacity:1,
	backgroundPosition:"(390px 83px)"
	},200);
});


// syntaxe normale
$(".fondintroarticle").hover(function() {
	$(this).animate({marginLeft:0},100);						
},function(){
	$(this).animate({marginLeft:10},300);
});


///////////////////////////// FIN FOND introraticle ///////////////////////////////







///////////////////////////// effet visuel liens annonceurs ///////////////////////////////


// Animation du fond => syntaxe spéciale pour petit plugin backpos
$(".liens_annonceurs p").css({backgroundPosition: "0px 0px"}).hover(function() {
	$(this).animate({
		// opacity:0.75,
		backgroundPosition:"(440px 0px)"
	},600);						
},function(){
	$(this).animate({
					// opacity:1,
	backgroundPosition:"(0px 0px)"
	},200);
});


// modification color et appartition vignette 
$(".liens_annonceurs a").hover(function() {
	$(".liens_annonceurs .bulleinfo").hide(); // on les vire toutes pour plus de sécurité
	$(this).fadeTo(300,1,function(){
		$(".liens_annonceurs .bulleinfo").hide(); // on les vire toutes pour plus de sécurité
		$(this).parent().parent().find(".bulleinfo").fadeIn('slow');	
	});							
}, function(){   // out
	$(".liens_annonceurs .bulleinfo").hide(); // on les vire toutes pour plus de sécurité
	$(this).fadeTo(200,0.5);
});


///////////////////////////// FIN visuel liens annonceurs ///////////////////////////////










///////////////////////////////////////////////// MENU DEROULANT HAUT ///////////////////////////////////////////////////

     
        // items principaux
		$("a.item1").mouseover(function() {
											// $("a.deroulant").mouseover(function() {

				$(this).parent().find("div.subnav").slideDown(200); // syntaxe obligatoire
				
				// on trouve le background-color qu'on va appliquer à l'id du menu principal
				// var bgcolorhover = $(this).parent().find("p:first").css("background-color");
				var bgcolorhover = $(this).children().css("background-color");
				// alert(bgcolorhover);
				$(this).css("background-color",bgcolorhover);

                $(this).parent().hover(function() {
				// hover							
                }, function(){   // out 
						$(this).parent().find("div.subnav").fadeOut(300); //When the mouse hovers out of the subnav, move it back up
						$(".subnav2").hide(); // cache tous les sous menus nivo2
						$(this).parent().find("a.item1").css("background-color", "transparent");
                });
        });
		
		
		// items secondaires
		$("a.deroulant2").mouseover(function() {
			$(this).parent().parent().parent().find(".subnav2").hide(); // on les maque tous
			$(this).parent().parent().find(".subnav2").show(); // on affiche le bon
		});

		
		
		
				
		// Rollover sur les sous items
		
		$(".subnav p").css("opacity","0.85");
		$(".subnav li.item1").css("opacity","0.85");
		$(".subnav .subnav2 li").css("opacity","0.85");
		
		var opacityp = $(".subnav p").css("opacity");

		$(".subnav a").hover(function() {
				$(this).parent("p").animate({
					opacity: 1
			  	}, 400);
				
				$(this).parent("li").animate({
					opacity: 1
			  	}, 400);
				
		},function(){
				$(this).parent("p").animate({
					opacity: opacityp
			  	}, 400);
				
				$(this).parent("li").animate({
					opacity: opacityp
			  	}, 400);			
		});
		
		
		
		
///////////////////////////////////////////////// FIN MENU DEROULANT ///////////////////////////////////////////////////

	


///////////////////////////////////////////////// effet visuel MENU BAS ///////////////////////////////////////////////////////

// syntaxe spéciale pour petit plugin backpos
$("#menubas a").css({backgroundPosition: "0px 0px"}).hover(function() {
	$(this).animate({
		// opacity:0.75,
		backgroundPosition:"(0px 30px)"
	},400);						
},function(){
	$(this).animate({
					// opacity:1,
	backgroundPosition:"(0px 0px)"
	},200);
});

///////////////////////////////////////////////// FIN effet visuel MENU BAS ///////////////////////////////////////////////////
	
	


///////////////////////////////////// nyroModal => pop up simple et... efficace !	
$('#article a.nyroModal').nyroModal();




///////////////////////////////////// vignettes du sommaire

		$(".bloc_sommaire").hover(function() {				
				$(this).find("img").animate({opacity: 1}, 400);				
		},function(){
				$(this).find("img").animate({opacity: 0}, 400);			
		});





///////////////////////////////////// A METTRE A LA FIN sinon bug ////////////////////////////	
///////////////////////////////////// FLASH WP CUMULUS ////////////////////////////
$('#wpcumuls').flash(
     {
         src: 'wp-cumulus/tagcloud.swf',
         width: 278,
         menu:true,
         height: 278,
         background: '#000000',
         id: 'wp-cumulus-movie',
         wmode: 'transparent'
         // flashvars: { folder: 'nightmare_ice' }
      },
      {
          expressInstall: true,
          version: '9'
      }
 );


// basic embed

/*$('#wpcumuls').flash({
    src: 'wp-cumulus/tagcloud.swf',
    width: 278,
    height: 278
});*/
///////////////////////////////////// FIN FLASH WP CUMULUS ////////////////////////////
						   			  
});

