document.observe("dom:loaded", function() {
  // initially hide all containers for tab content
  var MainMenu = new Menu('menu');
});
var FxQuick;

function Menu(id) {
	
	var id;
	var obj;
	var revert;
	this.init(id);
	
}

Menu.prototype.init = function(id) {
	
	if (FxQuick) {
		FxQuick.hideOpacity('GalleryOverlay');
	}
	
	this.id = id;
	var ref = this;
	
	this.obj = $(this.id);
	this.obj.select('ul.cat').each(function(e) {
		e.hide();
	});
	
	this.obj.select('ul li.main').each(function(e) {
		e.ref = ref;
		e.onmouseover = function() {
			this.ref.hover(this);
		}
		e.onmouseout = function() {
			this.ref.out(this);
		}
	});
	
	$$('ul.cat').each(function(e) {
		evenHeight(e.select('ul.gal'));
	});
	
}

Menu.prototype.hover = function(ref) {
	
	var obj = this;
	if($(ref).hasClassName('main')) {
		
		$$('.main.act').each(function(e) {
			e.removeClassName('act');
			e.addClassName('actfade');
			obj.revert = e;
		});
		
	}
	
	$(ref).addClassName('hv');
	
	var sub = $(ref).down('ul.cat');
	if (sub) {
		sub.show();
		var w = $(ref).getWidth();
		var offset = $(ref).positionedOffset();
		var h = sub.getHeight();
		sub.style.left = offset[0] + w + 'px';
		sub.style.top = (offset[1]-((h-30)/2)) + 'px';
		sub.style.zIndex = 1001;
		if (FxQuick) {
			$('GalleryOverlay').style.zIndex = 1000;
			$('GalleryOverlay').show();
			FxQuick.show($('GalleryOverlay'));
		}
	}
}

Menu.prototype.out = function(ref) {
	
	if ($(ref).hasClassName('main')) {
		if(this.revert) {
			this.revert.removeClassName('actfade');
			this.revert.addClassName('act');
			this.revert = false;
		}
	}
	
	var sub = $(ref).down('ul.cat');
	if (sub) {
		sub.hide();
		if (FxQuick) {
			FxQuick.hide($('GalleryOverlay'));
		}
	}
	$(ref).removeClassName('hv');
	
}

