// global variables for timeout and for current menu
var t=false,current;
var numslides=0;
var currentslide=0, oldslide=4;
var x=0;
var slides= new Array();
function SetupMenu() {
	//MakeSlideShow();
	
	if (!document.getElementsByTagName) return;
	items=document.getElementsByTagName("li");
	for (i=0; i<items.length; i++) {
		if (items[i].className != "menu") continue;
		//set up event handlers
		thelink=findChild(items[i],"A");
		thelink.onmouseover=ShowMenu;
		thelink.onmouseout=StartTimer;
		//is there a submenu?
		if (ul=findChild(items[i],"UL")) {
			ul.style.display="none";
			for (j=0; j<ul.childNodes.length; j++) {
				ul.childNodes[j].onmouseover=ResetTimer;
				ul.childNodes[j].onmouseout=StartTimer;
			}
		}
	}
}

function MakeSlideShow() { 

	SetupMenu();
	//find all images with class: slide
	imgs=document.getElementsByTagName("img");
	
	for (i=0; i<imgs.length; i++) {
		if (imgs[i].className != "slide") continue;
		slides[numslides]=imgs[i];
		if (numslides==0) {
			imgs[i].style.display="none";
		} else {
			imgs[i].style.display="none";
		}
		numslides++;
	}
	slides[rand(slides.length)].style.display="block";
	menu.style.display="block";
}

function rand(num) {
	
	j=Math.floor(Math.random() * num);
	if (j==0) j++;
	return j;
}


//find the first child of a particular opbject type
function findChild(obj,tag) {
	cn = obj.childNodes;
	for (k=0; k<cn.length; k++) {
		if (cn[k].nodeName==tag) return cn[k];				
	}
	return false;
}
function ShowMenu(e) {
	if (!e) var e = window.event;
	// which link was mouse over/
	thislink = (e.target) ? e.target: e.srcElement;
	ResetTimer();
	//Hide the prev menu if any
	if (current) HideMenu(current);
	// we want the LI, not the link
	thislink = thislink.parentNode;
	current=thislink;
	//find the submenu if any
	ul = findChild(thislink,"UL");
	if (!ul) return;
	ul.style.display="block";
}
function HideMenu(thelink){
	// find the sub menu
	ul = findChild(thelink,"UL");
	if (!ul) return;
	ul.style.display="none";
}
function ResetTimer() {
	if (t) window.clearTimeout(t);
}
function StartTimer() {
	t = window.setTimeout("HideMenu(current)",400);
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}
//setup the menu when the Page loads
window.onload=MakeSlideShow;
	
