// Get the hacked stylesheet
document.write('<style type="text/css">@import url("styles/hacks.css");</style>');

// Fixes IE6 CSS Rendering Bug
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
function fixWinIE() {
	if (document.body.scrollHeight < document.body.offsetHeight) { document.body.style.display = 'block'; }
}

// Spam Suppression for Emails
function stopSpam(name, domain, subject) {
	var symbol = '@';
	// Took out the Subject due to MS fault in Outlook Express (Source - http://support.microsoft.com/kb/q182985/ )
	// document.write('<a href="mailto:' + name + symbol + domain + '&subject=' + subject + '">' + name + symbol + domain + '</a>');
	document.write('<a href="mailto:' + name + symbol + domain + '">' + name + symbol + domain + '</a>');
}

// XHTML External Link Script
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
			anchor.onclick = function PopupPic() {
				window.open('image.html?'+this.href+'&'+this.title, 'imagePopUp', 'resizable=1,width=20,height=20');
				return false;
			}
		}
	}
}

// Rotate images randomly
// Unique Random Numbers Picker
// -Picks a number of unique random numbers from an array
// (c) 2002 Premshree Pillai
function randomMiniImages() {
	if (!document.getElementsByTagName) return;
	var gallery = document.getElementById('gallery');
	var images = gallery.getElementsByTagName('img');
	nums = images.length;
	pickNums(nums);
}

var numArr = new Array("01","02","03","04","05","06","07","08", "09", "10", "11"); // Add elements here
var pickArr = new Array(); // The array that will be formed
var count=0;
var doFlag=false;
var iterations=0;

function pickNums(nums) {
	var gallery = document.getElementById('gallery');
	var images = gallery.getElementsByTagName('img');
	iterations+=1;
	var currNum = Math.round((numArr.length-1)*Math.random());
	if(count!=0) {
		for(var i=0; i<pickArr.length; i++) {
			if(numArr[currNum]==pickArr[i]) {
				doFlag=true;
				break;
			}
		}
	}
	if(!doFlag) {
		pickArr[count]=numArr[currNum];
		images[count].src = "images/ksStamp" + numArr[currNum] + ".jpg";
		count+=1;
	}
	// Compare for max iterations you want
	if(iterations<(numArr.length*3)) {
		if((count<nums)) {
			pickNums(nums);
		}
	} else {
		location.reload();
	}
}

// Toggle Function
function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}

// Pop Up Window
function popUp(sPicURL, w, h) {
	window.open(sPicURL, 'popUp', 'resizable=0,width='+w+',height='+h+', scrollbars=no');
}

// Pop Up Image Window
function PopupPic(sPicURL, sPicTitle) {
	window.open('image.html?'+sPicURL, 'imagePopUp', 'resizable=1,width=20,height=20');
}

// Multiple Onload Functions to be called
function pageLoad() {
	externalLinks();
	randomMiniImages();
}
window.onload = pageLoad;

// Sets the book now button to the system date
function bb_set_date(){
	
	var today = new Date();
	var month = today.getMonth() + 1;
	var bb_dateFrom_day = document.getElementById("bb_dateFrom_day");
	var bb_dateFrom_month = document.getElementById("bb_dateFrom_month");
		try
  	{

	if(today.getDate()<10){
		bb_dateFrom_day.value = '0' + today.getDate();
	}else{
		bb_dateFrom_day.value = today.getDate();
	}

	if(month<10){
		month = '0' + month;
	}
	
	var value = today.getFullYear() + "-" + month;
	bb_dateFrom_month.value = value;
	}
	catch(err)
  	{
  	}
}


// Builds booking button url from values in the book now form. Submits form.
function bb_submit()
{
	var bb_dateFrom = document.getElementById('bb_dateFrom_month').value + "-" + document.getElementById('bb_dateFrom_day').value;
	
	document.getElementById('dateFrom').value = bb_dateFrom;
	try
  	{
  		pageTracker._linkByPost(document.getElementById('bb_check_availibility'));
  	}
	catch(err)
  	{
  	}
	document.getElementById('bb_check_availibility').submit();
}



window.onload = bb_set_date;

/*function bb_submit()
{
	var bb_dateFrom = document.getElementById('bb_dateFrom_month').value + "-" + document.getElementById('bb_dateFrom_day').value;
	
	document.getElementById('dateFrom').value = bb_dateFrom;
	try
  	{
  		pageTracker._linkByPost(document.getElementById('bb_check_availability'));
  	}
	catch(err)
  	{
  	}
	document.getElementById('bb_check_availability').submit();
}*/

// Initiatiates the promotional ad scroller
$(document).ready(function() {
	if ($('#promo-ad').length > 0) {
		$('#promo-ad').css('display', 'block');
		$('#promo-ad').cycle({ 
	    	speed:       300, 
	    	timeout:     3000,  
		});
		$('#promo-ad').hover (
			function() { 
				$('#promo-ad').cycle('pause');
			}, 
			function() {
				$('#promo-ad').cycle('resume');
			}
		);	
	}
});


$(document).ready(function() {
	if ($('#slideshow').length > 0) {
		$('#slideshow').css('display', 'block');
		$('#slideshow').cycle({ 
	    	speed:       300, 
	    	timeout:     3000,
		});
		$('#slideshow').hover (
			function() { 
				$('#slideshow').cycle('pause');
			}, 
			function() {
				$('#slideshow').cycle('resume');
			}
		);
	}
});

$(document).ready(function() {

$("#bb_submit").click(function() {
							   					   
var start_date = $("#bb_dateFrom_month").attr("value") + "-" +  $("#bb_dateFrom_day").attr("value");

$("#bb_dateFrom_month").attr("disabled", "disabled");
$("#bb_dateFrom_day").attr("disabled", "disabled");

$("#start_date").attr("value", start_date);

document.getElementById('bb_check_availability').submit();
							   });
});
