///////////////////////////////////////////////////////////

MENU_BODY_WIDTH= 250;
MENU_OPACITY= 90;
MENU_FADE_STEP= 0.8;

MENU_MOZ_TO_IE_OPACITY_RATIO= 1;

///////////////////////////////////////////////////////////
//
//  оригиналът на част от това, което следва, се намира на
//  http://www.sonymediasoftware.com
//  10x, sonypeople, i love u
//
///////////////////////////////////////////////////////////

M= new Array ();

function appendMenu (_image, _over, _size, _title, _link, _width) {
	if (_width == undefined)
		_width= MENU_BODY_WIDTH;
	M[(M.length)]= new Array (_image, _size, _title, _link, new Array (), _width, _over);
}

function appendItem (_title, _link) {

	M[(M.length - 1)][4][( M[(M.length - 1)][4].length )]= new Array (true, _title, _link);
}

function appendSeparator () {
	M[(M.length - 1)][4][( M[(M.length - 1)][4].length )]= new Array (false);
}

///////////////////////////////////////////////////////////

function deployMenuHeaders () {

	for (i= 0; i < M.length; i++) {

		// preloadImages (M[i][1]); // onmouseover="this.src=\'' + M[i][1] + '\'" onmouseout="this.src=\'' + M[i][0] + '\'"

		document.write ('<a href="' + M[i][3] + '" target="_top">' +
			'<img src="' + M[i][0] + '" alt="' + M[i][2] + '" ' +
			(
				(M[i][4].length > 0) ?
					(
					'onmouseover="ShowMenu(this, ' + i + ');" ' +
					'onmouseout="HideMenu(' + i + ');" '
					)
					: ''
			) +
			'border="0" height="29" width="' + M[i][1] + '"></a>');
	}

}

function deployMenuBodies () {

	for (i= 0; i < M.length; i++) {

		if (M[i][4].length <= 0)
			continue;

		output= '<div style="opacity: 1; left: 15px; top: 95px; visibility: hidden; width: ' + M[i][5] + '" class="menu" id="_MENU_' + i + '" onmouseover="HoldMenu();" onmouseout="HideMenu(' + i + ');">';

		for (j= 0; j < M[i][4].length; j++) {
			
			if (M[i][4][j][0])
				output+= '<div class="menurow" onmouseover="focusMenuRow (this);" onmouseout="blurMenuRow (this)" onclick="document.location=\'' + M[i][4][j][2] + '\'"><b><a href="' + M[i][4][j][2] + '" target="_top" class="nav2">' + M[i][4][j][1] + '</a></b></div>';
			else
				output+= '<div class="menurow" style="padding-top: 0; padding-bottom: 0; background-image: url(img/spc.gif)"><img src="img/spc.gif" width="1" height="5" border="0" /></div>';
		}
		
		output+= '</div>';

		document.write (output);

	}

}

///////////////////////////////////////////////////////////

function focusMenuRow (someThis) {
	someThis.style.backgroundColor= '#B0B9BB';
}

function blurMenuRow (someOtherThis) {
	someOtherThis.style.backgroundColor = '#000000';
}

///////////////////////////////////////////////////////////


var currentParent;
var currentMenu;
var menuToHide;
var fadestep;
var cleared = true;
var browserdetect;

function Pos (thisitem) {

	if (typeof (thisitem) != 'object')
		thisitem = document.getElementById (thisitem);

	var ww = thisitem.offsetWidth, hh = thisitem.offsetHeight;

	for (var xx = 0, yy = 0; thisitem != null; xx += thisitem.offsetLeft, yy += thisitem.offsetTop, thisitem = thisitem.offsetParent);
	
	return {Left:xx, Top:yy, Right:xx + ww, Bottom:yy + hh}
}


function ShowMenu (thisitem, menu) {

	if (typeof (menu) != 'object')
		menu = "_MENU_" + menu;

	cleared = false;
	currentParent = thisitem;

	if (typeof (menu) != 'object') {
		menu = document.getElementById (menu);
	}

	if (currentMenu == menu) {

		if (!cleared)
			clearInterval (fadestep);

		currentMenu = null;

	} else if (currentMenu != null) {

		InstantHide (currentMenu);

		if (!cleared) clearInterval (fadestep);
		currentMenu = null;
	}

	currentMenu = menu;

	currentMenu.style.left = Pos(currentParent).Right - currentMenu.offsetWidth + 8;
	currentMenu.style.top = Pos(currentParent).Bottom;
	currentMenu.style.visibility = 'visible';

	browserdetect= menu.filters? "ie" : typeof (menu.style.MozOpacity) == "string" ? "mz" : "";

	if (browserdetect == "ie")
		currentMenu.filters.alpha.opacity = MENU_OPACITY;

	else if (browserdetect == "mz")
		currentMenu.style.MozOpacity = MENU_OPACITY / 100 * MENU_MOZ_TO_IE_OPACITY_RATIO;
}


function HoldMenu () {

	ShowMenu (currentParent, currentMenu);
}


function HideMenu (hideMenu) {

	if (typeof (hideMenu) != 'object')
		hideMenu = "_MENU_" + hideMenu;

	if (typeof(hideMenu) != 'object') {
		hideMenu = document.getElementById (hideMenu);
	}

	if (menuToHide != hideMenu && menuToHide != null) {
		InstantHide (menuToHide);
	}

	menuToHide = hideMenu;
	FadeMenu ();
}

function FadeMenu () {

	fadestep= setInterval ("FadeLevel()",25);
}

function FadeLevel () {

	if (browserdetect == "ie")
		menuToHide.filters.alpha.opacity= Math.floor (menuToHide.filters.alpha.opacity * MENU_FADE_STEP);

	else if (browserdetect == "mz")
		menuToHide.style.MozOpacity= Math.floor (menuToHide.style.MozOpacity * MENU_FADE_STEP * 100) / 100;

	else
		menuToHide.style.visibility = 'hidden';
		
	if ((menuToHide.style.MozOpacity <= 0.0) || (menuToHide.filters.alpha.opacity <= 0)) {

		InstantHide (menuToHide);
		menuToHide = null;
	}
}

function InstantHide (iHideMenu) {

	clearInterval (fadestep);
	cleared= true;
	iHideMenu.style.visibility = 'hidden';
}