/*JS*/
$(document).ready(function() {		
	
	if($('#moreInfo').length) {
		hoverInfoHome();
	}
	
	if($('#moteurResa_home').length) {
		switcherResaHome();
		/*$("#moteurResa_home input.datepicker").datepicker({
			showOn: 'both',
			buttonImage: 'images/common/btn_datepicker.png'	,
			changeMonth: true,
			changeYear: true,			
			minDate: 0,			
			buttonText: 'Choisissez votre date de départ'		
		});*/
		update_calendrier('selectPays1','selectListeStations1','selectListeDuree1','selectListeNombre1','piscineSemaine','skisAuxPiedsSemaine','valueBudget',1,false);
		update_calendrier('selectPays2','selectListeStations2','rechercheWeekEnd[duree]','selectListeNombre2','piscineWeekEnd','skisAuxPiedsWeekEnd','valueBudgetWE',2,false);
		
		$("#sliderBudget").slider({
			value:0,
			min: 0,
			max: 5,
			step: 1,
			slide: function(event, ui) {
				$("#valueBudget").val(ui.value);
			},
			stop: function(event, ui) {
				update_calendrier('selectPays1','selectListeStations1','selectListeDuree1','selectListeNombre1','piscineSemaine','skisAuxPiedsSemaine','valueBudget',1);
			}
		});
		$("#valueBudget").val($("#sliderBudget").slider("value"));
		
		$("#sliderBudgetWE").slider({
			value:0,
			min: 0,
			max: 5,
			step: 1,
			slide: function(event, ui) {
				$("#valueBudgetWE").val(ui.value);
			},
			stop: function(event, ui) {
				update_calendrier('selectPays2','selectListeStations2','rechercheWeekEnd[duree]','selectListeNombre2','piscineWeekEnd','skisAuxPiedsWeekEnd','valueBudgetWE',2);
			}
		});
		$("#valueBudgetWE").val($("#sliderBudgetWE").slider("value"));
		$('#moteurResa_home select').sSelect({ddMaxHeight: '155px'});
		showMoreCriteriaHome();
		nightNumberActive();
	}
	
	$('#nav li li:last-child').addClass('last');
	
		
	if($('#moteurResa_common').length) {
		if($('#switcherResa_common').length) {
			switcherResaCommon(); 
			nightNumberActiveCommon();
			update_calendrier_bas('selectPays1','selectListeStations1','selectListeDuree1','selectListeNombre1','piscineSemaine','skisAuxPiedsSemaine',1,false);
			update_calendrier_bas('selectPays2','selectListeStations2','rechercheWeekEnd[duree]','selectListeNombre2','piscineWeekEnd','skisAuxPiedsWeekEnd',2,false);
		} else {
			update_calendrier_interne(false);
		}
		$('#moteurResa_common select').sSelect({ddMaxHeight: '155px'});
		/*$("#moteurResa_common input.datepicker").datepicker({
			showOn: 'both',
			buttonImage: 'images/common/btn_datepicker.png'	,
			changeMonth: true,
			changeYear: true,			
			minDate: 0,
			buttonText: 'Choisissez votre date de départ'		
		});*/
		showMoreCriteria();		
	}
	
	/*if($('#moteurResa_quick').length) {
		$('#moteurResa_quick select').sSelect({ddMaxHeight: '155px'});
		$("#moteurResa_quick input.datepicker").datepicker({
			showOn: 'both',
			buttonImage: 'images/common/btn_datepicker.png'	,
			changeMonth: true,
			changeYear: true,			
			minDate: 0,
			buttonText: 'Choisissez votre date de départ'		
		});		
	}*/
	
	if($('#tabResidence').length) {
		switchSeason();
	}
	
	if($('#flashCarousel_container').length) {
		$('#flashCarousel_container select').sSelect({ddMaxHeight: '155px'});
	}
	
	if($('#filterResults').length) {
		$('#filterResults select').sSelect({ddMaxHeight: '155px'});
		highlightHebType();
	}
	
	if($('#blocSlider').length) {
		blocSlider();
		/*if($('#blocSlider div.moteurResa_quick').length) {
			$('#blocSlider div.moteurResa_quick select').sSelect({ddMaxHeight: '155px'});		
		}*/		
		
		if($('.moteurResa_quick').length) {
		$('.moteurResa_quick select').sSelect({ddMaxHeight: '155px'});
		}
		
		if($('#flip_dossiers').length) {
			switchFileEditor(); 	
      		
		}
	}
	
	if($('#events').length) {
		sliderEvent();
	}
	
	if($('#nbParticipant').length) {
		optionSlider();
	}
	
	if($('#carouselRecoResidence').length) {
		initCarouselReco();
	}
	
	if($('#selectMonthEvent').length) {
		$('#selectMonthEvent select').sSelect({ddMaxHeight: '155px'});
		selectMonthEvent();
	}
	
	if($('#sidebar_panier').length) {
		$('#sidebar_panier > div.recapOption select').sSelect({ddMaxHeight: '155px'});	
		skinControlCheckbox();	
		skinControlRadio();	
		flipTabRecap();
	}
	
	if($('#NumParticipant').length) {
		$('#NumParticipant select').sSelect({ddMaxHeight: '155px'});	
		$('#mainContent_panier .participantForm .optionSlider_content dd select').sSelect({ddMaxHeight: '155px'});	
		$('#mainContent_panier .participantForm p.formuleHebergement select').sSelect({ddMaxHeight: '155px'});	
	}
	
	
	/*
  if($('#tabAccount').length) {
		flipTabAccount();
	}
	*/
	
	if($('#globalFeedback').length) {
		$('#filterFeedback > p select ').sSelect({ddMaxHeight: '155px'});	
	}	
			
	/*GESTION POPIN*/
	$('a.popinLink').colorbox({opacity:"0.7" , photo: true , scrolling:false , current : "photo {current} sur {total}", scalePhotos:false });
	$('a.popinLink_ajax').colorbox({opacity:"0.7" , width:"650px" , close:"FERMER", maxHeight:"850px" , scalePhotos:false });/* maxHeight a 100% marche bien selon la hauteur du viewport */
	$('a.popinLink_inline').click(function() {
		var popinToShow = $(this).attr('href');			
		$.fn.colorbox({opacity:"0.7" , width:"650px", maxHeight:"850px", scalePhotos:false ,inline:true, href:popinToShow});
	});
	
	
/*only functions for IE 6*/
	if ($.browser.msie && $.browser.version <= 6 ) {
			try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {} //caching CSS images			
		
			navIE6();		
		}		
/*end IE6*/

	if($('#produitCourant').length )
	{
		
		var productId = $('#produitCourant').val();
		if($('#h3_'+productId).length)
		{
			document.getElementById('h3_'+productId).className="";
			choisir_produit(productId,document.getElementById('h3_'+productId));	
		}
	}
});

function navIE6() {
	$('#nav > li').hover(function() {
		$(this).addClass('hovered');
	},function() {
		$(this).removeClass('hovered');
	});
}

function highlightHebType() {
	$('#content table.offersResults .choiceHeb input[type="radio"]:checked').next('label').addClass('mySelection');	

	$hebTypeRadio = $('#content table.offersResults .choiceHeb input:radio');
	$hebTypeLabel = $('#content table.offersResults .choiceHeb label');
		
	$hebTypeRadio.click(function() {
			$brotherLabels = $(this).parent('p').parent('fieldset.choiceHeb').find('label');			
			$brotherLabels.removeClass('mySelection');
			$(this).next('label').addClass('mySelection');			
		});
		
	$hebTypeLabel.click(function() {
		$brotherLabels = $(this).parent('p').parent('fieldset.choiceHeb').find('label');			
		$brotherLabels.removeClass('mySelection');
		$(this).addClass('mySelection');
	});	
}

function hoverInfoHome() {
	$('#moreInfo').click(function() {
		$('#hoverInfo').slideDown(function() {
			$('body').one('click' , function() {
				$('#hoverInfo').fadeOut();
			});			
		});			
	});
	
	/*$('#hoverInfo #closeIt').click(function() {
		$('#hoverInfo').fadeOut();
	});	*/	
}

function showMoreCriteria() {
	$('#moteurResa_common .btn_moreCrit a.btn').click(function() {
		var moreCritToShow = $(this).attr('href').split('#');
		$('#'+moreCritToShow[1]).slideDown();
		return false;
	});
	
	$('#moteurResa_common img.closeIt').live("click" , function() {
		$(this).parent('fieldset').parent('div').slideUp();
	});	
}

function showMoreCriteriaHome() {
	$('#moteurResa_home .btn_moreCrit a.btn').click(function() {
		var moreCritToShow = $(this).attr('href').split('#');
		$('#'+moreCritToShow[1]).show('slide','normal');
		return false;
	});
	
	$('#moteurResa_home img.closeThis').live("click", function() {
		$(this).parent('fieldset').parent('div').hide('slide','normal');
	});	
}

/*function showMoreCriteria() {
	$('#moteurResa_common .btn_moreCrit').click(function() {
		$('#moreCrit').slideDown();
		return false;
	});
	
	$('#moreCrit #closeIt').click(function() {
		$('#moreCrit').slideUp();
	});
}*/


/*function showMoreCriteriaHome() {
	$('#moteurResa_home .btn_moreCrit').click(function() {
		$('#moreCritHome').show('slide','normal');
		return false;
	});
	
	$('#moreCritHome #closeThis').click(function() {
		$('#moreCritHome').hide('slide','normal');
	});	
}*/

function switcherResaHome() {
	$switchBlocResa = $('#moteurResa_home .switchBlocResa');
	$switchBlocResa.eq(0).show();
	$('#switcherResa_home > li').eq(0).addClass('active');	
	
	$('#switcherResa_home > li > label').click(function() {		
		var blocToShow = $(this).attr('id').split('trig_');
		$switchBlocResa.hide();
		$('#switcherResa_home > li').removeClass('active');
		$('#'+blocToShow[1]).show();	
		$(this).parent('li').addClass('active');
		
		$('#moreCritHome , #moreCritHome2 , #moreCritHome3').css('display','none');
	});			
}

function switcherResaCommon() {
	$switchBlocResa = $('#moteurResa_common .switchBlocResa');
	$switchBlocResa.eq(0).show();
	$('#switcherResa_common > li').eq(0).addClass('active');	
	
	$('#switcherResa_common > li > label').click(function() {		
		var blocToShow = $(this).attr('id').split('trig_');
		$switchBlocResa.hide();
		$('#switcherResa_common > li').removeClass('active');
		$('#'+blocToShow[1]).show();	
		$(this).parent('li').addClass('active');
		
		$('#moteurResa_common div.moreCrit').css('display','none');
	});		
}

function nightNumberActive() {
	$('#blocResaHome_2 label.skinedRadio').click(function() {
		$('#blocResaHome_2 label.skinedRadio').removeClass('selected');
		$(this).addClass('selected');
	});
}

function nightNumberActiveCommon() {
	$('#blocResaCommon_2 label.skinedRadio').click(function() {
		$('#blocResaCommon_2 label.skinedRadio').removeClass('selected');
		$(this).addClass('selected');
	});
}

function skinControlCheckbox() {
	$('#mainContent_panier label.skinnedCheckbox').click(function() {
		$(this).removeClass('selected').parent('td').next('td').children('span').addClass('greyBox');
		$(this).children('input:checked').parent('label').addClass('selected').parent('td').next('td').children('span').removeClass('greyBox');	
	});
}

function skinControlRadio() {
	$('#mainContent_panier label.skinnedRadio').click(function() {
		var nameRadio = $(this).children('input:radio').attr('name');		
		$("#mainContent_panier label.skinnedRadio input[name="+nameRadio+"]").parent('label.skinnedRadio').removeClass('selected');				
		$(this).addClass('selected');
		
		if($(this).parent('div.paymentType').length) {
			$('#mainContent_panier div.paymentType p').hide();
			$(this).next('p').show();
		}		
	});
}

function selectMonthEvent() {
	$('#selectMonthEvent label.skinedRadio').click(function() {
		$('#selectMonthEvent label.skinedRadio').removeClass('selected');
		$(this).addClass('selected');
	}) 
}

function blocSlider() {
	$blocSliderTrigger = $('#blocSlider li h3');
	$blocSliderContent = $('#blocSlider li .blocSliderContent');	

	if($('#blocSlider li h3.active').length) {
		$('#blocSlider li h3.active').next('div.blocSliderContent').show();
	}else {
		$blocSliderContent.eq(0).show();
		$blocSliderTrigger.eq(0).addClass('active');
	}
	
	$blocSliderTrigger.click(function() {
		$blocSliderContent.slideUp().children('p.priceDetails').find('.btn').css('visibility','visible');
		$blocSliderTrigger.removeClass('active');
		$(this).next('div:hidden').slideDown('normal',function() {
			$(this).prev('h3').addClass('active');
		});
	});	
}

function switchFileEditor() {
	$('#blocSlider > li ul.fileEditor > li').live("click", function() {		
		if($(this).find('a').length) {
			return true
		} else {	
			var fileBlocToShow = $(this).attr('class');
			if($(this).attr('id').length) {			
				$(this).removeAttr('id').parent('ul').nextAll('div.filEditorBox').hide();					
			}
			else {				
				$(this).removeAttr('id').siblings('li').removeAttr('id').parent('ul').nextAll('div.filEditorBox').hide();
				$(this).attr('id','active').parent('ul').nextAll('div.box_'+fileBlocToShow).show();		
			}
		}
	});
	
	$('#blocSlider .box_addFeedback label.labelRating').live("click", function() {
		$(this).removeClass('selected').siblings('label.labelRating').removeClass('selected');
		$(this).addClass('selected').prevAll('label.labelRating').addClass('selected');
	});	
	
	$('#blocSlider table.totalDossier td.payLine a.btn').live("click", function() {
		$('#blocSlider .blocSliderContent .filEditorBox').hide();
		$('#blocSlider .blocSliderContent ul.fileEditor li').removeAttr('id');
		$('#blocSlider .blocSliderContent .box_showPaiment').show();
		$('#blocSlider .blocSliderContent ul.fileEditor li.showPaiment').attr('id','active');		
	});	
	
}

function optionSlider() {
	$optionSliderTrigger = $('#mainContent_panier ul.optionSlider > li h3');
	//$optionSliderContent = $('#mainContent_panier ul.optionSlider > li .optionSlider_content');
	
	$('#mainContent_panier ul.optionSlider').each(function() {	
		if($(this).children('li').children('h3.active').length) {
			$('#mainContent_panier ul.optionSlider > li h3.active').next('div.optionSlider_content').show();
		}else {
			$(this).children('li').eq(0).children('h3').addClass('active').next('div.optionSlider_content').show();
		}	
	});
	
	/*$optionSliderTrigger.click(function() {
		$optionSliderContent.slideUp();
		$(this).parent('li').parent('ul').find('h3').removeClass('active');
		$(this).next('div:hidden').slideDown('normal',function() {
			$(this).prev('h3').addClass('active');
		});
	});	*/	
	
	$optionSliderTrigger.click(function() {
		$(this).toggleClass('active');
		$(this).next('div').slideToggle();
	});	
	
	$optionDescTrigger = $('#mainContent_panier ul.optionSlider > li .optionSlider_content dt .knowMore');
		
	$optionDescTrigger.toggle(function() {		
		$(this).parent('dt').nextAll('dd.descOption').show();
	}, function() {		
		$(this).parent('dt').nextAll('dd.descOption').hide();
	});	
}

function sliderEvent() {
	$('#events > li a.btn').click(function() {
		var myEventHeight = $(this).prev('div.innerEvent').height();
		if (myEventHeight < 145) {
			myEventHeight = 155 ;
		}	
		if($(this).parent('li').hasClass('showContent')) {
			$('#events > li').animate({height : 145});
			$(this).parent('li').removeClass('showContent');
			$(this).children('span').text('+');	
			return false;
		}
		else {	
			$('#events > li').height(145).removeClass('showContent');
			$('#events > li a.btn span').text('+')
			$(this).parent('li').addClass('showContent').animate({height : myEventHeight});
			$(this).children('span').text('-');	
			return false;
		}
	});
}

function switchSeason() {
	$('#tabResidence li.season a').click(function () {
		var seasonToShow = $(this).attr('href').split('#');

		if(seasonToShow[1] == 'summerInfo') {
			$('#content').addClass('skinSummer');
			$('#mainContent .mainDesc , #diaporama ul.highlights , #mainContent .thingsToDo , #mainContent .userFeedback').hide();
			$('#mainDesc_summer , #highlights_summer , #thingsToDo_summer , #userFeedback_summer').show();

		} else {
			$('#content').removeClass('skinSummer');
			$('#mainContent .mainDesc , #diaporama ul.highlights , #mainContent .thingsToDo , #mainContent .userFeedback').show();
			$('#mainDesc_summer , #highlights_summer , #thingsToDo_summer , #userFeedback_summer').hide();
		}
		$(this).parent('li').addClass('active').siblings('li').removeClass('active');
		return false;
	});
}

function initCarouselReco() {
	 $("#carouselRecoResidence").jCarouselLite({
		btnNext: ".recoResidence .btn_next",
        btnPrev: ".recoResidence .btn_prev",
		visible: 2	
    });	
} 

function flipTabRecap() {
	$('#tabRecap > li > a').click(function() {
		var recapToShow = $(this).attr('href').split('#');
		
		if(recapToShow[1] == 'flip_options') {
			$('#flip_options').show();
			$('#flip_hebergement').hide();
		} else {		
			$('#flip_hebergement').show();
			$('#flip_options').hide();
		}
		$('#tabRecap > li').removeClass('current');
		$(this).parent('li').addClass('current');		
		return false;
	});
}

function flipTabAccount() {
	var defaultBlocToShow = $('#tabAccount > li.current > a').attr('href').split('#');
	$('#'+defaultBlocToShow[1]).show();

	$('#tabAccount > li:not(.print) > a').click(function() {
		var recapToShow = $(this).attr('href').split('#');
		
		if(recapToShow[1] == 'flip_dossiers') {
			$('#flip_dossiers').show();
			$('#flip_infos').hide();
		} else {		
			$('#flip_infos').show();
			$('#flip_dossiers').hide();
		}
		$('#tabAccount > li').removeClass('current');
		$(this).parent('li').addClass('current');		
		return false;
	});
}

function switcherParticipant (numParticipant) {
	$myTabs = $('#nbParticipant > li');	
	$myParticipants = $('#mainContent_panier div.participantForm');
	
	//inits
	$('#nbParticipant > li:lt('+numParticipant+')').show();	
	var tabToOpen = $('#nbParticipant > li.current').text();
	$('#participant_'+tabToOpen).show();	
	//$('#selectNumParticipant > option').eq(numParticipant - 1).attr('selected','selected');
	
	
	//click sur l'onglet
	$('#nbParticipant > li:not(#moreParticipant)').click(function() {
		var tabToShow = $(this).text();
		$myParticipants.hide();
		$myTabs.removeClass('current');
		$('#participant_'+tabToShow).show();
		$(this).addClass('current');
	});
	
	// bouton suivant
	$('#mainContent_panier .participantForm span.nextParticipant').click(function() {
		var currentTab = $('#nbParticipant > li.current').text();
		var visibleTab = $('#nbParticipant > li:visible').length;		
		var nextTab = parseInt(currentTab) + 1;		
		if (nextTab <= visibleTab) {			
			$('#nbParticipant > li.current').next('li:not(#moreParticipant)').addClass('current').prev('li').removeClass('current');
			$myParticipants.hide();
			$('#participant_'+nextTab).show();		
		} 
	});
	
	//bouton precedent
	$('#mainContent_panier .participantForm span.prevParticipant').click(function() {
		var currentTab = $('#nbParticipant > li.current').text();		
		$('#nbParticipant > li.current').prev('li').addClass('current').next('li').removeClass('current');
		var prevTab = parseInt(currentTab) -1;		
		if (prevTab > 0) {		
			$myParticipants.hide();
			$('#participant_'+prevTab).show();		
		} 
	});
	
	//liste deroulante
	$('#selectNumParticipant').change(function() {
		var selectTabToShow = $(this).children('option:selected').val(); 
		$myTabs.hide().removeClass('current').eq(0).addClass('current');
		$('#nbParticipant > li:lt('+selectTabToShow+')').show();
		$myParticipants.find('span.nextParticipant').show();
		$('#participant_'+selectTabToShow).find('span.nextParticipant').hide();
		$myParticipants.hide();		
		$('#participant_1').show();
	});		
	
	$('#NumParticipant select').resetSS();
}

function pleaseWaitLayer(longL) {
	var viewportHeight = $(document).height();		
	//$('body').append('<div id="pleaseWaitLayer"> </div>');
	$('#pleaseWaitLayer').css('height',viewportHeight).show();
	$('#pleaseWaitLoader').show();
	
	if(longL == true)
	{
		$('#imgLongLoader').show();
		$('#loaderText').show();
	}
	else
		$('#imgLoader').show();	
	
		
	//$('body').append('<img id="pleaseWaitLoader" src="images/common/pleaseWait.gif" alt="Chargement en cours" />');
}

function killPleaseWaitLayer(longL) {

	var idLoader = 'pleaseWaitLoader';

	$('#pleaseWaitLayer , #pleaseWaitLoader').hide();	
	
	if(longL == true)
	{
		$('#loaderText').hide();	
		$('#imgLongLoader').hide();
	}
	else
		$('#imgLoader').hide();
	
}

function openPopinFromFlash(imgUrlFromFlash, group, rang) {
	var nbPhotos = ("#flashCarousel_container a[rel='"+group+"']").length
	
	for (i=0; i < nbPhotos; i++) {
		if (i != rang) {
			$("#flashCarousel_container a[rel='"+group+"']").eq(i).colorbox({photo: true});
		}
	}
	myHref = $("#flashCarousel_container a[rel='"+group+"']").eq(rang).attr("href");
	$.fn.colorbox({ opacity:"0.7", scrolling:false , photo: true , scalePhotos:false , rel:group , slideshow:true, slideshowAuto:false, href:myHref });	
}

/* French initialisation for the jQuery UI date picker plugin. */
jQuery(function($){
	$.datepicker.regional['fr'] = {		
		closeText: 'Fermer',
		prevText: '<<',
		nextText: '>>',
		currentText: 'Courant',
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
		'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
		'Jul','Aoû','Sep','Oct','Nov','Déc'],
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dateFormat: 'dd/mm/yy', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
});





