subnavTimes = new Array(-1,-1);

setInterval("checkNav()", 20);

function checkNav() {
	for (i = 0; i < subnavTimes.length; i++){
		if (subnavTimes[i] != -1){
			subnavTimes[i]++;
			if (subnavTimes[i] == 10){
				closenav(i + 1);
			}
		}
	}
}

function opennav(navNr){
	//swap bg
	nav = 'topnav' + navNr;
	//swap(nav, true);
	
	//show subnav
	div = document.getElementById('subnav' + navNr);
	posnav = document.getElementById('posnav' + navNr);
	
	div.style.top = 53;
	div.style.left = posnav.offsetLeft - 1;
	div.style.display = 'block';
	
	subnavTimes[navNr - 1] = -1;
}

function closenav(navNr){
	nav = 'topnav' + navNr;
	//swap(nav);
	
	//show subnav
	div = document.getElementById('subnav' + navNr);
	div.style.display = 'none';	
	
	subnavTimes[navNr - 1] = -1;
}

function setClosenav(navNr){
	subnavTimes[navNr - 1] = 0;
}

function swap(id, keepon){
	img = document.getElementById(id);
	
	cursrc = img.src;
	
	overpos = cursrc.indexOf("_h.gif");
	normpos = cursrc.indexOf("_n.gif");
	
	if (normpos != -1) {
		//replace image
		begin = cursrc.substr(0,normpos)
		newsrc = begin + "_h.gif";
		img.src = newsrc;
	}
	
	if (overpos != -1  && keepon == undefined) {
		//replace image
		begin = cursrc.substr(0,overpos)
		newsrc = begin + "_n.gif";
		img.src = newsrc;
	}		
}

function swapbg(id, keepon){
	img = document.getElementById(id);
		
	cursrc = img.style.backgroundImage;
	cursrc = cursrc.substr(4, cursrc.length - 5);
		
	overpos = cursrc.indexOf("_h.gif");
	normpos = cursrc.indexOf("_n.gif");
	
	if (normpos != -1) {
		//replace image
		begin = cursrc.substr(0,normpos)
		newsrc = begin + "_h.gif";
		img.style.backgroundImage = 'url(' + newsrc + ')';
	}
	
	if (overpos != -1 && keepon == undefined) {
		//replace image
		begin = cursrc.substr(0,overpos)
		newsrc = begin + "_n.gif";
		img.style.backgroundImage = 'url(' + newsrc + ')';
	}
}