$(function(){
	
	$('#navigation > li').bind('mouseover', jsddm_open);
	$('#navigation > li').bind('mouseout',  jsddm_timer);

	$('a.gallery').lightBox();
	
	$('#selOtherSuite').change(function(){
		window.location.href = 'suite.php?s='+$(this).val();		
	});
	$('#selOtherCottage').change(function(){
		window.location.href = 'cottage.php?c='+$(this).val();		
	});
	
	$('div.date_select_container select').each(function(){
		$(this).change(function(){
			var objCont = $(this).parent();
			
			var date = $('select.date_select_year',objCont).val()+'-'+$('select.date_select_month',objCont).val()+'-'+$('select.date_select_day',objCont).val();
			$('input.date_select_hidden',objCont).val(date);
		});
	});
	
	$('#selPaymentMethod').change(function(){
		
		if($(this).val()=='card'){
			$('#card_wrap').show();
			$('#bacs_wrap').hide();
		}
		if($(this).val()=='bacs'){
			$('#card_wrap').hide();
			$('#bacs_wrap').show();
		}
		
	});
	
	$('div.payment_date_wrap select').change(function(){
		
		objDiv = $(this).parent();
		
		$('input',objDiv).val($('select:eq(0)',objDiv).val()+'-'+$('select:eq(1)',objDiv).val());
		
	});
	
	$('input.chkDoB').click(function(){
		if($(this).attr('checked') == true){
			$('select',$(this).parent().parent()).attr('disabled','');
		}else{
			$('select',$(this).parent().parent()).attr('disabled','disabled').val('00');
			$('input.date_select_hidden',$(this).parent().parent()).val('0000-00-00');
		}
	});
	
	$('#calendar2select').livequery('change',function(){
		$('#calendar_wrap').load('p/calendar2.php'+$(this).val());
	});
	
	$('#calendar_wrap3_select').livequery('change',function(){
		var divWrap = $(this).attr('id').replace('_select','');
		$('#'+divWrap).load('p/calendar3.php'+$(this).val());
	});
	
});

function UpdateCalendar(year, month, acc, months){
	$('#calendar_wrap_suite_'+acc).load('/p/calendar.php?y='+year+'&m='+month+'&a='+acc+'&n='+months);
}

function UpdateCalendar2(year, month, acc){
	$('#calendar_wrap').load('/p/calendar2.php?y='+year+'&m='+month+'&a='+acc);
}

function UpdateCalendar3(year, month){
	$('#calendar_wrap3').load('/p/calendar3.php?y='+year+'&m='+month);
}


var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open(){  
	jsddm_canceltimer();
   	jsddm_close();
   	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close(){  
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){  
	if(closetimer){  
		window.clearTimeout(closetimer);
      	closetimer = null;
	}
}
