// JavaScript Document
$(document).ready(function() {
	//lang
	$('#lang_sel').change(function() {
		var val = $(this).val();
		var current = document.URL;
		var len = current.indexOf("#") == 0 ? current.length : current.indexOf("#") ;
		var redirect = current.substr(0,len);
		//window.location = current+val;
	//	console.log(val,current,redirect);
	});	
	
	
	setTimeout(resizeMe,3500);
	function resizeMe(){
		var center 	= $('#center').height()+60;
		var left 	= $('#left').height()+60;
		var right 	= $('#right').height()+60;
		var max = Math.max(left,right,center)	
			$('#side_hotel_list').css('height',280+(max-left));
		//console.log(left,right,center);
	}

	
	setTimeout(set,3000);
	function set(){
		var h1 = $('.same_height1').height();
		var h2 = $('.same_height2').height();
		var h3 = $('.same_height3').height();		
		var arr = new Array(h1,h2,h3);
		var max =	getMax(arr);
		$('.same_height1,.same_height2,.same_height3').height(max);
		//console.log(max);
	}
	
	$('#rooms').change(function(){
		var rooms = $(this).val();
		if(rooms != '5+'){
		var max = rooms * 4;
		var i;
		var select = '';
		for(i = rooms; i<= max ; i++){
			select += '<option value="'+i+'">'+i+'</option>';
		}
		//alert(select);
		$('#adults')
		    .find('option')
		    .remove()
		    .end()
		    .html(select)
		;
		}
	});


	$( ".input_med" ).datepicker({ minDate: +0,numberOfMonths: 2,
		onSelect: function(dateText, inst) {
				var arr_date = new Date($('#arrival').val());
				var nextDay = arr_date.getDate()+1
				var curr_month = arr_date.getMonth() + 1; 
				var curr_year = arr_date.getFullYear();
				var dep_date = new Date(curr_month + "/" + nextDay + "/" + curr_year);
				$( "#departure" ).datepicker( "option", "minDate",dep_date);
		},	
		
		beforeShow: function()

	      {

	           setTimeout(function()

	           {

	               $(".ui-datepicker").css("z-index", 99);

	           }, 10); 

	      }
	});
	$('.input_cal').click(function(){
		$($(this).prev()).datepicker( "show" );
	});
	
	$('#nav li:last,.featured:last').not('li.current_page_item').css('background','none');
	
	$(".input,.textarea,.input_med,.input_small").focus(function () {
         $(this).css('background-color','#fff');
    });

	$(".input,.textarea,.input_med,.input_small").blur(function () {
         $(this).css('background-color','#ECECEC');
    });
	
	// newsletter
	$('#btn_newsletter').click(function(){
		$.post(site+'/sub.php',{name:$('#news_name').val(),email:$('#news_email').val()}, function(data) {
				$('#load_msg').html('<p>'+data+'</p>');
		});	
	});

});

function daysBetween(first, second) {
	var first = new Date($('#arrival').val());
	var second = new Date($().val());
    // Copy date parts of the timestamps, discarding the time parts.
    var one = new Date(first.getFullYear(), first.getMonth(), first.getDate());
    var two = new Date(second.getFullYear(), second.getMonth(), second.getDate());

    // Do the math.
    var millisecondsPerDay = 1000 * 60 * 60 * 24;
    var millisBetween = two.getTime() - one.getTime();
    var days = millisBetween / millisecondsPerDay;

    // Round down.
    return Math.floor(days);
}

function getMax( array ){
    return Math.max.apply( Math, array );
};
	


