if (!ASB) var ASB = {};

ASB.Navbar = function(active) {
	this.bar = $id('navbar');
	this.main = $id('main_navbar');
	this.curtain = $id('navbar_curtain');
	this.images = 
	this.addBehavior();
	this.latestHover = active;
	this.active = active;
}

ASB.Navbar.prototype.addBehavior = function() {
	var self = this;
	var links = this.main.getElementsByTagName('a');
	for (var i=0; i < links.length; i++) {
		links[i].asbIndex = i;
		links[i].onmouseover = function() {
			self.hover(this);
		}
	};
	
	var images = this.bar.getElementsByTagName('img');
	for (var i=0; i < images.length; i++) {
		images[i].asbIndex = i;
		images[i].onmouseover = function() {
			self.imageOver(this);
		}
		images[i].onmouseout = function(e) {
			self.imageOut(this);
		}
	};
	Atira.Event.addListener(this.bar,'mouseout',function(e) {
		self.barOut(e);
	});
}

ASB.Navbar.prototype.hover = function(tag) {
	var index = tag.asbIndex;
	$id('navbar_'+this.latestHover).style.display='none';
	$id('navbar_'+index).style.display='block';
	this.curtain.className = 'curtain_'+index;
	this.curtain.style.display='block';
	this.latestHover = index;
}

ASB.Navbar.prototype.imageOver = function(img) {
	if (img.className!='selected') {
		img.src=img.src.replace(/.png/,'_hover.png');
	}
}

ASB.Navbar.prototype.imageOut = function(img) {
	if (img.className!='selected') {
		img.src=img.src.replace(/_hover\.png/,'.png');
	}
}

ASB.Navbar.prototype.barOut = function(e) {
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg.nodeName!='BODY') {
		reltg = reltg.parentNode;
		if (reltg && reltg.id=='navbar') {
			return;
		}
	}	
	$id('navbar_'+this.latestHover).style.display='none';
	//$id('navbar_'+this.active).style.display='block';
	this.latestHover = this.active;
	this.curtain.style.display='none';
}
