function initNav(divs){
	var effects_a = new Array();
	var lis = divs.getElementsByTagName('li');
	for(var i =0;i<lis.length;i++){
		lis[i].onmouseover = mlover;
		lis[i].onmouseout = mloutSetTimeout;
		var uls = lis[i].getElementsByTagName('ul');
		for(var k=0;k<uls.length;k++){
			var found = 'no';
			for(var z=0;z<effects_a.length;z++){
				if(effects_a[z] == uls[k]){
					found = 'yes';
				}
			}
			if(found == 'no'){
				effects_a[effects_a.length] = uls[k];
				uls[k].style.zIndex = '1000';
				mlEffectLoad(uls[k]);
			}
		}
	}
}
function mloutSetTimeout(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.toElement;
	if(reltg){
		var under = ancestor(reltg,this);
		if(under === false && reltg != this){
			window.mlLast = this;
			var parent = this.parentNode;
			while(parent.parentNode && parent.className.indexOf('mlmenu') == -1){
				parent = parent.parentNode;
			}
			window.mlTimeout = setTimeout(function(){mlout()},1000);
		}
	}
}
function mlout(){
if(window.mlLast==null)return false;
	var uls = window.mlLast.getElementsByTagName('ul');
	for(var i=0;i<uls.length;i++){
		mlEffectOut(uls[i]);
		window.mlLast.className = 'haschild hide';
	}
	window.lastover = null;
}
function mlover(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	the_e.cancelBubble = true;
	if(the_e.stopPropagation){
		the_e.stopPropagation();
	}
	clearTimeout(window.mlTimeout);
	if(window.mlLast && window.mlLast != this && ancestor(this,window.mlLast) == false){
		mlout();
	}
	else{
		window.mlLast = null;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.fromElement;
	var ob = this.getElementsByTagName('ul');
		var under = ancestor(reltg,this);
		if(ob[0] && under == false){
			if(window.lastover != ob[0]){
				this.className = 'haschild';
				mlEffectOver(ob[0],this);
				window.lastover = ob[0];
			}
		}
}
function mlEffectOver(ob,parent){
	parent.className="hover";
	ob.className = 'show';
}
function mlEffectOut(ob){
	var parent = ob.parentNode;
	parent.className="";
	ob.className = '';
}
function mlEffectLoad(ob){
	var parent = ob.parentNode;
	while(parent.parentNode && parent.className.indexOf('mlmenu') == -1){
		parent = parent.parentNode;
	}
}
function ancestor(child, parent){
	if(child==null)return false;//Saves checking elsewhere
	//This is a fix for a Firefox bug *gasp*
	//Aparantly causes a bug in Opera!
	//I see no choice but a browser detect. *sigh* I didn't want to have to do this.
	if(navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Opera') == -1){
		//This should only be run by Gecko based browsers. this code should be fine in everything but Opera so forge away browsers.
		var allc = parent.getElementsByTagName('*');
		for(var i= 0;i<allc.length;i++){
			if(allc[i] == child){
				return true;
			}
		}
	}
	else{
		//http://www.dynamicdrive.com/forums/showthread.php?t=12341 Thanks Twey!
		for(; child.parentNode; child = child.parentNode){
			if(child.parentNode === parent) return true;
		}
	}
	return false;
}

function initButtons(){
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i<inputs.length; i++){
		if(inputs[i].type=="image"){
			addAnEvent(inputs.item(i),'mouseover',buttonHover);
			addAnEvent(inputs.item(i),'mouseout',buttonHoverout);
			inputs.item(i).style.borderWidth = "0px"
		}
		if(inputs[i].disabled == true){
			inputs[i].className = "disabled";
		}
	}
	
	var images = document.getElementsByTagName("img");
	for (var i = 0; i<images.length; i++){
		if(images[i].className=="button"){
			addAnEvent(images.item(i),'mouseover',buttonHover);
			addAnEvent(images.item(i),'mouseout',buttonHoverout);
		}
	}
}
function buttonHover(){
	if (this.src.indexOf("1") == -1){
		var file = this.src.split(".gif");
		this.src = file[0] + "1.gif";
	}
}
function buttonHoverout(){
	var file = this.src.split("1.gif");
	this.src = file[0] + ".gif";
}

function sfTarget () {
    var sfEls=document.getElementsByTagName("div");
    var aEls = document.getElementsByTagName("a");
    document.lastTarget = null;
    for (var i=0; i<sfEls.length; i++) {
        if (sfEls[i].id) {
            if (location.hash==("#" + sfEls[i].id)) {
                sfEls[i].className+=" sftarget";
                document.lastTarget=sfEls[i];
            }
            for (var j=0; j<aEls.length; j++) {
                if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i]; aEls[j].onclick = function() {
                    if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
                    if (this.targetEl) this.targetEl.className+=" sftarget"; document.lastTarget=this.targetEl;
                    return true;
                }
            }
        }
    }
}

//tracking and receipt pop ups
function initLinks(){
    var as = document.getElementsByTagName('a');
    for (var i=0; i<as.length; i++){
        if (as[i].className.indexOf("popup2") != -1){
            addAnEvent(as.item(i),'click',popupWin2);
        } else if (as[i].className.indexOf("popup") != -1){
	        addAnEvent(as.item(i),'click',popupWin);
	    }
    }

	if (document.getElementById("addattendee")){
		addAnEvent(document.getElementById("addattendee"),'click',addAttendee);
	}
}
function popupWin(){
    appWindow = window.open (this.href,"appWindow","width=800,height=500,toolbar=0,resizable=1,scrollbars=1");
    appWindow.focus ();
    return false;
}
function popupWin2(){
    appWindow = window.open (this.href,"appWindow","width=500,height=250,toolbar=0,resizable=1,scrollbars=1");
    appWindow.focus ();
    return false;
}

function addAnEvent(target, eventName, functionName){
	eval('target.on'+eventName+'=functionName');
}

function initAux(){}

function initPage(){
	if (document.getElementById){
		if (document.all) sfTarget();
		initNav(document.getElementById("nav"));
		if (document.getElementById("supernav")) initNav(document.getElementById("supernav"));
		initButtons();
		initLinks();
		initAux();
	}
}

window.onload=initPage;