var NavMenu = {
	On: '',
	CurrentNav: '',
	CurrentColor: '',
	atimer: null,
	btimer: null,
	tspeedshow: 600,
	tspeedhide: 300,
	
	showNav: function(caller, col1, col2){
		clearTimeout(this.btimer);
		this.hideCurrentNav(true);
		
		if (caller){
			var elt = $(caller.id+'_pan');
			if ((elt) && (elt.id != this.CurrentNav)){
				if (!elt.visible()){
					elt.show();
					a = caller.select('a')[0];
					a.setStyle({color: col2});
					this.CurrentNav = elt.id;
					this.CurrentColor = col1;
				}
			}
		}
	},
	hideCurrentNav: function(p){
		// (p = true) means event is triggered from the div to hide
		elt = $(this.CurrentNav);
		if ((elt) && (elt.visible()) && ((this.On != elt.id) || (p))){
			callerid = elt.id;
			pos=callerid.indexOf('_');
			callerid=callerid.substring(0,pos);
			
			elt.hide();
			this.On = '';
			this.CurrentNav = '';
			if ($(callerid)){
				a = $(callerid).select('a');
				if (a.length > 0){
					b = a[0];
					b.setStyle({color: this.CurrentColor});
				}	
			}
		}
	},
	show: function(caller, col1, col2){
		if (this.CurrentNav == ''){
			this.showTimer(caller, col1, col2);
		}else{
			this.showNav(caller, col1, col2);
		}
	},
	clearTimers: function(){					
		clearTimeout(this.atimer);
		clearTimeout(this.btimer);
	},
	showTimer: function(caller, col1, col2){
		this.clearTimers();
		this.atimer = setTimeout(function(){NavMenu.showNav(caller, col1, col2)}, this.tspeedshow); 
	},
	hideTimer: function(){
		this.clearTimers();
		this.btimer = setTimeout(function(){NavMenu.hideCurrentNav(false)}, this.tspeedhide); 
	}
}

Event.observe(window, 'load', function (){
	var nav = $$('.navigation');
	for (i=0;i<nav.length;i++){
		Event.observe(nav[i], 'mouseout', function() {
			NavMenu.clearTimers();
			NavMenu.hideTimer();
		});
	}
	
	var navbut;
	navbut = $$('.nav1');
	//NavMenu.show(this,'#000','#fff')
	for (i=0;i<navbut.length;i++){
		Event.observe(navbut[i], 'mouseover', function() {
			NavMenu.show(this,'#000','#fff')
		});
	}
	navbut = $$('.nav2');
	//NavMenu.show(this,'#000','#fff')
	for (i=0;i<navbut.length;i++){
		Event.observe(navbut[i], 'mouseover', function() {
			NavMenu.show(this,'#fff','#D4005E')
		});
	}
});

function NavOff(pEvent, pThis){
	var toElt = pEvent.relatedTarget || pEvent.toElement;
	
	if (toElt.id == pThis.id){
		if (!(toElt.up('.pan'))){
			NavMenu.hideCurrentNav(true);
		}
	}
}