// JavaScript Document

var menus = new Array("about", "connected", "lifetogether", "resources", "contact");

/*
 *  ======== show_menu ========
 *  Alternates the images in the main menu and displays the text below.
 */
function show_menu(selected, path)
{
	/* For each menu... */
	for (var i = 0; i < menus.length; i++) {
		var menu = menus[i];
		
		/* Hide all submenus */
		var submenux = document.getElementById(menu + '_submenu');
		submenux.style.display = "none";
		
		/* Turn all of the images orange */
		var menux = document.getElementById(menu);
		menux.style.background = "url(" + path + "images/elements/" + menu + ".gif) no-repeat";
	}
	
	/* Show the selected submenu */
	var submenux = document.getElementById(selected + '_submenu');
	submenux.style.display = "block";
	
	/* Set the selected menu white */
	var menux = document.getElementById(selected);
	menux.style.background = "url(" + path + "images/elements/" + selected + "_wht.gif) no-repeat";	
}

/*
 * ======== preloadMenuImgs ========
 * Pre-loads all of the secondary menu images.
 */
function preloadMenuImgs(path) {
    var d = document;
	
    if (!d.menuImgs) {
		d.menuImgs = new Array();
	}
	
	for (var i = 0; i < menus.length; i++) { 
		d.menuImgs[i] = new Image();
		d.menuImgs[i].src = path + "images/elements/" + menus[i] + "_wht.gif";
	}
}
 
/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html

*****/


/* Associate init function with load event. */
/*
if (window.addEventListener) {
	window.addEventListener("load", xfade_init, false);
}
	else {
	window.attachEvent("onload", xfade_init);
}
*/

var d = document;
var imgs = new Array();
var zInterval = 6000;
var current = 0;
var pause = false;

function xfade_init() {
	if(!d.getElementById) {
		return;
	}

	imgs = d.getElementById("top-half").getElementsByTagName("img");
	
	for(i = 1; i < imgs.length; i++) {
		imgs[i].xOpacity = 0;
	}
	
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade, zInterval);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	
	nIndex = imgs[current + 1] ? current + 1 : 0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity -= .05; 
	nOpacity += .05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity <= 0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade, zInterval);
	} else {
		setTimeout(so_xfade, 50);
	}	
}

function setOpacity(obj) {
	if (obj.xOpacity > .99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}
