
$(document).ready(function(){
/*$(".select h2").click(function(){
$("#search form").submit();
});*/
/*$("#overview li").click(function(){
  if($(this).find("a").attr("href")){
	 window.location=$(this).find("a").attr("href"); return false;
  }
});*/
$("#tabs").tabs();
$('#tabs').bind('tabsshow', function(event, ui) {
    if (ui.panel.id == "tab_maps") {
        map.checkResize();
    }
});
$('#tab_photo a').lightBox();
$("a[href$=pdf]").addClass("pdf").attr({ target: "_blank" });
$("a[href$=zip]").addClass("zip").attr({ target: "_blank" });
$("a[href$=psd]").addClass("psd").attr({ target: "_blank" });

$("#main a[href^='http://']").click(function(){
window.open(this.href,'external');
return false;
}); 

});

$(function()
		{
			
			var currentTime = new Date()

			// initialise the "Select date" link
			$('#date-pick')
				.datePicker(
					// associate the link with a date picker
					{
						createButton:false,
						createButton:false,
						startDate: currentTime.getDay()+'/'+(currentTime.getMonth()+1)+'/'+currentTime.getFullYear(),
						endDate: '31/'+(currentTime.getMonth()+1)+'/'+(currentTime.getFullYear()+1)
					}
				).bind(
					// when the link is clicked display the date picker
					'click',
					function()
					{
						updateSelects($(this).dpGetSelected()[0]);
						$(this).dpDisplay();
						return false;
					}
				).bind(
					// when a date is selected update the SELECTs
					'dateSelected',
					function(e, selectedDate, $td, state)
					{
						updateSelects(selectedDate);
					}
				).bind(
					'dpClosed',
					function(e, selected)
					{
						updateSelects(selected[0]);
					}
				);
				
			var updateSelects = function (selectedDate)
			{
				var selectedDate = new Date(selectedDate);
				var newMonth = (selectedDate.getMonth()+1);
				if(newMonth <= 9){ newMonth = '0'+newMonth; }
				
				var newDay = selectedDate.getDate();
				if(newDay <= 9){ newDay = '0'+newDay; }
				
				$('#arrive_day_day option[value=' + newDay + ']').attr('selected', 'selected');
				$('#arrive_day_month option[value=' + newMonth + ']').attr('selected', 'selected');
				$('#arrive_day_year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
			}
			// listen for when the selects are changed and update the picker
			$('#arrive_day_day, #arrive_day_month, #arrive_day_year')
				.bind(
					'change',
					function()
					{
						var d = new Date(
									$('#arrive_day_year').val(),
									$('#arrive_day_month').val()-1,
									$('#arrive_day_day').val()
								);
						$('#date-pick').dpSetSelected(d.asString());
					}
				);
			
			// default the position of the selects to today
			//var today = new Date();
			//updateSelects(today.getTime());
			
			// and update the datePicker to reflect it...
			$('#arrive_day_day').trigger('change');
});

$(function()
		{
			var currentTime = new Date()
			// initialise the "Select date" link
			$('#date-pick2')
				.datePicker(
					// associate the link with a date picker
					{
						createButton:false,
						startDate: currentTime.getDay()+'/'+(currentTime.getMonth()+1)+'/'+currentTime.getFullYear(),
						endDate: '31/'+(currentTime.getMonth()+1)+'/'+(currentTime.getFullYear()+1)
					}
				).bind(
					// when the link is clicked display the date picker
					'click',
					function()
					{
						updateSelects($(this).dpGetSelected()[0]);
						$(this).dpDisplay();
						return false;
					}
				).bind(
					// when a date is selected update the SELECTs
					'dateSelected',
					function(e, selectedDate, $td, state)
					{
						updateSelects(selectedDate);
					}
				).bind(
					'dpClosed',
					function(e, selected)
					{
						updateSelects(selected[0]);
					}
				);
				
			var updateSelects = function (selectedDate)
			{
				var selectedDate = new Date(selectedDate);
				var newMonth = (selectedDate.getMonth()+1);
				if(newMonth <= 9){ newMonth = '0'+newMonth; }
				
				var newDay = selectedDate.getDate();
				if(newDay <= 9){ newDay = '0'+newDay; }
				
				$('#leave_day_day option[value=' + newDay + ']').attr('selected', 'selected');
				$('#leave_day_month option[value=' + newMonth + ']').attr('selected', 'selected');
				$('#leave_day_year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
			}
			// listen for when the selects are changed and update the picker
			$('#leave_day_day, #leave_day_month, #leave_day_year')
				.bind(
					'change',
					function()
					{
						var d = new Date(
									$('#leave_day_year').val(),
									$('#leave_day_month').val()-1,
									$('#leave_day_day').val()
								);
						$('#date-pick').dpSetSelected(d.asString());
					}
				);
			
			// default the position of the selects to today
			//var today = new Date();
			//updateSelects(today.getTime());
			
			// and update the datePicker to reflect it...
			$('#leave_day_day').trigger('change');
});
