// ========================== My Submenus ============================
var sub_borderWidth       = 1;
var sub_boderColor        = 'white';
var sub_menuBackColor     = 'black';
var sub_menuHilightColor  = 'green';
var old_menu			  = '';
var old_menu_bk			= old_menu;

function writeSubMenu(name, x, y, w, className, subItems)
{
  document.write('<div style="display:none;position:absolute;padding-left:' + x + 'px;top:' + y + 'px;z-index:2" id="' + name + '">');
  document.write('<sc' + 'ript>var ' + name + 'menuIn=false;</scr' + 'ipt>');

	document.write('<table style="border-style:solid;border-width:' + sub_borderWidth + ';border-color:' + sub_boderColor + '" cellspacing=0  cellpadding=0><tr onMouseOut="menuOut(\'' + name + '\');"><td>');	  
			
  document.write('<table class="' + className + '" border=0 cellspacing=0 cellpadding=5 style="');
	if (w > 0)
		document.write('width:' + w +'px;');
		
	document.write('background-color:' + sub_menuBackColor + ';">');
  
  for (var i=0; i < subItems.length / 2; i++)
  {
    document.write('<tr onClick="hideElement(\'' + name + '\');' + subItems[i * 2] +'" onMouseOver="' + name + 'menuIn=true;this.style.backgroundColor=\'' + sub_menuHilightColor + '\'" onMouseOut="' + name + 'menuIn=false;this.style.backgroundColor=\'\'">' + 
                   '<td style="white-space:nowrap;"><a href="#" class="' + className + '" onClick="hideElement(\'' + name + '\',1);' + subItems[i * 2] +'">' + subItems[i * 2+1] + '</a></td></tr>');
  }   

  document.write('</table></td></tr></table></div>');
}

function menuOut(name)
{
	if (old_menu == name)
	{		
		old_menu='';
		setTimeout("if (!" + name + "menuIn) { hideElement('" + name + "', 2) } else { old_menu='" + name + "'}", 200);	
	}
}

function hideMenu()
{
  if (old_menu_bk != '')
    hideElement(old_menu_bk);

  old_menu_bk = '';
}

function showMenu(nDiv)
{
  if (old_menu_bk != nDiv && old_menu_bk != '')
		hideElement(old_menu_bk);

  showElement(nDiv);
  setTableCellsBk(nDiv);

  old_menu = nDiv;
	old_menu_bk = nDiv;
}

function setTableCellsBk(nDiv)
{
  oDiv = document.getElementById(nDiv);
  oRows = oDiv.getElementsByTagName("tr");

  for (i=1; i < oRows.length; i++)  // skip first row  
    oRows[i].style.backgroundColor = sub_menuBackColor;    
}

function hideElement(nDiv, doDelay)
{
	oDiv = document.getElementById(nDiv);

	if (nDiv == old_menu)
	{
		if ((typeof(doDelay) != "undefined") && (doDelay > 0))
		{		
			if (typeof(hideID) != "undefined")
				clearTimeout(hideID);

			if (doDelay == 1)
			{
				hideID = setTimeout("hideElement('" + nDiv + "', 0);", 500);				
				return oDiv;
			}

			doDelay = 0;
		}
	}

	// Don't close if we opened the menu back again last time
	if ((typeof(doDelay) != "undefined") && (doDelay == 0))
	{
		if (old_menu == nDiv)
			return oDiv;
	}

	if (old_menu == nDiv)
		old_menu = '';

  oDiv = document.getElementById(nDiv);
	if (oDiv != null)
		oDiv.style.display = 'none';

  return oDiv;
}

function showElement(nDiv)
{	
  oDiv = document.getElementById(nDiv);

	if (oDiv != null)
		oDiv.style.display = 'inline';

  return oDiv;
}

function showZoom(nDiv, nPic, nSrc)
{
  oPic = document.getElementById(nPic);
  oPic.src = nSrc;

	max = window.innerWidth;
	if (typeof(max) == "undefined")
	{
		oRows = document.getElementsByTagName("body");	
		oRects = oRows[0].getClientRects();

		
		max = 0;
		for (i=0; i < oRects.length; i++)
		{
			if (oRects[i].right > max)
				max = oRects[i].right;
		}
	}
	

  showElement(nDiv).style.width = max;
  
  return false;
}