
function resize_col2(){
	/* cette fonction permet de redimensionner la deuxieme colonne en fonction de la hauteur de la troisieme */
	if(!$("col3")){return null;}
	var height_col3 = $('col3').getHeight();
	var height_col2 = $('col2').getHeight();
	
	if(height_col3 > height_col2){
		height_col3 -= 20;
		$('col2').setStyle({ height: height_col3+"px"});
	}
}

function resize_col3(){
	/* cette fonction permet de redimensionner la deuxieme colonne et la troisime en fonction de la premiere */
	var height_col3 = $('col3').getHeight();
	var height_col2 = $('col2').getHeight();
	var height_col1 = $('col1').getHeight();
	
	if( (height_col2 < height_col1) && (height_col3 < height_col1)){

		J("#col2 .content_txt").css("height",height_col1-72+"px");
		J("#col3 .content_txt").css("height",height_col1-72+"px");
	}
	
}



function hack_minHeight(){
	var list_elem_minheight =  J("#container .minheight");
	J("#container .minheight").each(function (i) {	
		var minheight = J(this).attr("rel");
		if(minheight > J(this).height()){
			J(this).css("height", minheight+"px");
		}
	});
}

function init_item_liens(){
	J("#container .item_liens").each(function (i) {	
		J(this).hover(
			 function () { J(this).addClass("hover") },
			 function () { J(this).removeClass("hover")}
		);
	});
}

/**********************  CALENDAR   ********************/
function initAllCalendar(lang){
	J(function(){
		// config all
		J.datepicker.setDefaults(J.datepicker.regional[lang]);
		J("#datepicker_start").datepicker({
			   onSelect: function(dateText, inst) {
			   		J("#datepicker_end").attr("value", ""); 
			   		  var year = inst.selectedYear;
					  var month = inst.selectedMonth;
					  var day = inst.selectedDay; 
					  //day = parseInt(day)+parseInt(1); // jour suivant pour la date de depart
					
			   		J("#datepicker_end").datepicker('option' ,'minDate' ,new Date(year+0,month+0,day));		   		
			   		month = month+1;
			   		getNextReservation(year+"-"+month+"-"+day);
			   }
			});
		J("#datepicker_end").datepicker();
		
	});	
	//ne pas enlever
	J.datepicker.setDefaults(J.datepicker.regional[lang]);
	J.datepicker.setDefaults({ minDate: '-0m +-0w' });
}

function getNextReservation(date_debut){
	//cette fonction permet de rechercherla date de la prochaine reservation et de configurer le datepicker de depart en fonction
	J.ajax({
		type: "POST",
		url: "../disponibilites/ajax_reservation.php?start="+date_debut,
		async: false,
		data: "",
		success: function(msg){
			var date_array = msg.split("-");
			var year = (date_array[0]);
			var month = (date_array[1]) ;
			var day = (date_array[2]);
			month--;
			J(function(){
				J("#datepicker_end").datepicker();
				J("#datepicker_end").datepicker('option' ,'maxDate' , new Date(year,month,day));
				
			});		
		},
		error: function(){
			alert("Error data Ajax");
		}
	});
}



function gotoDispo(root_http , date){
	//window.location.href=root_http+"/disponibilites/?start="+date;
	window.location.href=root_http+"/disponibilites";
}

/*******************************************************************/
window.onload = function() {	
	resize_col2();
	hack_minHeight();
	if($('slideshow_picture_1')){ slideShow();} // fonction jquery
	J("a.lightboxed").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'zoomSpeedChange': 300,
		'overlayShow': true,
		'centerOnScroll' :true
	});
	init_item_liens();
	
	J("#formcontact").validate();
	J("#formdisponibilite").validate();
}


window.onresize = function() {
}



