var images = new Array(
	"/gfx/imgWelcome.jpg",
	"/gfx/imgWelcome-2.jpg",
	"/gfx/imgWelcome-3.jpg",
	"/gfx/imgWelcome-4.jpg",
	"/gfx/imgWhoWeAre.jpg",
	"/gfx/imgWhoWeAre-2.jpg",
	"/gfx/imgWhoWeAre-3.jpg",
	"/gfx/imgWhatWeDo.jpg",
	"/gfx/imgWhatWeDo-2.jpg",
	"/gfx/imgWhatWeDo-3.jpg",
	"/gfx/imgWeddings.jpg",
	"/gfx/imgWeddings-2.jpg",
	"/gfx/imgWeddings-3.jpg",
	"/gfx/imgPrivateParties.jpg",
	"/gfx/imgPrivateParties-2.jpg",
	"/gfx/imgPrivateParties-3.jpg",
	"/gfx/imgCorporateEvents.jpg",
	"/gfx/imgCorporateEvents-2.jpg",
	"/gfx/imgCorporateEvents-3.jpg",
	"/gfx/imgTestimonials.jpg",
	"/gfx/imgTestimonials-2.jpg",
	"/gfx/imgTestimonials-3.jpg",
     "/gfx/imgMenus.jpg",
	"/gfx/imgMenus-2.jpg",
	"/gfx/imgMenus-3.jpg",
	"/gfx/imgFarms.jpg",
	"/gfx/imgFarms-2.jpg",
	"/gfx/imgFarms-3.jpg",
	"/gfx/imgVenue.jpg",
	"/gfx/imgVenue-2.jpg",
	"/gfx/imgVenue-3.jpg",
	"/gfx/imgEmployment.jpg",
	"/gfx/imgEmployment-2.jpg",
	"/gfx/imgEmployment-3.jpg"
);

var currText = "Welcome";
var currBio = "";
var currImgIdx = 1;
var currTimer = null;
function preload() {
	var img = new Image();
	for (i = 0;i < images.length;i++)
		img.src = images[i];
}

function getElem(item) {
	if (document.getElementById) { // this is the way the standards work
		return document.getElementById(item);
	}
	else if(document.all) { // this is the way old msie versions work
		return document.all[item];
	}
	else if(document.layers) { // this is the way nn4 works
		return document.layers[item];
	}
}
function menuOver(item) {
	for (var e = item.parentNode;e;e = e.parentNode) {
		if (e.className && e.className == "nav") {
			e.className = "nav nav-on";
			return;
		}
	}
}
function menuOut(item) {
	for (var e = item.parentNode;e;e = e.parentNode) {
		if (e.className && e.className == "nav nav-on") {
			e.className = "nav";
			return;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = getElem(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function blendImage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);

	getElem(divid).style.backgroundImage = "url(" + getElem(imageid).src + ")";
	changeOpac(0, imageid);
	setTimeout("getElem('" + imageid + "').src = '" + imagefile + "';", 50);

	for (i = 0;i <= 100;i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(i * speed) + 50);
	}
}
function imageFader(name) {
	var suffix = "";
	if (currImgIdx == 4) currImgIdx = 1;
	else {
		currImgIdx++;
		suffix = "-" + currImgIdx;
	}
	blendImage("mainImageCont", "mainImage", "/gfx/img" + name + suffix + ".jpg", 1500);
}
function startFader(name) {
	if (currTimer) clearInterval(currTimer);
	if (name == "Welcome") {
		currImgIdx = 1;
		currTimer = setInterval("imageFader('" + name + "')", 5000);
	}
}
//startFader("Welcome");

function swapText(newText) {
	try {
		onIndex;
	} catch(e) {
		window.location = "/#" + newText;
		return;
	}
	if (currText == newText) return;

	//startFader(newText);

	getElem(currText).style.display = 'none';
	getElem(newText).style.display = 'block';

	currText = newText;

	getElem("mainImage").src = '/gfx/img' + newText + '.jpg';
}
function swapBio(newBio) {
	if (currBio == newBio) {
		if (newBio != "") getElem(newBio).style.display = 'none';
		currBio = '';
	}
	else {
		if (currBio != "") getElem(currBio).style.display = 'none';
		if (newBio != "") getElem(newBio).style.display = 'block';
		currBio = newBio;
	}
}

function loadCheck() {
	var loc = window.location.toString();
	var idx = loc.lastIndexOf("#");
	if (idx > -1) {
		var act = loc.substr(idx + 1);
		swapText(act);
	}
	else {
		idx = loc.lastIndexOf("?");
		if (idx > -1) {
			var act = loc.substr(idx + 1);
			swapText(act);
		}
		else if (window.initial_section) {
			swapText(window.initial_section);
		}
	}
}
