var i, j;
var indImg = new Array();
var im1 = new Array();
var im2 = new Array();
var im3 = new Array();
var im4 = new Array();
var screenWidth;
var stopScroll = 0;
var currentPhoto = "photo1";
var closeMenu1 = 0;
var closeMenu2 = 0;
var closeMenu3 = 0;
var closeMenu4 = 0;

var indexImageURLs = new Array();
indexImageURLs[0] = "images/backgroundPage.jpg";
indexImageURLs[1] = "images/backgroundGradient.jpg";
indexImageURLs[2] = "images/bedroom.jpg";
indexImageURLs[3] = "images/button1.png";
indexImageURLs[4] = "images/button2.png";
indexImageURLs[5] = "images/button3.png";
indexImageURLs[6] = "images/button4.png";
indexImageURLs[7] = "images/buttonsRight.png";
indexImageURLs[8] = "images/deck.jpg";
indexImageURLs[9] = "images/flower.jpg";
indexImageURLs[10] = "images/kitchen.jpg";
indexImageURLs[11] = "images/lodge.jpg";
indexImageURLs[12] = "images/title1.png";
indexImageURLs[13] = "images/title2.png";
indexImageURLs[14] = "images/title3.png";
indexImageURLs[15] = "images/title4.png";
indexImageURLs[16] = "images/title5.png";
indexImageURLs[17] = "images/titleRightBanner.jpg";
indexImageURLs[18] = "images/titleRightBannerPattern.jpg";
indexImageURLs[19] = "images/titleText.png";
indexImageURLs[20] = "images/veil.png";
indexImageURLs[21] = "images/partyPonies.jpg";


var page1ImageURLs = new Array();
page1ImageURLs[0] = "images/introduction.jpg";
page1ImageURLs[1] = "images/introductionWatermark.jpg";

var page2ImageURLs = new Array();
page2ImageURLs[0] = "images/scroll1.jpg";
page2ImageURLs[1] = "images/scroll2.jpg";
page2ImageURLs[2] = "images/scroll3.jpg";
page2ImageURLs[3] = "images/scroll4.jpg";
page2ImageURLs[4] = "images/scroll5.jpg";
page2ImageURLs[5] = "images/scroll6.jpg";
page2ImageURLs[6] = "images/scroll7.jpg";

var page3ImageURLs = new Array();
page3ImageURLs[0] = "images/viewFinder.jpg";
page3ImageURLs[1] = "images/mapImage1.jpg";
page3ImageURLs[2] = "images/mapImage2.jpg";
page3ImageURLs[3] = "images/mapImage3.jpg";
page3ImageURLs[4] = "images/mapImage4.jpg";
page3ImageURLs[5] = "images/mapImage5.jpg";
page3ImageURLs[6] = "images/map.gif";
page3ImageURLs[7] = "images/directionsWatermark.jpg";

var page4ImageURLs = new Array();
page4ImageURLs[0] = "images/clickHere.jpg";
page4ImageURLs[1] = "images/clickHere_Sel.jpg";
page4ImageURLs[2] = "images/reservationsWatermark.jpg";

var monthNames = new Array();
monthNames[0] = "January";
monthNames[1] = "February";
monthNames[2] = "March";
monthNames[3] = "April";
monthNames[4] = "May";
monthNames[5] = "June";
monthNames[6] = "July";
monthNames[7] = "August";
monthNames[8] = "September";
monthNames[9] = "October";
monthNames[10] = "November";
monthNames[11] = "December";

var dayNames = new Array();
dayNames[0] = "Sunday";
dayNames[1] = "Monday";
dayNames[2] = "Tuesday";
dayNames[3] = "Wednesday";
dayNames[4] = "Thursday";
dayNames[5] = "Friday";
dayNames[6] = "Saturday";

if (document.images) {

	j = 0;
	for (i = 0 ; i < indexImageURLs.length ; i++) {
		indImg[j] = new Image();
		indImg[j].src = indexImageURLs[i];
		j = j + 1;
		window.status = "Loading.... " + indexImageURLs[i];
	}

	j = 0;
	for (i = 0 ; i < page1ImageURLs.length ; i++) {
		im1[j] = new Image();
		im1[j].src = page1ImageURLs[i];
		j = j + 1;
		window.status = "Loading.... " + page1ImageURLs[i];
	}

	j = 0;
	for (i = 0 ; i < page3ImageURLs.length ; i++) {
		im3[j] = new Image();
		im3[j].src = page3ImageURLs[i];
		j = j + 1;
		window.status = "Loading.... " + page3ImageURLs[i];
	}

	j = 0;
	for (i = 0 ; i < page4ImageURLs.length ; i++) {
		im4[j] = new Image();
		im4[j].src = page4ImageURLs[i];
		j = j + 1;
		window.status = "Loading.... " + page4ImageURLs[i];
	}
}

var scrollYcoords = new Array();
scrollYcoords[0] = 0;
scrollYcoords[1] = 207;
scrollYcoords[2] = 414;
scrollYcoords[3] = 621;
scrollYcoords[4] = 828;
scrollYcoords[5] = 1035;
scrollYcoords[6] = 1242;

var scrollXcoords = new Array();
scrollXcoords[0] = 0;
scrollXcoords[1] = 0;
scrollXcoords[2] = 0;
scrollXcoords[3] = 0;
scrollXcoords[4] = 0;
scrollXcoords[5] = 0;
scrollXcoords[6] = 0;

window.onscroll=scrollContactDetails;

function scrollContactDetails() {

	var yOffset;
	var contactObj;

	yOffset = findScrollTop();
	contactObj = findDOM("contactDetails", 0);
	if ((findLivePageHeight() < 800) && (((findLivePageHeight() - 180) + yOffset) < 600)) {
		contactObj.style.top =  "600px";
	} else {
		contactObj.style.top =  ((findLivePageHeight() - 180) + yOffset) + "px";
	}
}

function initialisePage() {

	if (parent.location.href == self.location.href) {
		window.location.href = "index.html";
	}
}

function toggleConvertButton(imgName, num) {

	if (document.images && imgName) {
		imgName.src = im4[num].src;
	}
	return false;
}

function buildPage() {

	var yOffset;
	var contactObj;
	var timerCyclePhoto;
	var timerAnimateMenuDown;
	var pageObj;
	var dateTimeObj;
	var today = new Date();

	if (findLivePageWidth() > 967) {
		screenWidth = findLivePageWidth();
	} else {
		screenWidth = 967;
	}

	dateTimeObj = findDOM("dateTime", 0);
	dateTimeObj.innerHTML = "<div>" + dateString(today) + "</div>";

	pageObj = findDOM("page", 0);
	pageObj.style.top = 0;
	pageObj.style.left = (screenWidth/2) - 484;

	yOffset = findScrollTop();
	contactObj = findDOM("contactDetails", 0);
	if ((findLivePageHeight() < 880) && (((findLivePageHeight() - 180) + yOffset) < 600)) {
		contactObj.style.top =  "600px";
	} else {
		contactObj.style.top =  ((findLivePageHeight() - 180) + yOffset) + "px";
	}

	timerCyclePhoto = setTimeout("cyclePhoto(100)", 30000);

	pageObj.style.visibility = "visible";

	timerAnimateMenuDown = setTimeout("animateMenuDown(5)", 500);

	j = 0;
	for (i = 0 ; i < page2ImageURLs.length ; i++) {
		im2[j] = new Image();
		im2[j].src = page3ImageURLs[i];
		j = j + 1;
		window.status = "Loading.... " + page2ImageURLs[i];
	}

	window.status = ""
}

function animateMenuDown(increment) {

	var buttonsObj;
	var timerAnimateMenuDown;
	
	buttonsObj = findDOM("buttons", 0);
	buttonsObj.style.top = (parseInt(buttonsObj.style.top.substring(0, (buttonsObj.style.top.length - 2))) + increment) + "px";

	if (buttonsObj.style.top.substring(0, (buttonsObj.style.top.length - 2)) < 266) {
		timerAnimateMenuDown = setTimeout("animateMenuDown(5)", 35);
	} else if (buttonsObj.style.top.substring(0, (buttonsObj.style.top.length - 2)) > 266) {
		timerAnimateMenuDown = setTimeout("animateMenuDown(-1)", 40);
	} else {
		buttonsObj.style.zIndex = 7;
	}
}

function toggleMenuDown(menuName, activeHeight) {

	var pLoc;
	var scrollTimer = "";
	var menuObj = findDOM(menuName, 0);

	pxLoc = menuObj.style.top.indexOf('p');
	if (parseInt(menuObj.style.top.substring(0, pxLoc)) < activeHeight) {
		menuObj.style.top = (parseInt(menuObj.style.top.substring(0, pxLoc)) + 2) + "px";
		scrollTimer = setTimeout("toggleMenuDown('" + menuName + "', " + activeHeight + ")", 0);
	}
}

function toggleMenuUp(menuName, activeHeight, menuNo) {

	var pLoc;
	var closeMenu;
	var scrollTimer = "";
	var menuObj = findDOM(menuName, 0);

	switch (menuNo) {
	case 1:
		closeMenu = closeMenu1;
		break;

	case 2:
		closeMenu = closeMenu2;
		break;

	case 3:
		closeMenu = closeMenu3;
		break;

	case 4:
		closeMenu = closeMenu4;
		break;
	}

	pxLoc = menuObj.style.top.indexOf('p');
	if ((parseInt(menuObj.style.top.substring(0, pxLoc)) > activeHeight) && (closeMenu == 1)) {
		menuObj.style.top = (parseInt(menuObj.style.top.substring(0, pxLoc)) - 1) + "px";
		scrollTimer = setTimeout("toggleMenuUp('" + menuName + "', " + activeHeight + ", " + menuNo + ")", 1);
	}
}

function toggleMapImage (imgName, num) {

	if (document.images && imgName) {
		imgName.src = im3[num].src;
	}
	return false;
}

function reDrawScreen() {

	var contactObj;
	var pageObj;
	var yOffset;
	
	if (findLivePageWidth() > 967) {
		screenWidth = findLivePageWidth();
	} else {
		screenWidth = 967;
	}

	pageObj = findDOM("page", 0);
	pageObj.style.top = 0
	pageObj.style.left = (screenWidth/2) - 484;

	yOffset = findScrollTop();
	contactObj = findDOM("contactDetails", 0);
	if (findLivePageHeight() < 800) {
		contactObj.style.top =  "600px";
	} else {
		contactObj.style.top =  ((findLivePageHeight() - 180) + yOffset) + "px";
	}
	window.scrollTo(0, 0);

	window.status = "";
}

function resizePage(height) {

	var frameObj;
	var pageObj;
	var titleRightBannerPatternObj;

	frameObj = findDOMParent("content", 0);
	frameObj.style.height = (height - 290) + "px";
	pageObj = findDOMParent("page", 0);
	pageObj.style.height = height + "px";
	titleRightBannerPatternObj = findDOMParent("titleRightBannerPattern", 0);
	titleRightBannerPatternObj.style.height = (height - 596) + "px";
}

function dateString(theDate) {

	var theDay = dayNames[theDate.getDay()];
	var theMonth = monthNames[theDate.getMonth()];
	var theYear = theDate.getFullYear();

	return theDay + ", " + theDate.getDate() + " " + theMonth + ", " + theYear;
}

function changePhoto(photoPage, photoPageImage) {

	var currentPhotoName;
	var imgSrc;
	var photoDivObj = findDOM(photoPage, 0);
	var photoImgObj = findDOM(photoPageImage, 0);

	imgSrc = photoImgObj.src;
	currentPhotoName = imgSrc.substring(imgSrc.lastIndexOf("/") + 1, (imgSrc.length - 4));
	switch(currentPhotoName) {
		case "flower":
			photoDivObj.innerHTML = "<img src='images//kitchen.jpg' border='0'  id='" + photoPageImage + "'>";
			break;
		case "kitchen":
			photoDivObj.innerHTML = "<img src='images//deck.jpg' border='0'  id='" + photoPageImage + "'>";
			break;
		case "deck":
			photoDivObj.innerHTML = "<img src='images//bedroom.jpg' border='0'  id='" + photoPageImage + "'>";
			break;
		case "bedroom":
			photoDivObj.innerHTML = "<img src='images//lodge.jpg' border='0'  id='" + photoPageImage + "'>";
			break;
		case "lodge":
			photoDivObj.innerHTML = "<img src='images//flower.jpg' border='0'  id='" + photoPageImage + "'>";
			break;
	}
} 

function cyclePhoto(Opacity) {

	var timerCyclePhoto;
	var photo1Obj = findDOM("photo1", 0);
	var photo2Obj = findDOM("photo2", 0);

	if (currentPhoto == "photo2") {
		photo1Obj.style.filter = "alpha(opacity = " + (100 - Opacity) + ")";
		photo1Obj.style.mozOpacity = (100 - Opacity)/100;
		photo1Obj.style.opacity = (100 - Opacity)/100;
		photo2Obj.style.filter = "alpha(opacity = " + Opacity + ")";
		photo2Obj.style.mozOpacity = Opacity/100;
		photo2Obj.style.opacity = Opacity/100;
	} else {
		photo1Obj.style.filter = "alpha(opacity = " + Opacity + ")";
		photo1Obj.style.mozOpacity = Opacity/100;
		photo1Obj.style.opacity = Opacity/100;
		photo2Obj.style.filter = "alpha(opacity = " + (100 - Opacity) + ")";
		photo2Obj.style.mozOpacity = (100 - Opacity)/100;
		photo2Obj.style.opacity = (100 - Opacity)/100;
	}

	if (Opacity >= 0) {
		timerCyclePhoto = setTimeout("cyclePhoto(" + (Opacity - 10) + ")", 0);
	} else {
		if (currentPhoto == "photo1") {
			currentPhoto = "photo2"
			changePhoto("photo1", "image1");
		} else {
			currentPhoto = "photo1"
			changePhoto("photo2", "image2");
		}
		timerCyclePhoto = setTimeout("cyclePhoto(100)", 30000);
	}
} 

function fadePageOut(Opacity, pageName, watermark, watermarkTop, watermarkLeft) {

	var fadePageOutTimer;
	var watermarkObj;
	var watermarkImgObj;
	var iframeObj = findDOM("content", 0);
	var watermarkObj = findDOM("watermark", 0);

	watermarkObj.style.filter = "alpha(opacity = " + Opacity + ")";
	watermarkObj.style.mozOpacity = Opacity/100;
	watermarkObj.style.opacity = Opacity/100;
	iframeObj.style.filter = "alpha(opacity = " + Opacity + ")";
	iframeObj.style.mozOpacity = Opacity/100;
	iframeObj.style.opacity = Opacity/100;
	clearTimeout(fadePageOutTimer);
	if (Opacity >= 0) {
		fadePageOutTimer = setTimeout("fadePageOut(" + (Opacity - 10) + ", '" + pageName + "', '" + watermark + "', '" + watermarkTop + "', '" + watermarkLeft + "')", 1);
	} else {
		watermarkImgObj = findDOM("watermarkImg", 0);
		watermarkImgObj.src = watermark;
		iframeObj.src = pageName;
		watermarkObj.style.top = watermarkTop;
		watermarkObj.style.left = watermarkLeft;
		
		fadePageOutTimer = setTimeout("fadePageIn(0)", 400);
	}
} 

function fadePageIn(Opacity) {

	var fadePageInTimer;
	var iframeObj = findDOM("content", 0);
	var watermarkObj = findDOM("watermark", 0);

	watermarkObj.style.filter = "alpha(opacity = " + Opacity + ")";
	watermarkObj.style.mozOpacity = Opacity/100;
	watermarkObj.style.opacity = Opacity/100;
	iframeObj.style.filter = "alpha(opacity = " + Opacity + ")";
	iframeObj.style.mozOpacity = Opacity/100;
	iframeObj.style.opacity = Opacity/100;
	clearTimeout(fadePageInTimer);
	if (Opacity <= 100) {
		fadePageInTimer = setTimeout("fadePageIn("+ (Opacity + 10) + ")", 1);
	}
}

function scrollImages(minYcoord, maxYcoord) {

	var obj;
	var scrollTimer = "";
	var imgStr = "";
	var imgTop;
	var imgLeft;

	for (i = 0 ; i < page2ImageURLs.length ; i++) {
		obj = findDOM(page2ImageURLs[i].substr(page2ImageURLs[i].indexOf("/") + 1, ((page2ImageURLs[i].length - 5) - page2ImageURLs[i].indexOf("/"))), 0);
		obj.style.position = "absolute";
		obj.style.top = scrollYcoords[i];
		obj.style.left = scrollXcoords[i];
		scrollYcoords[i] = (scrollYcoords[i] - 1);
		if (scrollYcoords[i] < minYcoord) {
			scrollYcoords[i] = maxYcoord;
		}
	}
	if (stopScroll != 1) {
		scrollTimer = setTimeout("scrollImages(" + minYcoord + ", " + maxYcoord + ")", 100);
	}
}