﻿var pageNames = new Array(12);
pageNames[0] = "HomePage";
pageNames[1] = "RatesGenPage";
pageNames[2] = "RatesGenPage";
pageNames[3] = "RatesWedRecPage";
pageNames[4] = "RatesWedCerRecPage";
pageNames[5] = "RatesPromPage";
pageNames[6] = "ContactPage";
pageNames[7] = "GalleryPage";
pageNames[8] = "CaterersPage";
pageNames[9] = "ParkingPage";
pageNames[10] = "VideoPage";
pageNames[11] = "PoliciesPage";

var navNames = new Array(12);
navNames[0] = "HomeNav";
navNames[1] = "RatesNav";
navNames[2] = "RatesNav";
navNames[3] = "RatesNav";
navNames[4] = "RatesNav";
navNames[5] = "RatesNav";
navNames[6] = "ContactNav";
navNames[7] = "GalleryNav";
navNames[8] = "CaterersNav";
navNames[9] = "ParkingNav";
navNames[10] = "VideoNav";
navNames[11] = "PoliciesNav";

//The left position of the animated G when the nave is clicked
var flyingGPosLeft = new Array(12);
flyingGPosLeft[0] = "27";
flyingGPosLeft[1] = "37";
flyingGPosLeft[2] = "0";
flyingGPosLeft[3] = "0";
flyingGPosLeft[4] = "0";
flyingGPosLeft[5] = "0";
flyingGPosLeft[6] = "14";
flyingGPosLeft[7] = "24";
flyingGPosLeft[8] = "9";
flyingGPosLeft[9] = "9";
flyingGPosLeft[10] = "9";
flyingGPosLeft[11] = "-20";

//The top position of the animated G when the nave is clicked
var flyingGPosTop = new Array(12);
flyingGPosTop[0] = "-10";
flyingGPosTop[1] = "48";
flyingGPosTop[2] = "0";
flyingGPosTop[3] = "0";
flyingGPosTop[4] = "0";
flyingGPosTop[5] = "0";
flyingGPosTop[6] = "107";
flyingGPosTop[7] = "165";
flyingGPosTop[8] = "225";
flyingGPosTop[9] = "281";
flyingGPosTop[10] = "337";
flyingGPosTop[11] = "393";

var flyingGFrameCounter = 26;
var navActiveId = 0;
var navPreviousActiveId = 0;

function buildNav(){
	var pageName = window.location.hash.replace("#", "");
	if (pageName != "") {
		for (i in pageNames) {
			if (pageNames[i] != pageName + "Page") {
				//Turn the display to none on all the pages
				document.getElementById(pageNames[i]).style.display = "none"
				//Set nav class to inactive
				document.getElementById(navNames[i]).className = "nav";
			} else {
				//Set the display to block on the page clicked
				document.getElementById(pageName + "Page").style.display = "block";
				//Set the nav to active
				document.getElementById(navNames[i]).className = "navActive";
				//alert(i);
				//Set the anchor link at the top of the page
				document.getElementsByTagName("body")[0].firstChild.name = pageName;
				document.getElementsByTagName("body")[0].firstChild.id = pageName;

				window.location.hash = pageName.replace("Page", "");

				document.getElementById("flyingG26").style.top = flyingGPosTop[i] + "px";
				document.getElementById("flyingG26").style.left = flyingGPosLeft[i] + "px";
				navActiveId = i;
				navPreviousActiveId = i;
			} //pageNames[i] != pageName
		}//for
	} //pageName != ""
}//init()

function navOver(obj) {
	if (obj.className != "navActive") {
		obj.className = "navOver";
	}
	//So the text wont be selected if the mouse is down and dragged over our link
	if (window.getSelection) { // Firefox, Opera, Google Chrome and Safari
		var selection = window.getSelection();
		selection.removeAllRanges();
	}
	else {
		if (document.selection.createRange) {// Internet Explorer
			var range = document.selection.createRange();
			document.selection.empty();
		}
	}
} //navOver

function navOut(obj) {
	if (obj.className != "navActive") {
		obj.className = "nav";
	}
} //navOut

function navDown(obj, pageId, navId) {
	//So the text wont be selected if the mouse drags over when the nav is clicked
	if (typeof obj.onselectstart != "undefined") { //IE
		obj.onselectstart = function () { return false }
	} else {
		if (typeof obj.style.MozUserSelect != "undefined") { //Firefox
			obj.style.MozUserSelect = "none"
		} else { //All others
			obj.onmousedown = function () { return false }
		}
	};

	//Change the page and highlight the nav
	for (i in pageNames) {
		//Turn the display to none on all the pages
		document.getElementById(pageNames[i]).style.display = "none";
		//Set nav class to inactive
		document.getElementById(navNames[i]).className = "nav";
		if (i == pageId & flyingGPosTop[i] != 0) {
			navPreviousActiveId = navActiveId;
			navActiveId = i;
		}
	};
	//alert(navPreviousActiveId + " - " + navActiveId);

	//Turn the display to block on the called page
	document.getElementById(pageNames[pageId]).style.display = "block";
	//Set nav class to active on the called nav
	document.getElementById(navNames[navId]).className = "navActive";
	//Set the anchor link at the top of the page and the url
	document.getElementsByTagName('body')[0].firstChild.name = pageNames[pageId].replace("Page","");
	document.getElementsByTagName('body')[0].firstChild.id = pageNames[pageId].replace("Page", "");

	window.location.hash = pageNames[pageId].replace("Page", "");

	if(flyingGPosTop[pageId] != 0 & flyingGFrameCounter == 26) flyingGanimation();
} //navDown

function navBodyOver(obj) {
	//This is for links in the body text
	obj.className = "navBodyOver";
} //navBodyOver

function navBodyOut(obj) {
	//This is for links in the body text
	obj.className = "navBody";
} //navBodyOut

function navBodyDown(pageName, obj) {
	//This is for links in the body text
	for (i in pageNames) {
		if (pageNames[i] != pageName) {
			//Turn the display to none on all the pages
			document.getElementById(pageNames[i]).style.display = "none";
			//Set nav class to inactive
			document.getElementById(navNames[i]).className = "nav";
		} else {
			//Set the display to block on the page clicked
			document.getElementById(pageName).style.display = "block";
			document.getElementById("topOfPage").name = pageName;
			window.location.hash = pageName;
			obj.className = "navActive";
		}
	}
} //navBodyDown

function flyingGanimation() {
	var down = flyingGFrameCounter;
	var up = 27 - flyingGFrameCounter;
	//Turn off the last frame
	if(up < 26)	document.getElementById("flyingG" + up).style.display = "none";
	document.getElementById("flyingG" + down).style.display = "none";
	//advance the counter
	flyingGFrameCounter--;
	down = flyingGFrameCounter;
	up = 27 - flyingGFrameCounter;
	//Is this the end
	if (flyingGFrameCounter > 0) {
		//Position the images
		document.getElementById("flyingG" + down).style.top = flyingGPosTop[navPreviousActiveId] + "px";
		document.getElementById("flyingG" + down).style.left = flyingGPosLeft[navPreviousActiveId] + "px";
		document.getElementById("flyingG" + up).style.top = flyingGPosTop[navActiveId] + "px";
		document.getElementById("flyingG" + up).style.left = flyingGPosLeft[navActiveId] + "px";
		//Turn on the new frames
		document.getElementById("flyingG" + up).style.display = "block";
		document.getElementById("flyingG" + down).style.display = "block";
		setTimeout("flyingGanimation()", 50)
	} else {
		flyingGFrameCounter = 26;
	}
} //flyingGanimation
