$(document).ready(function() {
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		$('#menubar_hl li').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});
	};
	
	// modification des selectbox
	// left
	//$('#nb_night').selectbox();
	//$('#nb_adults').selectbox({ containerClass: 'selectbox-wrapper nb_adults'});
	//$('#nb_kids').selectbox({ containerClass: 'selectbox-wrapper nb_kids'});
	//$('#th_activities').selectbox();
	//$('#regions').selectbox({ containerClass: 'selectbox-wrapper etablist'});
	$('#stations').selectbox({ containerClass: 'selectbox-wrapper etablist'});
	//$('#search_form_etab').selectbox({ containerClass: 'selectbox-wrapper etablist', maxChar: '27'});
	//$('#flexibility').selectbox();
	$('#formule').selectbox({ containerClass: 'selectbox-wrapper formule'});
	$('#search_geo_pays').selectbox({ containerClass: 'selectbox-wrapper search_geo_pays'});
	
	// contact
	if($('.form').length) 
	{
		$('#select_pays').selectbox();
		$('#theme_demande').selectbox();
		$('#subject').selectbox();
	}
	// modification des boutons radio
	//$("#search_form").cssCheckbox();
	$(".bloc_resultat_annonce").cssCheckbox();
	$("#center fieldset.get_mag").cssCheckbox();
	
	// create datePicker
//	$('.date-pick').datePicker({ clickInput:true,renderCallback:function(){alert("ee");}});	
	$('.date-pick').datePicker({ clickInput:'true'});	
	
	// Prepare and hide element to preserve functionality w/out javascript enable
	// when page is loading : (because of Webkit)
	$('.more_crit_fieldset').hide();
	$('.switch_crit a:first').toggle(); 
	$('.choix_recherche_geo img:first').toggle(); 
	$('.choix_recherche_geo img:last').toggle(); 
	
	$('.switch_crit a').click(function(e){
		e.preventDefault(); // return false
		$('.switch_crit a').toggle(); 
		$('.more_crit_fieldset').toggle('fast');
	});
	
	// switch geo_search
	$('.choix_recherche_geo img').click(function(e){
		e.preventDefault(); // return false
		$('.choix_recherche_geo img').toggle(); 
		$('.link_recherche_geo').toggle();
	});

	// tooltip mouseover on .tooltip elements
	tooltip();
	
	// inputValue
	textInputDynamicValue('input[@type=text]','value');
	
	if($('.nos_offres').length)
	{
		$('.nos_offres').hover( function(){
			if($('a', this).length){ $(this).addClass('shover'); }
		}, function() {
			if($('a', this).length){ $(this).removeClass('shover'); }
		});
		$('.nos_offres').click(function(){
			if($('a', this).length)
			{
				$(this).find("a").click();
    			window.location=$(this).find("a").attr("href");
			}
			return false;
	});
	}
	if($('.thematique').length)
	{
		$('.thematique').hover( function(){
			if($('a', this).length){ $(this).addClass('shover'); }
		}, function() {
			if($('a', this).length){ $(this).removeClass('shover'); }
		});
		$('.thematique').click(function(){
			if($('a', this).length)
			{
				$(this).find("a").click();
    			window.location=$(this).find("a").attr("href");
			}
			return false;
	});
	}
	
	if($('#center dl.offerList').length)
	{
		$('#center dl.offerList').hover( function(){
			$(this).addClass('offerList_shover'); 
		}, function() {
			$(this).removeClass('offerList_shover'); 
		});
		/*$('#center dl.offerList dt , #center dl.offerList dd.mainDesc ').click(function(){
    	window.location=$(this).siblings().find("a.bookNow").attr("href");return false;
		});		*/
	}
	
	if($('#center dl.lastOffers_account').length)
	{
		$('#center dl.lastOffers_account').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});
		$('#center dl.lastOffers_account').click(function(){
    	window.location=$(this).find("a").attr("href");return false;
		});
	}
	
	if($('#center ul.accountMainPush').length)
	{		
		$('#center ul.accountMainPush li').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});
		$('#center ul.accountMainPush li').click(function(){
    	window.location=$(this).find("a").attr("href");return false;
		});
	}
	
		if($('#center ul.account_menu').length)
	{		
		$('#center ul.account_menu li').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});
		$('#center ul.account_menu li').click(function(){
    	window.location=$(this).find("a").attr("href");return false;
		});
	}
	tabNav_planList();//gestion de la nav par onglet page plan et acces
	initSB_selection(); //init skin select box page ma selection
});

/* FUNCTIONS */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = -25;		
		// these 2 variable determine popup's distance from the cursor
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/**/
function textInputDynamicValue (input_selector, text_to_use, def_class) {
	if (text_to_use == undefined) text_to_use = 'title';
	if (def_class == undefined) def_class = 'dvDefault';
	var dynamic_value = [];
	$(input_selector).each(function(j) {
		switch (text_to_use) {
			case 'title' :
				dynamic_value[j] = $(this).attr('title');
				break;
			case 'value' :
				dynamic_value[j] = $(this).attr('value');
				break;
			default :
				dynamic_value[j] = text_to_use;
		}
		$(this).attr('value', dynamic_value[j]).addClass(def_class)
		.focus(function() {
			if (this.value == dynamic_value[j]) {
				this.value = '';
				$(this).removeClass(def_class);
			}
		})
		.blur(function() {
			if (this.value == '') {
				this.value = dynamic_value[j];
				$(this).addClass(def_class);
			};
		});
	});
};

/* Navigation par onglets liste plan et acces */
function tabNav_planList() {		
	if($('.menu_listPlan').length) {	
		$(".gab_txt .layerTab_plan").hide();		
		$("ul.menu_listPlan li:first-child").addClass("active");
		var initFirstTab = $("ul.menu_listPlan li:first-child").children().attr("href").split("#");		
		$("#"+initFirstTab[1]).show();
		
		$(".menu_listPlan li a").click(function(){
			
			$(".menu_listPlan li ").removeClass("active");
			$(".gab_txt .layerTab_plan").hide();
			
			var linkTab = $(this).attr("href").split("#");
			$("#"+linkTab[1]).show();
			
			$(this).parent("li").addClass("active");
			
			return false;
		});	
	}
}

/*init skin selectbox page ma selection */
function initSB_selection() {
	if($('.form_resa').length) {
		$('#center_search_form_etab').selectbox({ containerClass: 'selectbox-wrapper center_search_form_etab', maxChar: '26'});
		$('#center_nb_night').selectbox();
		$('#center_nb_adults').selectbox({ containerClass: 'selectbox-wrapper center_nb_adults'});
		$('#center_nb_kids').selectbox({ containerClass: 'selectbox-wrapper center_nb_kids'});
		$('#center_nb_baby').selectbox({ containerClass: 'selectbox-wrapper center_nb_baby'});
	}
}




