// global variables for timeout and for current menu
var t=false,current;
function SetupMenu() {
	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;
			}		
		}
	}
}
// find the first child object of a particular 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 the mouse over?
	thislink = (e.target) ? e.target: e.srcElement;
	ResetTimer();
	// hide the previous menu, if any
	if (current) HideMenu (current);
	// we want the LI, not the link
	thislink = thislink.parentNode;
	current=thislink;
	// find sun menu, if any
	ul = findChild(thislink,"UL");
	if (!ul) return;
	ul.style.display="block";
}
function HideMenu(thelink) {
	// find the submenu,if any
	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)",200);
}
// Set up the menu when the page loads
// window.onload=SetupMenu;
	


function initFuncs() {
	SetupMenu();
	if (document.getElementById('contactForm')) {
	var contact = document.getElementById('contactForm');
	var inputs = contact.getElementsByTagName('input');
	var area = contact.getElementsByTagName('textarea');	
	var sel = contact.getElementsByTagName('select');		
	for (var i=0;i<inputs.length;i++) {
		if (inputs[i].id == 'sbmtBtn') continue;
		addEvent(inputs[i],'focus',highlight,false);
		addEvent(inputs[i],'blur',unhighlight,false);		
	}
	for (var i=0;i<area.length;i++) {
		addEvent(area[i],'focus',highlight,false);
		addEvent(area[i],'blur',unhighlight,false);		
	}	
	for (var i=0;i<sel.length;i++) {
		addEvent(sel[i],'focus',highlight,false);
		addEvent(sel[i],'blur',unhighlight,false);		
	}					
	var dancerLink = document.getElementById('dancer');
	addEvent(dancerLink,'click',switchDance,false);
	}
	
	var ancs = document.getElementsByTagName('a');
	for(var i=0;i<ancs.length;i++) {
		if (!ancs[i].attributes['class']) continue;
		if (ancs[i].attributes['class'].nodeValue == 'popUp') {
			addEvent(ancs[i],'click',loadInNew,false);
		}
	}
	
}

function loadInNew(e) {
	var target = catchAndStop(e)
	var newWin = window.open(target.href,'newWin');
}
	
	
function catchAndStop(e) {
	if (!e) e = window.event;
	if (e.preventDefault) {
		e.preventDefault();
	} else {
		e.returnValue = false	
	}	
	target = e.srcElement || e.target;
	return target;
}




function switchDance() {
	var dancerLink = document.getElementById('dancer');
	var dancerDiv = document.getElementById('dancerDiv');
	if (dancerLink.checked) {
		dancerDiv.style.display = 'block';
	} else {
		dancerDiv.style.display = 'none';		
	}	
}

function checkContact(form) {
	if (form.Fname.value == '') {
		alert('You must provide your name.');	
		form.Fname.className = 'formError';		
		form.Fname.focus();
		return false;
	}
	if ((form.Femail.value == '') || (form.Femail.value.indexOf('@') == -1)) {
		alert('You need to provide an email address.');	
		form.Femail.className = 'formError';		
		form.Femail.focus();
		return false;	
	}
	return true;
}

function highlight(e) {
	if (!e) e = window.event;
	var target = e.srcElement || e.target;
	target.style.background = '#fff';	
}
function unhighlight(e) {
	if (!e) e = window.event;
	var target = e.srcElement || e.target;
	target.style.background = '#eee';	
	target.className = 'noerror';
}



addEvent(window,'load',initFuncs,false);
function addEvent(elm, type, fn, cap) {
	if (elm.addEventListener) {
		elm.addEventListener(type,fn,cap);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on'+type,fn);
		return r;
	}
	else {
		elm['on'+type] = fn;
	}
}	
