/*-----------------------------------------------------------
	Project:	Courchevel 2010
	Author:		C2iS - DJO
	Last:		06/09/2010
-----------------------------------------------------------*/
/**:::::::: FUNCTIONS ::::::::::**/
/** labelInField function **/
$.fn.labelValue = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};


function heightToDiv() {
	var bodyHeight = $('html').outerHeight();
	var header = $("#header").outerHeight();
	var footer = $("#footer_global_home").outerHeight() + $("#optim").outerHeight();
	var result = bodyHeight - header - footer;
	$("#homeFlash, #wrap.events").height(result-10);
	
	// Sociopro
	var searchHeight = $("#search").height();
	$("#searchSociopro").height(searchHeight);
	
	// Load du flash pour le hall of fame
	try {
	  setFlash();
  }catch(err) {}
};

function langSais() {
	if ($(this).next("ul").is(":visible")) {
		$(this).next("ul").hide();
	}else {
		$("#menuTop #lang ul").hide();
		$(this).next("ul").show();
	}
};

function dynBloc() {
	var bloc = $(this).next(".dynBloc");
	if (bloc.is(":visible")) {
		bloc.slideUp();
		$("#container.type #contentHebergement h2").removeClass("deployed");
	}else{
		$("#container.type #contentHebergement .dynBloc").slideUp();
		bloc.slideDown();
		$(this).siblings("h2").removeClass("deployed");
		$(this).addClass("deployed");
	}
};



/**:::::::: DOM READY ::::::::::**/

$(document).ready(function() {
	//only functions for IE 6
	if ($.browser.msie && $.browser.version >= 6 ) {
		try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {} //caching CSS images
		
		//menuTop sfhover IE6
		$('#menuTop ul li').hover(function(){ $(this).addClass('shover'); },function(){ $(this).removeClass('shover'); });
	
	};
	
	// Resize
	$(window).resize(function(){  
		heightToDiv();
	});
	
	// Calcul hauteur contenu flash
	heightToDiv();
	
	// Datepicker
	$('.date-picker').datePicker();
	
	$('input.datePicker').datePicker({clickInput:true});
	
	
	// Skin select sauf pour IE	
	if (!($.browser.msie && $.browser.version == 6 )) {
		$('#searchEngine select').sSelect();
	};
	
	//labelInField
	$('input[type="text"]').labelValue();
	
	// MenuTop hover
	$('#menuTop ul li, #menuTop ul li.last, #menuTop .sMenu li').hover(function(){
		$(this).addClass("active");
		$(this).prev("li").addClass("altBorder");
		$(this).children(".sMenu").show();
	},function(){
		$(this).removeClass("active");
		if ($(this).hasClass("current")) {
			// ne pas enlever la class altBorder
		}else{
			$(this).prev("li").removeClass("altBorder");
		};
		$(this).children(".sMenu").hide();
	});
	
	// MenuTop current
	if ($("#menuTop ul li.current").length) {
		$("#menuTop ul li.current").prev("li").addClass("altBorder");
	};
	
	// Link li menu
	$("#menuTop .sMenu li").click(function() {
		window.open = $(this).find("a").attr("href");
	});
	
	// Link li langue
	$("#menuTop #lang li").click(function() {
		window.location = $(this).find("a").attr("href");
		return false;
	});
	
	// Module langues + Saisons
	$("#menuTop #lang span").click(langSais);
	
	// Fermer les ul au click en dehors
	$("#menuTop #lang").bind( "clickoutside", function(event){
		$(this).children("ul").hide();
	});
	
	// Footer home
	if ($("#homeFlash").length) {
		
		$("#footer_global_home").addClass("home");
	}else{
	
		$("#footer_global_home").removeClass("home");
	
	};
	
	// Blocs hébergement
	$("#container.type #contentHebergement h2").click(dynBloc);
	
	$("#container.type #contentHebergement .dynBloc.first").prev("h2").addClass("deployed");
	
	
	// Search engine
	if ($("#searchEngine").length) {
		if (($("#searchEngine #searchSociopro").length) && ($("#searchEngine #search").length)) {
			
		}else{
			$("#search").addClass("noBorder");
		};	
	};
	
	
	/* SKIN RADIO & CHECKBOX */
	/* Test checked */
	// Radio
	$('input[type="radio"].RadioClass').each(function(){
		if($(this).is(":checked")){
			$(this).parent("label").addClass("RadioSelected");
		}
	});
	// Checkbox
	$('input[type="checkbox"].CheckBoxClass').each(function(){
		if($(this).is(":checked")){
			$(this).parent("label").addClass("LabelSelected");
		}
	});
	
	// Change radio to checked
	$(".RadioClass").change(function(){
		if($(this).is(":checked")){
			$(".RadioSelected:not(:checked)").removeClass("RadioSelected");
			$(this).parent("label").addClass("RadioSelected");
		}
		return false;
	});
	
	// Change checkbox to checked
	$(".CheckBoxClass").change(function(){
		if($(this).is(":checked")){
			$(this).parent("label").addClass("LabelSelected");
		}else{
			$(this).parent("label").removeClass("LabelSelected");
		}
		return false;
	});
	
	// Min height si form dans la page
	if ($("#container.type #colContent").find("form")) {
		$("#container.type #colContent #content").attr("style","min-height:250px");
	};
	

	
});
