﻿var bi = new BrowserInfo();

var menu = new Array(
	'menu_about',
	'menu_news',
	'menu_copyright',
	'menu_past');

var submenu = new Array(
	'menu_about_submenu', 
	'menu_news_submenu', 
	'menu_copyright_submenu', 
	'menu_past_submenu');

var activeSubmenu = null;

window.onload = function() {
	for (var i = 0; i < submenu.length; i++) {	
		// Event.observe(submenu[i], 'mouseout', e_mouseout);
		Event.observe(submenu[i], 'mouseover', e_mouseover);
	}

}

if (!bi.ie || (bi.ie && bi.ieMVersion > 6)) {
	document.onmousedown = function(event) {
		// alert(Event.pointerX(event) + ', ' + Event.pointerY(event));
		if (activeSubmenu) {
			activeSubmenu.withinRect(Event.pointerX(event), Event.pointerY(event));
		}
	}
}

function e_mouseover(event) {
	var submenuid = Event.element(event);
}

function refreshSubmenu() {
	for (var i = 0; i < submenu.length; i++) {
		$(submenu[i]).style.display = 'none';
	}
}

function displaySubmenu(menuid) {
	refreshSubmenu();
	var submenuid = menuid + "_submenu";
	$(submenuid).style.display = 'block';
	activeSubmenu = new Rect(submenuid);
}

function Rect(id) {
	var pos  = Position.positionedOffset($(id));
	var rect = Element.getDimensions($(id));
	this.id = id;
	this.x = pos[0];
	this.y = pos[1];
	this.width = rect.width;
	this.height = rect.height;
}

Rect.prototype.withinRect = function(x, y) {
	if (x < this.x || y < this.y || x > (this.x + this.width) || y > (this.y + this.height)) {
		refreshSubmenu();
	}
}

Rect.prototype.getRect = function(id) {
	var pos  = Position.positionedOffset($(id));
	var rect = Element.getDimensions($(id));
	this.x = pos[0];
	this.y = pos[1];
	this.width = rect.width;
	this.height = rect.height;
}


