var imgFade, imgEl;
var imgCount = 2;
var imgTotal = 3;
var frontVisible = true;

window.Array.prototype.isIn = function(item) {
	for (var x in this) {
		if (this[x] == item) {
			return true;
			break;
		}
	}
	return false;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function imgLoader() {
	var newImg = new Image();
	newImg.onload = function() {
		if (frontVisible == true) {
			imgDiv.style.backgroundImage = "url(" + newImg.src + ")";
			imgFade.custom(1,0);
			frontVisible = false;
		} else {
			imgEl.src = newImg.src;
			imgFade.custom(0,1);		
			frontVisible = true;
		}
	}
	newImg.src = "/images/" + document.body.className + "_image_" + imgCount + ".jpg";
}

function setupFader() {
	if (Fx && $("fader_image") && $("fader_image_div")) {
		imgEl = $("fader_image");
		imgDiv = $("fader_image_div");
		imgFade = new Fx.Style(imgEl, "opacity", {duration:2000, onComplete: function() {
			if (imgCount<imgTotal) {
				imgCount++;
			} else {
				imgCount = 1;
			}
			setTimeout(imgLoader, 4000);
		}});
		setTimeout(imgLoader, 4000);
	}
}

addLoadEvent(setupFader);

function setupMenu() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("menubar");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI" && document.body.className != node.className) {
				if (node.getElementsByTagName("ul")[0]) {
					node.getElementsByTagName("ul")[0].style.width = node.offsetWidth + "px";
				}
				node.onmouseover = function() {
					this.className += " over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

addLoadEvent(setupMenu);
		
