/*
	@program	Site Wide JavaScript Code
	@author		Daniel Petkovski
	@version	v1.0 for Windsong Resort TCI
*/


/*========================================
 Initiate Site-Wide jQuery Functions
========================================*/

$(document).ready(function () {
	
	// Fix Target Links for XHTML 1.0 Compliance //	
	$('a[rel=external]').attr('target', '_blank');
	
	
	// Activate E-Postcard Pop-Up //
	$('.ePostcard').click(function (e) {
		e.preventDefault();
		var postcardLink = $(this).attr('href');
		window.open(postcardLink, 'ePostcard', 'width=650, height=600');
	});
	
	// Internet Explorer Hacks //
	if ($.browser.msie) {
		$('#jsddm li ul li a').css({
			'filter' : 'alpha(opacity=90)'														 
		});
	}
});


/*========================================
 Activate DatePicker Plug-in
========================================*/

$(function() {
	var bookingDate = {
		checkin: null,
		checkout: null,
		nights: null,
		init: function () {
			
			/*==============================
			 Set Default Variables
			==============================*/
			
			// Date Format Settings for IBE //
			Date.firstDayOfWeek = 0;
			Date.format = 'mm/dd/yyyy';
			
			// Set Default Check-In and Check-Out Date //
			bookingDate.checkin = new Date().addDays(1).asString();
			bookingDate.update();
						
			
			/*==============================
			  Initiate DatePicker Plug-In
			==============================*/
			
			// Start DatePicker //
			$('#checkin')
				.datePicker(
					{
						clickInput : true,
						startDate : bookingDate.checkin
					}
				).val(
					bookingDate.checkin
				).trigger(
					'change'
				).bind(	
					'dpClosed',
					function(e, selected) 
					{ 
						bookingDate.checkin = new Date(selected[0]).asString();
						bookingDate.update();
					}
				);
			
			// Bind Update Function to Nights Drop-Down //
			$('#nights').bind('change', function() { bookingDate.update(); });
			
		},
		update: function () 
		{
			// Get Current Nights Selected //
			var n = $('#nights').val();
			bookingDate.nights = parseInt(n);
			
			// Set New Checkout Date //
			bookingDate.checkout = new Date(bookingDate.checkin).addDays(bookingDate.nights).asString();
			$('#checkout').val(bookingDate.checkout);
		}
	};
	bookingDate.init();
});