//JS pour l'ouverture contenus des onglets//

var tabIndex = 0;
var controlForm = 0;
var clouds = "";
var callUrl = "/ezjscore/call/cavadeos::commentcount::";
$(document).ready(function(){
	$('.cloud').each( function(e){
		var id = $(this).find('a').attr('class');
		if( id ) 
		{
			clouds = clouds + id.substring(6) + ",";
		}
	});
	
	if( clouds != "" )
	{
		callUrl = callUrl +clouds+"?ContentType=json";
		
		$.getJSON( callUrl, function(data) {				
							$('.cloud').each( function(e){
								//count = data.content[$(this).attr('id').substring(6)];
								count = data.content[$(this).find('a').attr('class').substring(6)];
								if( count ) 
								{
									$(this).find('a').text(count);
								} else {
									$(this).find('a').text("0");
								}
							})
					}
				 );
	}
	// Basculer sur un autre site
	/*$('#autresSites').change(function()
	{
		var newSite = $(this).val();
		document.location.href = newSite;
	});*/
	// Onglets principaux

	$('#panes .abonnementCont .firstDl dt img:first').show();
	
	$('#inscription li').each(function(i,e)
	{

		$(this).find('a').click(function(e)
		{
			e.preventDefault();
			$('#inscription li a').removeClass('current');
			$(this).addClass('current');
			$('#panes .paneBlock').hide();
			$('#panes .paneBlock:eq('+i+')').show();
			currentClass = $('#panes .paneBlock:eq('+i+')').attr('class').replace(' paneBlock','');
			$('#inscription').attr('class',currentClass+'Select');
		});
	
		
	});
$('#inscription li a').click(function(e)
		{
	if ($('#inscription').hasClass('rechercheContSelect') || $('#inscription').hasClass ('inscriptionContSelect'))
	{
	    $('#bandeauAll').hide();
	}
	else 
	
	{
		 $('#bandeauAll').show();
	}
});
		
	$('#searchTextTop').focus(
		function(){
			$('#inscription cli a').removeClass('current');
			$(this).closest('li').find('a').addClass('current');
			$('.rechercheCont').show();
			$('.abonnementCont').hide();
			$('.inscriptionCont').hide();
			$('#inscription').attr('class','rechercheContSelect');
	});
	
	$('#navSelect  .btnNext').click( function(){
		var site = $('#autresSites').val();
		window.open( site, '', '');
		//document.location.href = site;
	});

	// Changer le nombre d'affichage dans la liste des résultats de recherche
	$('.searchLimit').change(function()
	{
		var newLimit = $(this).val();
		var newUrl = "";
		var url = document.location.href;
		if ( url.lastIndexOf( 'limit' ) > -1 )
		{
			// On doit remplacer limit=xx par limit=newLimit
			var currentLimit = getParamValue( 'limit', url );
		//alert(currentLimit)
			var searchUrl = 'limit='+currentLimit;
			newUrl = url.replace( searchUrl, 'limit='+newLimit );
		} else {
			newUrl = document.location.href+"&limit="+newLimit;
		}
		document.location.href = newUrl;
	});
	
	// Changer le nombre d'affichage dans liste en mode view parameters
	$('.searchLimitVP').change(function()
	{
     	var newLimit = $(this).val();
     	var url = document.location.href;
     	if( url.lastIndexOf( 'limit' ) > -1 )
     	{
            document.location.href = url.replace( getVPValue( 'limit' ), '/(limit)/'+newLimit );
          } else {
            document.location.href = url+'/(limit)/'+newLimit;
         }   
	});
	
	$('.changeRubriqueHistoryForm').change(function()
	{
     	var newLimit = $(this).val();
     	var url = document.location.href;
     	if( url.lastIndexOf( 'rubrique' ) > -1 )
     	{
            document.location.href = url.replace( getVPValue( 'rubrique' ), '/(rubrique)/'+newLimit );
          } else {
            document.location.href = url+'/(rubrique)/'+newLimit;
         }   
	});
	
	function getVPValue( vp )
	{
     	var u = document.location.href;
  		var reg = new RegExp("\/[\\(]"+vp+"[\\)]\/(.*)");
     	//var reg = new RegExp( "\/(\d+)" );
  		matches = u.match(reg);
  		if(matches)
		{
			return matches[0] != undefined ? decodeURIComponent(matches[0]).replace(/\+/g,' ') : '';
			//return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g,' ') : '';
		} else { alert( "pff"); }
		
	}
	// Trouver un paramètre dans une url
	function gup( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

	// Validation des formulaires
	$('#formContact').submit(function(e)
	{
		controlForm = 0;
		/*showErrorLabels($(this).find('input[name=radioCivilite]'),'check')*/
		showErrorLabels($(this).find('#champNom'),'empty')
		showErrorLabels($(this).find('#champPrenom'),'empty')
		showErrorLabels($(this).find('#textAddresse'),'empty')
		showErrorLabels($(this).find('#champCodePostal'),'empty')
		showErrorLabels($(this).find('#champVille'),'empty')
		showErrorLabels($(this).find('#AddresseMail'),'email')
		showErrorLabels($(this).find('#champMessage'),'empty')
		var objetVal = ""
		switch( $('#selectDemande').val() )
		{
			case 'C':
			objetVal = $('#selectService01').val();
			break;
			case 'E':
			objetVal = $('#selectService02').val();
			break;
			case 'A':
			objetVal = $('#selectService03').val();
			break;
		}
		$('#champObjet').val( objetVal );
		if(controlForm!=0)
		{
			e.preventDefault();
		}
	});

	$('#formAnciensNumeros').submit(function(e)
	{
		controlForm = 0;
		var numeroArray = Array();
		var qteArray = Array();
		showErrorLabels($(this).find('#numero'),'empty')
		showErrorLabels($(this).find('#qualite'),'empty')
		//showErrorLabels($(this).find('input[name=radioCivilite]'),'check')
		showErrorLabels($(this).find('#champNom'),'empty')
		showErrorLabels($(this).find('#champPrenom'),'empty')
		showErrorLabels($(this).find('#textAddresse'),'empty')
		showErrorLabels($(this).find('#champCodePostal'),'empty')
		showErrorLabels($(this).find('#AddresseMail'),'email')
		showErrorLabels($(this).find('#champVille'),'empty')
		showErrorLabels($(this).find('#selectPays'),'empty')
		showErrorLabels($(this).find('#message'),'empty')
		var objetVal = $('#numero').val()+" x "+$('#qualite').val()+" exemplaires\n"

		$('.numero').each(function(i)
		{
			//alert( $(this).val() );
			numeroArray.push( $(this).val() );
		});
		
		$('.qte').each(function(i)
		{
			//alert( $(this).val() );
			qteArray.push( $(this).val() );
		});
		
		for( i = 0; i < numeroArray.length; i++ )
		{
			objetVal = objetVal + numeroArray[i] +" x "+qteArray[i]+" exemplaires\n";
		}

		$('#champObjet').val( objetVal );
		
		//e.preventDefault();
		//$('#champVille').val( $('#champVille').val() + $('#selectPays').val() );
		if(controlForm!=0)
		{
			e.preventDefault();
		}
	});
	//formulaire de commentaire
	$('#CommentAddForm').submit(function(e)
	{
		controlForm = 0;
		showErrorLabels($(this).find('textarea[name=CommentContent]'),'empty')
		if(controlForm!=0)
		{
			e.preventDefault();
		}
	});
	// Limiter aux caractères numériques dans les champs de saisie
	restrictNum();
	function restrictNum()
	{
		$('.restrictNum').keydown(function(){ preventKey($(this)) });
		$('.restrictNum').keyup(function(){ preventKey($(this)) });
		$('.restrictNum').blur(function(){ preventKey($(this)) });
		$('.restrictNum').click(function(){ preventKey($(this)) });
	}
	function preventKey(elem)
	{
		if(elem.val()!=''||(/[^0-9]/).test(elem.val()))
		{
			elem.val(elem.val().replace(/[^0-9]/,''));
		}
	}
	$('#selectPetitesAnnonces').submit(function(e)
	{
		e.preventDefault();
		newLocationWindow = $(this).attr('action')+'annonces/'+$('#lib_rubrique').val();
		window.open(newLocationWindow);
	});
	$('#formAnciensNumeros .btnAjouter').click(function()
	{
		inputLength = Math.ceil($(this).closest('.formulaire').find('.restrictNum').length/2);
		$('<div><label>N&deg; suppl&eacute;mentaire&nbsp;:</label><input type="text" class="numero restrictNum" name="numero'+(inputLength+1)+'" maxlength="4" /></div><div><label for="qualite">La quantit&eacute; souhait&eacute;e&nbsp;:</label><input type="text" id="qualite" class="qte restrictNum" name="qualite'+(inputLength+1)+'" maxlength="3" /></div>').insertBefore($(this).closest('.btnCont'));
		restrictNum();
	});
	// Action du champ "rechercher"
	$('#inputMotsCles').hide();
	$('#searchTextTop').keyup(function(e)
	{
		$('#inputMotsCles').val($(this).val())
		$('#inputTerm').val($(this).val())
		
	});
	$('#searchTextTop').change(function()
	{
		$('#inputMotsCles').val($(this).val())
		$('#inputTerm').val($(this).val())
	});
	$('#searchTextTopForm').submit(function(e)
	{
		//openNewpage($('#searchForm'),'#siteRecherche','cavadeos');
		//console.log($('#searchForm'))
		e.preventDefault();
		$('#searchForm input[type=submit]').get(0).click();
	});
	$('#searchForm').submit(function()
	{
		openNewpage($(this),'#siteRecherche','cavadeos');
	});
	$('.tabs .abonnement a').addClass('current');
	$('.paneBlock').hide();
	$('.paneBlock.abonnementCont').show();
	$('.tabs li a').each(function(i,e)
	{
		$(this).click(function(e)
		{
			e.preventDefault();
			$('.tabs li a').removeClass('current');
			$(this).addClass('current');
			$('.paneBlock').hide();
			$('.paneBlock:eq('+(i)+')').show();
		});
	});
	
	
	$('#panes .abonnementCont .firstDl dt .zoneActive, #panes .inscriptionCont .firstDl dt .zoneActive').mouseover(
	function()
	{
		
		$(this).closest('dt').find('.bigger').show();
	});
	$('#panes .abonnementCont .firstDl dt .bigger, #panes .inscriptionCont .firstDl dt .bigger').mouseout(
	function()
	{
		$(this).closest('dt').find('.bigger').hide();
	});
	$('#siteRecherche').change(function()
	{
		if($(this).val()!='cavadeos')
		{
			$('#rechercheRegions, #rechercheVideos, #rechercheArticles, #recherchePhotos, #rechercheAudio').attr('disabled','disabled')
		} else {
			$('#rechercheRegions, #rechercheVideos, #rechercheArticles, #recherchePhotos, #rechercheAudio').attr('disabled','')
		}
	});
	// Frise horizontal des résultats sportifs events
	if($('#scrollerList').length>0)
	{
		$('.mainSportTab table').each(function()
		{
			$(this).wrap('<div class="tableSportInfo"></div>');
			$(this).closest('.tableSportInfo').appendTo('.mainSportTab .pane');
		});
		
		var friseLargeur = 0;
		$('#scrollerList li').each(function()
		{
			friseLargeur+=(parseInt($(this).width())+2);
		});
		var NbElement=$('#scrollerList li').length;
		$('#scrollerList ul.items').css('width',friseLargeur+'px');
		$('.btnPrevList').mousedown(function()
		{
			if(NbElement>3)
			{
				alwaysMoveRight = setInterval(function()
					{
						if(parseInt($('#scrollerList ul.items').css('left'))<0)
						{
							$('#scrollerList ul.items').css({'left':parseInt($('#scrollerList ul.items').css('left'))+5+'px'})
						}
					},1);
			}
		});
		$('#scrollerList').prev('.btnPrevList').mouseup(function()
		{
			clearInterval(alwaysMoveRight);
		});
		var maxLargeur = -(friseLargeur-parseInt($('#scrollerList').width()));
		$('.btnNextList').mousedown(function()
		{
			var containerMarginLeft = parseInt($('.tabContainerFrise').css('left'));
			if(NbElement>3)
			{
				//alert(parseInt($('#scrollerList ul.items').css('left'))+','+-(friseLargeur-parseInt($('#scrollerList').width()) ))
				alwaysMoveLeft = setInterval(function()
				{
						if(parseInt($('#scrollerList ul.items').css('left'))>maxLargeur)
						{
							$('#scrollerList ul.items').css({'left':parseInt($('#scrollerList ul.items').css('left'))-5+'px'})
						}
					},1);
			}
		});
		$('#scrollerList').next('.btnNextList').mouseup(function()
		{
			clearInterval(alwaysMoveLeft);
		});
		
	}
	$('#mainContent .sportBlog .tab li').each(function(i,e)
		{
			if($(e).hasClass('active'))
			{
				tabIndex=i;
			}
		});
});

$(function() {
	$("ul.tab").tabs("div.pane > div",{
		initialIndex:tabIndex
	});

// Select boxes
$('#navSelect').submit(
	function(e)
	{
		e.preventDefault();
		document.location = $(this).find('select').val();
	});
});
// Ouvrir form dans une nouvelle fenêtre
function openNewpage(formId,selectId,currentVal)
{
	if($(selectId).val()!=currentVal)
	formId.attr('target','_blank');
	else
	formId.attr('target','_self');
	if( $(selectId).val() == "guide" )
	formId.attr('action','http://elevage.leperon.fr/search/' );
	if( $(selectId).val() == "annuaire" )
	formId.attr('action','http://annuaire.leperon.fr/search/' );
	if( $(selectId).val() == "cavadeos" ||$(selectId).val() == "pa" ||$(selectId).val() == "cavalivre" )
	formId.attr('action', '/content/action' );
}

//les rollover de la sous nav//
var lateTemp = 0;
var closetimer = 0;
$(document).ready(function(){
	$('.subNav').hide();
	$('#nav ul:first li.active .subNav').show();
	$('#nav ul:first li').mouseover(function()
	{
		$('#nav ul.nav1 > li').removeClass('current');
		$(this).addClass('current');
		nav_canceltimer(closetimer);
		$('.subNav').hide();
		$('#nav ul.nav1 > li.active').attr('class','desactive');
		$(this).find('.subNav').show();
	});
	$('#nav ul.nav1 > li').mouseout(function()
	{
		currentItem = $(this);
		closetimer = window.setTimeout(function()
		{
			currentItem.removeClass('current');
			$('.subNav').hide();
			$('#nav ul.nav1 > li.desactive').attr('class','active');
			currentItem.find('.subNav').hide();
			$('#nav ul.nav1 li.active .subNav').show();
		},1000);
	});
	$('#nav ul.subNav').prev('a:not(.evenements)').click(function(e)
	{
		e.preventDefault();
	});
});

function nav_canceltimer(timerName)
	{  if(closetimer)
	   {  window.clearTimeout(timerName);
		  timerName = null;}}


$(document).ready(function() {
 //l'info flash//
/*window.api = $("#scroller").scrollable({size: 1}).circular().autoscroll({
	autoplay: true,
	api: true
	});*/
	var flashPlay;
	if($('.scrollable').length>0)
	{
		var settime = 3000;
		var scrollerLength = $('#scroller .items p').length;
		var scrollerWidth = $('#scroller .items p').width()*scrollerLength;
		$('#scroller .items p').clone().appendTo($('#scroller .items'));
		var scrollerLength2 = $('#scroller .items p').length;
		var scrollerWidth2 = $('#scroller .items p').width()*scrollerLength2;
		$('#scroller .items').width(scrollerWidth2);
		flashPlay = window.setInterval(function()
		{
			flashInterval(scrollerWidth);
		},settime);
		$('#content .contHeader .pause').click(function(e)
		{
			e.preventDefault();
			if($(this).hasClass('pause'))
			{
				clearInterval(flashPlay);
				$(this).attr('class','play');
			} else {
				flashPlay = window.setInterval(function()
				{
					flashInterval(scrollerWidth);
				},settime);
				$(this).attr('class','pause');
			}
		});

		$('#content .contHeader .browse').click(function(e)
		{
			e.preventDefault();
			var currentIncr = '-=';
			var currentItem = $(this);
			if(currentItem.hasClass('prevPage'))
			{
				currentIncr = '+=';
			}
			if(currentItem.hasClass('nextPage'))
			{
				currentIncr = '-=';
			}
			if(!$('#scroller .items').is(':animated'))
			{
				if(currentItem.hasClass('prevPage')&&parseInt($('#scroller .items').css('left'))>=0)
					{
						$('#scroller .items').css('left',-(scrollerWidth)+'px');
					}
					if(currentItem.hasClass('nextPage')&&parseInt($('#scroller .items').css('left'))== -(scrollerWidth))
					{
						$('#scroller .items').css('left','0');
					}
				$('#scroller .items').animate({"left": currentIncr+$('#scroller .items p').width()+'px'},'swing');
			}
			if($('#content .contHeader .pause').hasClass('pause'))
			{
				clearInterval(flashPlay);
				flashPlay = window.setInterval(function()
				{
					flashInterval(scrollerWidth);
				},settime);
			}
		});
	}
	
	
function flashInterval(scrollerWidth)
{
	$('#scroller .items').animate({"left": '-='+$('#scroller .items p').width()+'px'},'swing',function()
		{
			if(parseInt($('#scroller .items').css('left'))== -(scrollerWidth))
			{
				$('#scroller .items').css('left','0');
			}
		});
}

$('#formLoginTop input').focus(function()
{
	if($(this).val()=='Entrez votre e-mail'||$(this).val()=='Mot de passe')
	$(this).val('');
});
$('.annonceAnnuaire input[type=text]').focus(function()
{
	$(this).val('');
});
$('#foot li:first').addClass('firstLi');

// Défilement des images dans la mise en avant du haut

//$('.infoCourse dl.actif').hide();
$('.infoCourse .vignetteCourse .thumbnail .cache:first(.actif)').hide();
$('.infoCourse .contenu:not(.actif)').hide();
$('.infoCourse .contenu_titre:not(.actif)').hide();
$('.infoCourse .vitrineContenu:not(.actif)').hide();

$('.infoCourse .vignetteCourse .thumbnail').each(function()
{								   
								   
	$(this).click(function()
		{
			$('.infoCourse .vignetteCourse .thumbnail .cache').show();
			$(this).find('.cache').hide();
		});
});

$('.infoCourse .vignetteCourse .thumbnail').each(function(i,e)
	{
		$(this).click(function()
		{
			$('.infoCourse .contenu').hide();
			$('.infoCourse .contenu_titre').hide();
			$('.infoCourse .vitrineContenu').hide();
			//$('.infoCourse .thumbnail:not(:visible)').show();
			//$(this).hide();
			$('.infoCourse .contenu:eq('+i+')').show();
			$('.infoCourse .vitrineContenu:eq('+i+')').show();
			$('.infoCourse .contenu_titre:eq('+i+')').show();
			//hideThumbs();
			
			
		});
		
	 });

function carousselAuto() {
	var j = 0;
	setInterval(function(){ 
		j = j + 1;
		if(j > $('.vitrineContenu').length -1){
		  j = 0;
		}
		$(".vitrine .vitrineContenu,.courseDetail .contenu").hide();
		$(".vitrine .vitrineContenu:eq("+j+"),.courseDetail .contenu:eq("+j+")").show(); 
	$('.thumbnail:eq('+j+')').trigger('click');
	//console.log(j); 
	},6000);
}
$(document).ready(function(){	
  var email =  $('#term');	
	//console.log(email.val());
	 verifMotcles(email.val());	   
});
//carousselAuto();
/* var k = 0;
 setInterval(function(){ k++;
j = (k > $('.contenu').length)? 0 : k + 1;
$(".courseDetail .contenu").hide();
$(".courseDetail .contenu:eq("+k+")").show();
return k; },2000);*/

 
	
 
  

	// Sélections de la fiche contact
	if($('.selectService').length>0)
	{
		$('.selectService').hide();
		var url = document.location.href;
		var currentChoice = getParamValue( 'requested', url );
		if(currentChoice)
		{
			$('#selectDemande').val(currentChoice)
		}
		var currentService = getParamValue( 'service', url );
		if(currentService)
		{
			$('#selectService01').val(currentService)
		}
		$('select#'+ $('#selectDemande option:selected').attr('class')).show();
		$('.redaction div').hide();
		var currentOptionContact = $('.selectService:visible').find('option:selected').attr('class').replace('Opt','')
		$('.redaction #'+currentOptionContact).show();
		$('#selectDemande').change(function()
		{
			$('.selectService').hide();
			$('select#'+ $('#selectDemande option:selected').attr('class')).show();
			$('.redaction div').hide();
			$('.redaction #'+ $('.selectService:visible').find('option:selected').attr('class').replace('Opt','')).show();
		});
		$('.selectService').change(function()
		{
			$('.redaction div').hide();
			$('.redaction #'+ $(this).find('option:selected').attr('class').replace('Opt','')).show();
		});
	}
	// Carousel de la page article
	// Fade in / fade out des images successives dans un caroussel
	function fadeEffect(elem,txt)
	{
		
		if(!elem.closest('.player').find('.vitrineContenu').is(':animated'))
		{
			
			elem.closest('.player').find('.vitrineContenu:visible').css('z-index','97');
			elem.css('z-index','98').fadeIn(function()
			{
				elem.siblings('.vitrineContenu').hide();
				txt.siblings('.legendePhoto').hide();
				elem.show();
				txt.show();
			});
			elem.siblings('.vitrineContenu').fadeOut(function(){});
			txt.siblings('.legendePhoto').fadeOut(function(){});
		}
	}
	// Images en fondu enchainé de la page article
	$('.infoElevage .elevageCont .playerCont .player .vitrineContenu').hide();
	setTimeout(function()
	{
		$('.vitrineContenu').each(function()
		{
			var newMargin = 0;
			var imgWidth = parseInt($(this).find('img').attr('width'));
			var largeurImg = ($(this).closest('.playerCont ').length > 0 )? 405 :  300;
			if(imgWidth<largeurImg)
			{
				
				newMargin = parseInt((largeurImg-imgWidth)/2);
				$(this).css({
					'width':imgWidth+'px',
					'padding-left':newMargin+'px'
				});
			}
			
			
			$(this).find('.credit').css('width',(imgWidth-10)+'px');
		});
	},1);
	$('.infoElevage .elevageCont .playerCont .legendePhoto').hide();
	$('.infoElevage .elevageCont .playerCont .player .vitrineContenu:first').show();
	$('.infoElevage .elevageCont .playerCont .legendePhoto:first').show();
	$('.infoElevage .elevageCont .playerCont .player .vitrineContenu:first').css('z-index','97');
	if($('.infoElevage .elevageCont .playerCont').length>0)
	{
		var shadeImages;
		shadeImages = setInterval(function()
		{
			nextShadeImg();
		},6000);
	}
	function nextShadeImg()
	{
		if($('.infoElevage .elevageCont .playerCont .player .vitrineContenu:visible').next('.vitrineContenu').length==0)
		{
			fadeEffect($('.infoElevage .elevageCont .playerCont .player .vitrineContenu:first'),$('.infoElevage .elevageCont .playerCont .legendePhoto:first'));
		}
		else
		{
			fadeEffect($('.infoElevage .elevageCont .playerCont .player .vitrineContenu:visible').next(),$('.infoElevage .elevageCont .playerCont .legendePhoto:visible').next());
		}
		clearInterval(shadeImages);
		shadeImages = setInterval(function()
		{
			nextShadeImg();
		},6000);
	}
	$('.infoElevage .elevageCont .playerCont .btnNext').click(
	function(e)
	{
		e.preventDefault();
		nextShadeImg();
	});
	$('.infoElevage .elevageCont .playerCont .btnPrev').click(
	function(e)
	{
		e.preventDefault();
		if($('.infoElevage .elevageCont .playerCont .player .vitrineContenu:visible').prev('.vitrineContenu').length==0)
		{
			fadeEffect($('.elevageCont .playerCont .player .vitrineContenu:last'),$('.infoElevage .elevageCont .playerCont .legendePhoto:last'));
		}
		else
		{
			fadeEffect($('.infoElevage .elevageCont .playerCont .player .vitrineContenu:visible').prev(),$('.infoElevage .elevageCont .playerCont .legendePhoto:visible').prev());
		}
		clearInterval(shadeImages);
		shadeImages = setInterval(function()
		{
			nextShadeImg();
		},2000);
	});
	// Caroussel des vidéos dans page article
	$(function(){
       var tabListe = new Array();
       $('.autrePlayer ul li').hide();
       $('.autrePlayer ul li:first').show();
        
        $('.autrePlayer ul li').each(function(i){
            tabListe.push($(this));
        });
        //alert($(".video").length);
        var index = 0;
        $(".autrePlayer .btnNext").click(function(){
           index = (index >= tabListe.length - 1)? 0 :  index + 1;
           $('.autrePlayer ul li').hide();
           $('.autrePlayer ul li:eq('+index+')').show();
           return index;
        });
        $(".autrePlayer .btnPrev").click(function(){
           index = (index <= 0)? tabListe.length - 1 :  index - 1;
           $('.autrePlayer ul li').hide();
           $('.autrePlayer ul li:eq('+index+')').show();
           return index;
        });
        
    });
	/*if($('.infoElevage .elevageCont .autrePlayer .video ul li').length>1)
	{
		$('.infoElevage .elevageCont .autrePlayer .video').carousel('.infoElevage .elevageCont .autrePlayer .btnPrev', '.infoElevage .elevageCont .autrePlayer .btnNext');
	} else {
		$('.infoElevage .elevageCont .autrePlayer .btnNext, .infoElevage .elevageCont .autrePlayer .btnPrev').css('visibility','hidden');
	}*/
	// Caroussel contextuel dans page article
$('.infoElevage .elevageContext .contextTv .contextPlayer .video').carousel('.infoElevage .elevageContext .contextTv .contextPlayer .btnPrev', '.infoElevage .elevageContext .contextTv .contextPlayer .btnNext');
	// Gestion de hauteur du contenu et de la zone contextuelle
	setTimeout(function()
	{
		if($('#mainContent').height()<$('#context').height())
		{
			$('#mainContent, #mainContent .infoElevage'/*,  #mainContent .rubriqueAccessRestreint, #mainContent .contactMain, #mainContent .planDuSite, #searchNoResult'*/).css('min-height',$('#context').height()+'px');
		}
	},1000);
	
	 /*if($('#mainContent .info').length>0&&$('#mainContent .info').next().length==0)
	{
		$('#mainContent').css('background-color','#ece9e2');
	}*/
});

// L'overlay pour mot de pass oublier
/*$(function() {
		$("a[rel]").overlay({effect: 'apple', top:190, left:340});
});*/
$(document).ready(function() {
						  
 //l'info flash//
 /*if($(".flash").length>0)
 {
window.api = $("#scrollerList").scrollable({size: 1})({
	});
 }*/
});

// Caroussels


 

$.fn.carousel = function(previous, next, options){
	var sliderList = $(this).children()[0];
	if (sliderList) {
		var increment = $(sliderList).children().outerWidth(true);
		// Hack pour régler le problème de largeur sous Mac
		if($(this).parent().attr('class')=='contextPlayer')
		{
			increment = 180;
		}
		var elmnts = $(sliderList).children(),
		numElmts = elmnts.length,
		sizeFirstElmnt = increment,
		shownInViewport = Math.round($(this).width() / sizeFirstElmnt),
		firstElementOnViewPort = 1,
		isAnimating = false;

		for (i = 0; i < shownInViewport; i++) {
			$(sliderList).css('width',(numElmts+shownInViewport)*increment + increment + "px");
			$(sliderList).append($(elmnts[i]).clone());
		}

		$(previous).click(function(event){
			if (!isAnimating) {
				if (firstElementOnViewPort == 1) {
					$(sliderList).css('left', "-" + numElmts * sizeFirstElmnt + "px");
					firstElementOnViewPort = numElmts;
				}
				else {
					firstElementOnViewPort--;
				}
				$(sliderList).find('.myExperience').each(function()
				{
					saveHTML=$(this).html();
					$(this).empty();
					$(this).html(saveHTML);
				});
				$(sliderList).animate({
					left: "+=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){
					isAnimating = false;
				});
				isAnimating = true;
			}
		});

		$(next).click(function(event){
			if (!isAnimating) {
				if (firstElementOnViewPort > numElmts) {
					firstElementOnViewPort = 2;
					$(sliderList).css('left', "0px");
				}
				else {
					firstElementOnViewPort++;
				}
				$(sliderList).find('.myExperience').each(function()
				{
					saveHTML=$(this).html();
					$(this).empty();
					$(this).html(saveHTML);
				});
				$(sliderList).animate({
					left: "-=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){
					isAnimating = false;
				});
				isAnimating = true;
				
			}
		});
	}
};

//var controlForm = 0;
// hover sur les titre gabarit recherche resultat pour apparaitre l'image correspondant //
$(document).ready(function() {
						   
 
	

						  
	//var followTrigger = new Spry.Widget.Tooltip('illustration1', '.title1', {followMouse: true});
	/*var followTrigger = new Spry.Widget.Tooltip('illustration2', '.title2', {followMouse: true});
	var followTrigger = new Spry.Widget.Tooltip('illustration3', '.title3', {followMouse: true});
	var followTrigger = new Spry.Widget.Tooltip('illustration4', '.title4', {followMouse: true});*/
	$('.rechercheReponses .tableAffichage .title').each(function(i,e){
		$(this).mouseover(function()
		{
			followPopup($('.resultatsImages img:eq('+i+')'));
		});
		$(this).mouseout(function()
		{
			stopPopup($('.resultatsImages img:eq('+i+')'));
		});
	});
	var offset = $('body').offset();
	function followPopup(element) {
		element.show();
		$('body').bind('mousemove',function(e)
		{
			element.css({
					'left':(e.pageX - offset.left + 30)+'px',
					'top':(e.pageY - offset.top)+'px'
			});
		});
	}
	function stopPopup(elem)
	{
		elem.hide();
		$('body').unbind('mousemove');
	}

	$('.cavadeosVideo .cavadeosTvCont .videoCont').mouseover(function()
	{
		$(this).find('.videoDetail').hide();
	});
	$('.cavadeosVideo .cavadeosTvCont .videoCont').mouseout(function()
	{
		$(this).find('.videoDetail').show();
	});
	$('#formOubliPassword').submit(function(e)
	{

		showErrorLabels($(this).find('#oubliEmail'),'email')
		if(controlForm!=0)
		{
			e.preventDefault();
		}
	});
});

function showErrorLabels(elem,control)
{
	if(control=='check')
	{
		if(!elem.is(':checked'))
		{
			elem.closest('div').next('.error').show();
			controlForm = controlForm + 1;
		} else {
			elem.closest('div').next('.error').hide();
		}
	}
	if(control=='email')
	{
		if(!elem.val().match(/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/)||elem.val()=='')
		{
			elem.closest('div').next('.error').show();
			controlForm = controlForm + 1;
		} else {
			elem.closest('div').next('.error').hide();
		}
	}
	if(control=='number')
	{
		if(elem.val().match(/[^0-9]/)||elem.val()=='')
		{
			elem.closest('div').next('.error').show();
			controlForm = controlForm + 1;
		} else {
			elem.closest('div').next('.error').hide();
		}
	}
	if(control=='empty')
	{
		if(elem.val()=='')
		{
			elem.closest('div').next('.error').show();
			controlForm = controlForm + 1;
		} else {
			elem.closest('div').next('.error').hide();
		}
	}
	return controlForm;
}


// Find param in url
function getParamValue(param,url)
	{
		var u = url == undefined ? document.location.href : url;
		var reg = new RegExp('(\\?|&|^)'+param+'=(.*?)(&|$)');
		matches = u.match(reg);
		if(matches)
		{
			return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g,' ') : '';
		}
	}

/////////////////////////////////////////////////////////////
// EP Player v2 - JS API
// ----------------------------------------------------------
// Control functions
/////////////////////////////////////////////////////////////
function EP_get(id) {
	var el = document.getElementById(id);
	if(el && el.EP_isLoaded) {
		return el;
	} else {
		alert('\''+ id +'\' not found!');
		return;
	}
}

/////////////////////////////////////////////////////////////
function EP_play(id) {
	var p = EP_get(id);
	if(p) p.EP_play();
}

/////////////////////////////////////////////////////////////
function EP_setVolume(id, v) {
	var p = EP_get(id);
	if(p) p.EP_setVolume(v);
}

/////////////////////////////////////////////////////////////
function EP_pause(id) {
	var p = EP_get(id); 
	if(p) p.EP_pause();
}

/////////////////////////////////////////////////////////////
function EP_stop(id) {
	var p = EP_get(id); 
	if(p) p.EP_stop();
}

/////////////////////////////////////////////////////////////
function EP_playPause(id) {
	var p = EP_get(id); 
	if(p) p.EP_playPause();
}

/////////////////////////////////////////////////////////////
function EP_prev(id) {
	var p = EP_get(id); 
	if(p) p.EP_prev();
}

/////////////////////////////////////////////////////////////
function EP_next(id) {
	var p = EP_get(id); 
	if(p) p.EP_next();
}

/////////////////////////////////////////////////////////////
function EP_setShuffle(id, v) {
	var p = EP_get(id); 
	if(p) p.EP_setShuffle(v);
}

/////////////////////////////////////////////////////////////
function EP_setRepeat(id, v) {
	var p = EP_get(id); 
	if(p) p.EP_setRepeat(v);
}

/////////////////////////////////////////////////////////////
function EP_setAutoPlay(id, v) {
	var p = EP_get(id); 
	if(p) p.EP_setAutoPlay(v);
}

/////////////////////////////////////////////////////////////
function EP_addTracks(id, xml, i) {
	var p = EP_get(id); 
	if(p) p.EP_addTracks([xml, i]);
}

/////////////////////////////////////////////////////////////
function EP_removeTracks(id, xml) {
	var p = EP_get(id); 
	if(p) p.EP_removeTracks(xml);
}

/////////////////////////////////////////////////////////////
function EP_loadPlaylist(id, f) {
	var p = EP_get(id); 
	if(p) p.EP_loadPlaylist(f);
}

/////////////////////////////////////////////////////////////
function EP_setPlaylist(id, xml, s) {
	var p = EP_get(id); 
	if(p) p.EP_setPlaylist(xml);
	if(s == true) EP_play(id);
}

/////////////////////////////////////////////////////////////
function EP_clearPlaylist(id) {
	var p = EP_get(id); 
	if(p) p.EP_clearPlaylist();
}

/////////////////////////////////////////////////////////////
function EP_playTrack(id, i) {
	var p = EP_get(id); 
	if(p) p.EP_playTrack(i);
}

/////////////////////////////////////////////////////////////
function EP_getCurrentTrackData(id) {
	var p = EP_get(id); 
	if(p) return p.EP_getCurrentTrackData();
	return new Object();
}

/////////////////////////////////////////////////////////////
function EP_getTrackData(id , i) {
	var p = EP_get(id); 
	if(p) return p.EP_getTrackData(i);
	return new Object();
}

/////////////////////////////////////////////////////////////
function EP_setSize(id, w, h) {
	var el = EP_get(id);
	if(el) {
		el.style.width = w;
		el.style.height = h;
	}
}

/////////////////////////////////////////////////////////////
// Callback functions
/////////////////////////////////////////////////////////////
function EP_onLoad(id) {
	// alert(id +': onLoad');
}

function EP_onPlay(id) {
	// alert(id +': onPlay');
}

/////////////////////////////////////////////////////////////
function EP_onStop(id) {

}

/////////////////////////////////////////////////////////////
function EP_onPause(id) {

}

/////////////////////////////////////////////////////////////
function EP_onNext(id) {

}

/////////////////////////////////////////////////////////////
function EP_onPrev(id) {

}

/////////////////////////////////////////////////////////////
function verifMotcles (email)
{
	 
	
	
	$('#search').click (function (e)
	{	
		//console.log($('#locality').val());
		 if ( $('#term').val().length == 0 || email==$('#term').val() )
		 {
			 e.preventDefault();
			 $('.erreur').remove();
			 var mErreur = "Veuillez saisir un Mot cl&eacute; !";
			 var eErreur = '<span class="erreur">'+mErreur+'</span>';
			 $('#term').after(eErreur);
			 
			 
		}
		//if($('#locality').val() == 'Code postal / Région')
		//	$('#locality').val==('');
		
	
	});
	
	$('#search input[type=submit]').click(function(){
		var motifCP = /^Code po/;
		if(motifCP.test($('#locality').val())){
			$('#locality').val('');
		}		
	});
}


$(document).ready(function() {
 //l'info flash du shf//
/*window.api = $("#scroller01").scrollable({size: 1}).circular().autoscroll({
	autoplay: true,
	api: true
	});*/
	var flashPlay01;
	if($('#context .scrollShf').length>0)
	{
		var settime = 3000;
		var scrollerLength = $('#context #scroller01 .items p').length;
		var scrollerWidth = $('#context #scroller01 .items p').width()*scrollerLength;
		$('#context #scroller01 .items p').clone().appendTo($('#context #scroller01 .items'));
		var scrollerLength2 = $('#context #scroller01 .items p').length;
		var scrollerWidth2 = $('#context #scroller01 .items p').width()*scrollerLength2;
		$('#context #scroller01 .items').width(scrollerWidth2);
		flashPlay01 = window.setInterval(function()
		{
			flashInterval2(scrollerWidth);
		},settime);

		$('.pauseshf').click(function(e)
		{
			clearInterval(flashPlay01);
			$(this).hide();
			$('#context .playshf').css('display','block');
		});

		$('#context .playshf').click(function(e)
		{
			flashPlay01 = window.setInterval(function()
			{
				flashInterval2(scrollerWidth);
			},settime);
			$(this).hide();
			$('#context .pauseshf').css('display','block');
		});
		
		$('#context .contHeader .browse').click(function(e)
		{
			e.preventDefault();
			var currentIncr = '-=';
			var currentItem = $(this);
			if(currentItem.hasClass('prevPage'))
			{
				currentIncr = '+=';
			}
			if(currentItem.hasClass('nextPage'))
			{
				currentIncr = '-=';
			}
			if(!$('#context #scroller01 .items').is(':animated'))
			{
				if(currentItem.hasClass('prevPage')&&parseInt($('#context #scroller01 .items').css('left'))>=0)
					{
						$('#context #scroller01 .items').css('left',-(scrollerWidth)+'px');
					}
					if(currentItem.hasClass('nextPage')&&parseInt($('#context #scroller01 .items').css('left'))== -(scrollerWidth))
					{
						$('#context #scroller01 .items').css('left','0');
					}
				$('#context #scroller01 .items').animate({"left": currentIncr+$('#context #scroller01 .items p').width()+'px'},'swing');
			}
			if($('#context .contHeader .pause').hasClass('pause'))
			{
				clearInterval(flashPlay01);
				flashPlay01 = window.setInterval(function()
				{
					flashInterval2(scrollerWidth);
				},settime);
			}
		});
	}
	
	function flashInterval2(scrollerWidth)
	{
		$('#context #scroller01 .items').animate({"left": '-='+$('#context #scroller01 .items p').width()+'px'},'swing',function()
			{
				if(parseInt($('#context #scroller01 .items').css('left'))== -(scrollerWidth))
				{
					$('#context #scroller01 .items').css('left','0');
				}
			});
	}

	});

