isDOM=document.getElementById; //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM; //Opera 5+
isOpera6=isOpera && window.print; //Opera 6+
isOpera7=isOpera && document.readyState; //Opera 7+
isMSIE=document.all && document.all.item && !isOpera; //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE; //MSIE 5+
isNetscape4=document.layers; //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape"; //Mozilla или Netscape 6.*

var scrWidth = 0;
var offLeft = 0;
var leftPadding, topPadding;
var activeMenu;
var linkDivActive;
var timeOnDiv;
var layerRef;
var styleRef;

var mouseX = 0, mouseY = 0;

if (document.all) // IE 4+
{
	layerRef = "document.all.";
	styleRef = ".style";
	leftPadding = 0;
	topPadding = 0;
}
else if (document.layers) // Netscape 4
{	
	layerRef = "document.layers['";
	styleRef = "']";
	leftPadding = 8;
	topPadding = 6;
}
else
{
	layerRef="document.getElementById('";
	styleRef="').style";
	leftPadding = 8;
	topPadding = 6;
}

setSize();
window.onresize = setSize;

if (isNetscape4) document.captureEvents(Event.MOUSEMOVE);

if (isMSIE || isOpera7)
{
  document.onmousemove = function() {
    mouseX = event.clientX + document.body.scrollLeft;
    mouseY = event.clientY + document.body.scrollTop;
    return true;
	}
}
else if (isOpera){
  document.onmousemove = function(){
    mouseX = event.clientX
    mouseY = event.clientY
    return true
  }
}
else if (isNetscape4 || isMozilla){
  document.onmousemove = function(e){
    mouseX = e.pageX
    mouseY = e.pageY
    return true
  }
}



// Функции для работы с меню и пр.
	
function setSize() {
	if(isMSIE) {				
		scrWidth = document.body.clientWidth;
	}
	else {	
		scrWidth = innerWidth;
	}

	if (scrWidth > 767) {
		offLeft = Math.round((scrWidth - 767) / 2) - leftPadding;
	}
	else {
		offLeft = 0;
	}
}

function changeProp(objName,theProp,theValue) { 	
	eval(layerRef+objName+styleRef+'.'+theProp+' = \''+theValue+'\'');
}

function getProp(objName,theProp) { 	
	return eval(layerRef+objName+styleRef+'.'+theProp);
}

function showLayer(name)
{
	changeProp(name,'visibility','visible');
}

function hideLayer(name)
{
	changeProp(name,'visibility','hidden');
}

function moveLayer(name, left, top)
{
	if (left != '') 
	{
		changeProp(name, 'left', left);
	}
	
	if (top != '')
	{
		changeProp(name, 'top', top);
	}
}

function showmLayer(id)
{	
	moveLayer(id, mouseX, mouseY);
	showLayer(id);
	
	return false;

}

function showaLayer(id)
{	
	moveLayer(id, mouseX, mouseY);
	showLayer(id);
}

function hideaLayer(id)
{
	hideLayer(id);
	
	return false;
}

function showMenu(id, offset)
{	
	if (id == '')
	{
		return false;
	}
	
	if ((timeOnDiv != null) && (activeMenu != ''))
	{
		clearTimeout(timeOnDiv);
		hideMenu();
	}
	
	activeMenu = id;
	menuName = 'menu' + activeMenu;

	moveLayer('menuPicker', offLeft + offset + 185, 3 + topPadding);
	moveLayer(menuName, offLeft + offset + 185, '');
	
	showLayer(menuName);
	showLayer('menuPicker');
	
	return false;
}

function menuTimer()
{
	timeOnDiv = setTimeout("hideMenu();", 1000);
}

function subMenuOver()
{	
	linkDivActive = 1;
	clearTimeout(timeOnDiv);
}

function subMenuOut()
{	
	linkDivActive = 0;
	timeOnDiv = setTimeout("if (linkDivActive == 0) { hideMenu(); }", 1000);
}

function hideMenu()
{
	if (activeMenu == '') {
		return false;
	}
	
	menuName = 'menu' + activeMenu;
	
	hideLayer(menuName);
	hideLayer('menuPicker');
	
	activeMenu = '';

	return false;
}

function changeMenuColor(newColor, id)
{
	menuName = 'subMenu' + id;
	
	if (isMSIE || isOpera5 || isMozilla)		
		changeProp(menuName,'backgroundColor', newColor);	
  else if (isNetscape4)
		changeProp(menuName,'bgColor', newColor);	

	return false;
}

function getMenuOver(id)
{
	return changeMenuColor('#F0F0F0', id);
}

function getMenuOut(id)
{
	return changeMenuColor('#FFFFFF', id);
}
