// Globals

var UserAgent   = navigator.userAgent.toLowerCase();
var g_bIsOpera  = UserAgent.indexOf('opera') != -1;
var g_bIsSafari = UserAgent.indexOf('safari') != -1;
var g_bIsKonq   = UserAgent.indexOf('konqueror') != -1;
var g_bIsKHTML  = (g_bIsKonq || g_bIsSafari || UserAgent.indexOf('khtml') != -1);
var g_bIsIE     = (!g_bIsKHTML && !g_bIsOpera && (UserAgent.indexOf('msie 5') != -1 || UserAgent.indexOf('msie 6') != -1 || UserAgent.indexOf('msie 7') != -1));
var g_bIsGecko  = UserAgent.indexOf('gecko/') != -1;
var g_bActivateMenusEffect = false;


function SetLayout()
{
	try {
		document.getElementById('MainContent').style.width = (document.body.clientWidth - 190) + 'px';
		var iHeight = (g_bIsGecko) ? document.documentElement.scrollHeight : document.body.scrollHeight;
		document.getElementById('SideBar').style.height = (iHeight) + 'px';
	}
	catch(e){}
}

try {
	onresize = function() {
		SetLayout();
	} 
}
catch(e){}

/**
* Sets inner menu: X,Y location in the page, visibility, styles.
*
* @param    objParentMenu  (object)   The top menu element.
* @param    sInnerID       (string)   ID of the inner menu DIV container.
* @param    bDisplay       (boolean)  true if the menu should be displayed, false is used to set its location.
* @return                  (void)
*/
function setInnerMenu(objParentMenu, sInnerID, bDisplay)
{
	try {
		var objInnerMenuDiv = document.getElementById(sInnerID);
		var y = parseInt(objParentMenu.offsetLeft);
		var x = parseInt(objParentMenu.scrollHeight) + parseInt(document.getElementById('MainMenu').offsetTop);
		var iWidth  = '160';//(g_bIsIE) ? parseInt(objParentMenu.clientWidth) : parseInt(objParentMenu.scrollWidth);

		objInnerMenuDiv.style.top  = x + 'px';
		objInnerMenuDiv.style.left = y + 'px';
		
		
		objInnerMenuDiv.style.width = iWidth + 'px';
/*
		objUL = objInnerMenuDiv.getElementsByTagName('ul')[0];
		objUL.style.width = (iWidth + 5) + 'px';
*/

		objLinks = objInnerMenuDiv.getElementsByTagName('li');
		for(var i=0,iTotal=objLinks.length;i<iTotal;i++) {
			objLinks[i].style.width = (iWidth) + 'px';
			objLinks[i].style.display = 'block';
			//objLinks[i].firstChild.style.display = 'block';
		}

		if(bDisplay) {
			DisplayMenu(sInnerID);
		}
		else {
			// Just place the inner menus without display (during the OnLoad event).
			objInnerMenuDiv.style.visibility = 'hidden';
		}
	}
	catch(e){}
}

/**
* Sets the displayed menu: visibility, styles & opacity.
*
* @param    sMenuID (string)   The ID of the menu container.
* @return           (void)
*/
function DisplayMenu(sMenuID)
{
	try {
		if (g_bActivateMenusEffect && !g_bIsKonq && !g_bIsIE) {
			var objInnerMenuDiv = document.getElementById(sMenuID);
			objInnerMenuDiv.style.opacity = 0.33;

			objInnerMenuDiv.style.visibility = 'visible';
			for (var i=0; i<50; i++) {
				setTimeout("document.getElementById('"+sMenuID+"').style.opacity = "+(0.39 + (i/100))+";",200);
			}
		}
		else {
			document.getElementById(sMenuID).style.opacity = 0.80;
			objInnerMenuDiv.style.visibility = 'visible';	
		}
	}
	catch(e){}
}

/**
* Actions that will happen during menu activation / deactivation
*
* @param    sMenuID  (string)   The ID of the menu container.
* @param    bDisplay (boolean)   true/false menu should be displayed.
* @return            (void)
*/
function MenuActivation(sMenuID, bDisplay)
{
	try {
		var sMenuParentID = sMenuID.replace(/subMenuContainer_/,'MenuItem_');
		var objMenuParent = document.getElementById(sMenuParentID);
		var objMenu       = document.getElementById(sMenuID);
		
		objMenu.style.visibility = (bDisplay ? 'visible' : 'hidden');
		//objMenuParent.className = 'TopMenuCell' + (bDisplay ? '_Active' : '');
		SetTopMenuBG(objMenuParent,bDisplay);

	}
	catch(e){}
}

function SetTopMenuBG(objMenu, bDisplay)
{
	try {
		objMenu.className = 'TopMenuCell' + (bDisplay ? '_Active' : '');
	}
	catch(e){}		
}

/**
* Actions that will happen durin menu activation / deactivation
*
* @param    sMenuID  (string)   The ID of the menu container.
* @param    bDisplay (boolean)   true/false menu should be displayed.
* @return            (void)
*/
function MenuLinkActivation(objMenuItem, bDisplay)
{
	try {

		objMenuItem.className = 'SubMenuItem' + (bDisplay ? '_Active' : '');
		if (g_bIsIE) {
			objMenuItem.getElementsByTagName('a')[0].className = 'SubMenuItemLink' + (bDisplay ? '_Active' : '');
			objMenuItem.getElementsByTagName('a')[0].style.width = '100%';
		}

	}
	catch(e){}
}
