$(function() {
	//Documentation located in special.docs.js
	var bookform;
	var hotelID;
	$('form').each(function() { if ($(this).attr('id')) {bookform = $(this);}   });
	$("select#hotel",bookform).change(function(){		
		hotelID = $(this).val();

		$('.submit', bookform).click(function() {	
			if (hotelID == 'fitzcastle'){					
			
				var arrivedate = $(this).parent().parent().children().children('input#arrival').val();
				var departdate = $(this).parent().parent().children().children('input#departure').val();
				var adults = $(this).parent().parent().children().children('select#adults').val();
				var children = $(this).parent().parent().children().children('select#child').val();

				var arriveMonth = parseInt(arrivedate.substring(0,2),10);
				var arriveDay = parseInt(arrivedate.substring(3,5),10);
				var arriveYear = parseInt(arrivedate.substring(6,10),10);
				var arrivalDate = new Date(arriveYear, arriveMonth-1, arriveDay); 
				
				var departMonth = parseInt(departdate.substring(0,2),10);
				var departDay = parseInt(departdate.substring(3,5),10);
				var departYear = parseInt(departdate.substring(6,10),10);
				var departureDate = new Date(departYear, departMonth-1, departDay); 
				
				var today=new Date();
				var tenMonthsLater = new Date(today.getFullYear(), today.getMonth()+10, today.getDate());
				if ( (arrivalDate == 'Invalid Date') || (departureDate == 'Invalid Date') ) {
					return false;
				} else if ( (arrivalDate > tenMonthsLater) || (departureDate > tenMonthsLater) ) {
					alert('Please select an arrival date within 10 months of today\'s date.');
				} else {
					window.open('http://www.fitzpatrickcastle.com/reservations?hotel_id=905&guide_id=1&service_model=2&inday='+arriveDay+'&inmonth='+arriveMonth+'&outday='+departDay+'&outmonth='+departMonth+'&adults='+adults+'&children='+children,'booking','resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
				}
				return false;
			}
		});
	});


	$('div#content h1').sifr(
		{ strSWF: '/flash/engravers-gothic-bt-bold.swf', strColor: '#18212a', strLinkColor: '#18212a', strHoverColor: '#18212a', strWmode: 'transparent', intPadding: [21, 5, 0, 0], strFlashVars: 'textalign=left&', strCase: 'upper' },
		{ expressInstall: true }
	);
	$('div#homepage-banner-specials h2').sifr(
		{ strSWF: '/flash/engravers-gothic-bt-bold.swf', strColor: '#ba8060', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strCase: 'upper' },
		{ expressInstall: true }
	);
	
	$('div#content h2').sifr(
		{ strSWF: '/flash/engravers-gothic-bt-bold.swf', strColor: '#242f3d', strLinkColor: '#242f3d', strHoverColor: '#242f3d', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=left&', strCase: 'upper' },
		{ expressInstall: true }
	);
	
	$('div.property-specials h3').sifr(
		{ strSWF: '/flash/engravers-gothic-bt-bold.swf', strColor: '#242f3d', strLinkColor: '#242f3d', strHoverColor: '#242f3d', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=center&', strCase: 'upper' },
		{ expressInstall: true }
	);
	
	$("body.homepage div#masthead").flash(
		{src:"/flash/home.swf",
		 width:720,
		 height:276,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"}
	);
	
	$("div#gallery-grand-central").flash(
		{src:"/flash/grandcentral-gallery.swf",
		 width:445,
		 height:326,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"}
	);
	
	$("div#gallery-manhattan").flash(
		{src:"/flash/manhattan-gallery.swf",
		 width:445,
		 height:326,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"}
	);
	
	
	$('div#code-box').hide();
	$('a#add-promo').toggle(function() {
		$('div#code-box').show();
		$(this).addClass('check-long');
		return false; 
		}, function() { 
			$('div#code-box').hide();
			$(this).removeClass('check-long'); 
			return false; 
	});
	
	//MSN Map
	var openFn=function(hash){
		hash.w.show();
		var leftPos = ($(window).width()-$('#map-container').width())/2;
		var topPos = Math.max($(window).scrollTop(),parseInt($('#map-container').css('top')));
		$('#map-container').css({left:leftPos,top:topPos});
		$('#map').msnMap({listView:true, hotelOnly: true});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
		$('.places').remove();
		$('#map-container').css({top:0});
	};
	$('#map-container').jqm({trigger:'#btn-msnmap', onShow: openFn, onHide: hideFn});
	
	// Blog Form
	$('div.form-help').hide();
	$('a.help-link').toggle( function() {
		$(this).parents('div.field').children('div.form-help').show();
		return false;
	},function(){ 
	  $(this).parents('div.field').children('div.form-help').hide();
	  return false;
	});
	
	// Striped Table
	$('table.striped-table').children('tbody').children('tr:odd').addClass('stripe');

	// Thickbox Window Close
	$('a#close-window').click(function(){								   
		tb_remove();
	});
	
	//PNG fix
	$(document).pngFix();
	
});