// Teramedia Menus vers. 3.0

function hideAllMenus(){
	for (i=0; i<MENUS.length; i++)
		MENUS[i].off();
}

function item_class(item_id, css_class){
	document.getElementById (item_id).className = css_class;
}
function menu_show(){
	clearTimeout(this.hideTimer);
	this.hideTimer = null;
	for (i=0; i<MENUS.length; i++){
		if (i!=this.num) MENUS[i].off();
	}
	availHeight = parseInt(document.body.clientHeight);
	scrollHeight = parseInt((isIE)? document.body.scrollTop : window.pageYOffset);
	var top = Math.min((this.parent_div.offsetTop + parseInt(this.top_off)), (availHeight + scrollHeight - parseInt(this.length)));
	if (top < scrollHeight) top = scrollHeight;
	this.div.style.top = top + 'px';
	this.div.style.left = parseInt(this.parent_div.offsetLeft) + parseInt(this.left_off) + 'px';
	this.div.style.visibility = 'visible';
}

function menu_hide(){
	this.hideTimer = setTimeout('MENUS[' + this.num + '].off()', this.hide_delay);
}

function menu_over(){
	clearTimeout(this.hideTimer);
	this.hideTimer = null;
}
function menu_out(){
	this.hide();
}
function menu_off(){
	this.div.style.left = '0';
	this.div.style.visibility = 'hidden';
}

function menu (params_array, parent_div, ord_num){

	this.name = params_array[0];
	this.num = ord_num;
	this.width = params_array[1];
	this.parent_div = parent_div;
	this.left_off = params_array[2];
	this.top_off = params_array[3];
	this.css_class = params_array[4];
	this.hide_delay = 500;
	
	this.over = menu_over;
	this.out = menu_out
	this.show = menu_show;
	this.hide = menu_hide;
	this.off = menu_off;

	document.write(
		'<div class="' + this.css_class + '" id="menu_div' + this.num + '" style="position: absolute; width: '
		+ this.width + 'px; top: 0px; left: 0px; visibility: hidden" '
		+ 'onMouseOver="MENUS[' + this.num + '].over()" onMouseOut="MENUS['
		+ this.num + '].out()">'
	);
	for (el_count=5; el_count<params_array.length; el_count++){
		item_caption = params_array[el_count][0];
		item_link = params_array[el_count][1];
		item_id = el_count - 5;
		item_html_id = "menu_item_" + this.num + '_' + item_id;
		document.write(
			'<a href="' + item_link + '" onClick="hideAllMenus()"><div id="' 
			+ item_html_id + '" class="' + this.css_class + '_item" onMouseOver="item_class(' 
			+ "'" + item_html_id + "', '" + this.css_class + "_item_over'" + ')" onMouseOut="item_class(' 
			+ "'" + item_html_id + "', '" + this.css_class + "_item'" + ')">' + item_caption + '</div></a>'
		);
	}
	document.write(
		'</div>'
	);
	this.div = document.getElementById ('menu_div' + this.num);
	this.length = this.div.offsetHeight;
}

function create_menus (){
	for (menu_count=0; menu_count<MENU_ITEMS.length; menu_count++){
		MENUS[menu_count] = new menu (MENU_ITEMS[menu_count], 
			document.getElementById ('action_div' + menu_count), menu_count);
	}
}

create_menus();
function showMenu(n){ MENUS[n].show(); }
function hideMenu(n){ MENUS[n].hide(); }

