function createNavigation(ulid) {
	var images = document.getElementById(ulid).getElementsByTagName("img");

	//Determine the current selected tab
	for (var i=0; i < images.length; i++) {
		if (images[i].src.indexOf('_at') > 1) {currentAtId = images[i].id;} 
		else {
			images[i].onclick = function() {
				stopTimer();
				if (saveObj.id != this.id) {
					resetMenu(); //Make sure menu is at default state
					saveObj = this; //Save the new object
					displaySubNav(this.id,currentAtId,this,1); //Display the sub navigation
					return false;
				} else {
					return true;
				}
			};
			if (currentAtId != this.id) {
				images[i].onmouseout = function() {startTimer();};
			}
		}
		// Create the sub navigation events
		if (images[i].id != 'oo') 
			createSubNav(images[i].id);	
	}
}

function createSubNav(id) {
	var subnav = document.getElementById('headersubnav_'+id).getElementsByTagName("li");

	for(var i=0; i < subnav.length; i++) {
		subnav[i].onmouseover = function() {
			stopTimer();
			if (id == currentAtId && this.className.indexOf('at') == -1) {updateClassName(this,"hover","");}
		};
		subnav[i].onmouseout = function() {
			if (id == currentAtId) {updateClassName(this,"","hover");}
			else {startTimer();} 
		};
	}
}

function displaySubNav(x,y,img,state) {
	var d = document.getElementById('headersubnav_default');
	x = document.getElementById('headersubnav_'+x);
	y = document.getElementById('headersubnav_'+y);

	if (state == 1) {img.src = img.src.replace('_off','_on');}
	else {img.src=img.src.replace('_on','_off');}

	if (x != y) {
		d.style.display="none"; //Hide the default
		y.style.display="none"; //Hide the last item
		x.style.display="block"; //Show the current item
	}
}

function startTimer() {
	stopTimer(); //Make sure it is stopped first
	delayhide = setTimeout("resetMenu()",1000);
}

function resetMenu() {
	if (typeof saveObj == "object") {
		displaySubNav(currentAtId,saveObj.id,saveObj,0);
		saveObj = '';
		stopTimer();
	}
}

function stopTimer() {
	if (typeof delayhide != "undefined") {clearTimeout(delayhide);};
}