/* *************************************************************************
*
*  File: menu.js
*  Purpose: Dropdown menu functions
*
************************************************************************* */

/* *************************************************************************
*
*  Initialization
*
************************************************************************* */

var ns = 0;
var layerRef = "document.all";
var styleSwitch = ".style";

var ns4 = ((document.layers) ? true : false);
var ie4 = ((document.all && document.getElementById) ? true : false);
var ie45 = ((navigator.appVersion.indexOf ('MSIE 4.5; Mac') >- 1) ? true : false);

if (is_nav && !is_firefox)
{
	ns = 1;
	layerRef = "document.layers";
  	styleSwitch = "";
}

/* *************************************************************************
*
*  function showLayer (_objLayerName, _level, _objCaller, _objLayerParentID)
*
************************************************************************* */

function showLayer (_objLayerName, _level, _objCaller, _objLayerParentID)
{
	var objLayer = getObj (_objLayerName),
		objLayerParent = getObj (_objLayerParentID),
		posLeft = 0,
		posTop = 0;

	if (ns == 0)
	{
		if (_level > 1)
		{
			hideLayerSiblings (objLayer);
		}

		objLayer.style.display = 'block';
	}
	else
	{
		eval (layerRef + '["' + _objLayerName + '"]' + styleSwitch + '.display="block"');
	}

	if (_level != null && _objCaller != null)
	{
		if (_level == 1)
		{
			posLeft = getX (_objCaller) + 8;
			posTop = getY (_objCaller) + getHeight (_objCaller) - 1;

//			posLeft = ((posLeft > 0) ? posLeft : '200px');
//			posTop = ((posTop > 0) ? posTop : '37px');
		}
		else
		{
			posLeft = getX (objLayerParent) + ((getWidth (_objCaller) > 0) ? getWidth (_objCaller) : 155) + 2;
			posTop = getY (objLayerParent) + getHeight (objLayerParent) + ((_objCaller.offsetTop > 0) ? _objCaller.offsetTop : ((_objCaller.offsetParent.offsetTop > 0) ? _objCaller.offsetParent.offsetTop : calcOffsetTop (_objCaller.parentNode))) - 1;
//			posTop = getY (objLayerParent) + getHeight (objLayerParent) + calcOffsetTop (_objCaller.parentNode) - 1;

//			posLeft = ((posLeft > 0) ? posLeft : '350px');
//			posTop = ((posTop > 0) ? posTop : '55px');
		}

		if (posTop != 0 && posLeft != 0)
		{
			if (ns == 0)
			{
				objLayer.style.top = posTop + 'px';
				objLayer.style.left = posLeft + 'px';
			}
			else
			{
				eval (layerRef + '["' + _objLayerName + '"]' + styleSwitch + '.top="' + posTop + 'px"');
				eval (layerRef + '["' + _objLayerName + '"]' + styleSwitch + '.left="' + posLeft + 'px"');
			}
		}
	}
}

/* *************************************************************************
*
*  function hideLayer (_objLayerName)
*
************************************************************************* */

function hideLayer (_objLayerName)
{
	var objLayer = getObj (_objLayerName);

	objLayer.style.display = 'none';

	if (ns == 0)
	{
		objLayer.style.display = 'none';
	}
	else
	{
		eval (layerRef + '["' + _objLayerName + '"]' + styleSwitch + '.display="none"');
	}
}

/* *************************************************************************
*
*  function hideLayer (_obj)
*
************************************************************************* */

function hideLayerSiblings (_obj)
{
	var arrSiblings = new Array ();

	arrSiblings = getChildren (_obj.parentNode);

	for (var indexSiblings = 0; indexSiblings < arrSiblings.length; indexSiblings++)
	{
		arrSiblings[indexSiblings].style.display = 'none';
	}
}

/* *************************************************************************
*
*  function overImage (_imgSrc)
*
************************************************************************* */

function overImage (_imgSrc)
{
	_imgSrc.children.tags ('IMG')[0].src = _imgSrc.children.tags ('IMG')[0].src.replace ('.gif', 'r.gif');
}

/* *************************************************************************
*
*  function outImage (_imgSrc)
*
************************************************************************* */

function outImage (_imgSrc)
{
	_imgSrc.children.tags ('IMG')[0].src = _imgSrc.children.tags ('IMG')[0].src.replace ('r.gif', '.gif');
}

/* *************************************************************************
*
*  function overlImage (_imgSrc, _imgName)
*
************************************************************************* */

function overlImage (_imgSrc, _imgName)
{
	_imgSrc.children.tags ('IMG')[0].src = _imgSrc.children.tags ('IMG')[0].src.replace ('.gif', 'r.gif');
	document.images["cl"].src = '{IMG}model/detail/' + _imgName + '.gif';
}

/* *************************************************************************
*
*  function outlImage (_imgSrc, _imgName)
*
************************************************************************* */

function outlImage (_imgSrc, _imgName)
{
	_imgSrc.children.tags ('IMG')[0].src = _imgSrc.children.tags ('IMG')[0].src.replace ('r.gif', '.gif');
	document.images[name].src = '{IMG}spacer.gif';
}

/* *************************************************************************
*
*  function getRandomSplash (_objContainerID)
*
************************************************************************* */

function getRandomSplash (_objContainerID, _maxImg)
{
	var index = 0,
		objContainer = getObj (_objContainerID);

	index = Math.round (Math.random () * ((_maxImg != null) ? _maxImg : 1));
//	objContainer.src = imgSplashRoot + index + ".jpg";

	return index;
}

/* *************************************************************************
*
*  function getRandomBanner (_objContainerID, _maxImg)
*
************************************************************************* */

function getRandomBanner (_objContainerID, _maxImg)
{
	var index = 0,
		objContainer = getObj (_objContainerID);

	index = Math.round (Math.random () * ((_maxImg != null) ? _maxImg : 1));
//	objContainer.src = imgBannerRoot + index + ".swf";

	return index;
}

/* *************************************************************************
*
*  function blurMenu ()
*
************************************************************************* */

function blurMenu ()
{
/*	blur ();*/
}

/* *************************************************************************
*
*  function showCatalogImage (_objImgContainerID, _objImgTitleContainerID, _imgSrc, _imgName)
*
************************************************************************* */

function showCatalogImage (_objImgContainerID, _objImgTitleContainerID, _imgSrc, _imgName)
{
	var objImgContainer = getObj (_objImgContainerID),
		objImgTitleContainer = getObj (_objImgTitleContainerID);

	objImgContainer.src = _imgSrc;
	objImgContainer.alt = _imgName;
	objImgContainer.title = _imgName;

	objImgTitleContainer.innerHTML = _imgName;
}

/* *************************************************************************
*
*  function showCatalogDescription (_objDescriptionContainerID, _descTitle, _descText)
*
************************************************************************* */

function showCatalogDescription (_objDescriptionContainerID, _descTitle, _descText)
{
	var arrTexts = new Array (),
		objDescriptionContainer = getObj (_objDescriptionContainerID);

	arrTexts = getChildren (objDescriptionContainer);

	arrTexts[0].innerHTML = _descTitle;
	arrTexts[1].innerHTML = _descText;

	objDescriptionContainer.style.visibility = 'visible';
}

/* *************************************************************************
*
*  function hideCatalogDescription (_objDescriptionContainerID)
*
************************************************************************* */

function hideCatalogDescription (_objDescriptionContainerID)
{
	var arrTexts = new Array (),
		objDescriptionContainer = getObj (_objDescriptionContainerID);

	arrTexts = getChildren (objDescriptionContainer);

	arrTexts[0].innerHTML = '&nbsp;';
	arrTexts[1].innerHTML = '&nbsp;';

	objDescriptionContainer.style.visibility = 'hidden';
}

/* *************************************************************************
*
*  function showMovie (_objContainerID, _movieURL)
*
************************************************************************* */

function showMovie (_objContainerID, _movieURL)
{
	var objContainer = getObj (_objContainerID);

	if (ns4)
	{
		var lyr = document.layers[_objContainerID].document;

		lyr.open ();
		lyr.write ('<embed src="' + _movieURL + '" width="264" height="198" controller="true"></embed>');
		lyr.close ();
	}

	if (ie45)
	{
		window.open('vn_embed.jsp@path=' + _movieURL, 'windowName', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=200,left=122,top=234');
	}
	else if (ie4)
	{
		document.all[_objContainerID].innerHTML = '<embed src="' + _movieURL + '" width="264" height="198" controller="true"></embed>';
	}
}

/* *************************************************************************
*
*  function hidePreload (_objContainerID, _objContainerClassNameEmpty)
*
************************************************************************* */

function hidePreload (_objContainerID, _objContainerClassNameEmpty)
{
	var objContainer = getObj (_objContainerID);

	objContainer.className = replaceClassName (objContainer.className, _objContainerClassNameEmpty, '');
}

/* *************************************************************************
*
*  function setInitMap (_objImageContainerID, _objListContainerID)
*
************************************************************************* */

function setInitMap (_objImageContainerID, _objListContainerID)
{
	var arrMapItems = new Array (),
		objImageContainer = getObj (_objImageContainerID),
		objListContainer = getObj (_objListContainerID),
		imageX = 0,
		imageY = 0;

	arrMapItems = getChildren (objListContainer);

	imageX = getX (objImageContainer);
	imageY = getY (objImageContainer);

	for (var indexItems = 0; indexItems < arrMapItems.length; indexItems++)
	{
		arrMapItems[indexItems].style.left = getX (arrMapItems[indexItems]) + imageX + 'px';
		arrMapItems[indexItems].style.top = getY (arrMapItems[indexItems]) + imageY + (is_opera70 ? -10 : 0) + 'px';
	}
}

/* *************************************************************************
*
*  function showMapDescription (_objCallerID, _objContainerID, _objItemID)
*
************************************************************************* */

function showMapDescription (_objCallerID, _objContainerID, _objItemID)
{
	var objCaller = getObj (_objCallerID),
		objContainer = getObj (_objContainerID),
		objItem = getObj (_objItemID);

	objItem.style.display = 'block';
	objItem.style.left = getX (objCaller) + ((objCaller.className.indexOf ('itemAlternate') == -1) ? 15 : 0) + 'px';
	objItem.style.top = getY (objCaller) + getHeight (objCaller) + 3 + 'px';
	objCaller.className = addClassName (objCaller.className, 'itemHover');
}

/* *************************************************************************
*
*  function closeMapDescription (_objCallerID, _objItemID)
*
************************************************************************* */

function closeMapDescription (_objCallerID, _objItemID)
{
	var objCaller = getObj (_objCallerID),
		objItem = getObj (_objItemID);

	objItem.style.display = 'none';
	objCaller.className = replaceClassName (objCaller.className, 'itemHover', '');
}

/* *************************************************************************
*
*  function calcOffsetTop (_obj)
*
************************************************************************* */

function calcOffsetTop (_obj)
{
	var arrSiblings = new Array (),
		offsetTop = 0;

	arrSiblings = getChildren (_obj.parentNode);

	for (var indexSiblings = 0; indexSiblings < arrSiblings.length; indexSiblings++)
	{
		if (arrSiblings[indexSiblings] == _obj)
		{
			break;
		}
	}

//	offsetTop = indexSiblings * getHeight (_obj);
	offsetTop = indexSiblings * 15;

	return offsetTop;
}

/* *************************************************************************
*
*  function doInitMenu (_objMenuID)
*
************************************************************************* */

function doInitMenu (_objMenuID)
{
	var objMenu = getObj (_objMenuID);
	
	if (objMenu)
	{
		doParseMenu (objMenu);
	}
}

/* *************************************************************************
*
*  function doParseMenu (_objMenu)
*
************************************************************************* */

function doParseMenu (_objMenu)
{
	var arrItems = _objMenu.childNodes;
		
	for (var indexItems = 0; indexItems < arrItems.length; indexItems++)
	{
		if (arrItems [indexItems].tagName == 'LI')
		{
			arrItems [indexItems].onmouseover = function () 
			{ 
				doShowSubmenu (this, true); 
			}
			
			arrItems [indexItems].onmouseout = function () 
			{
				doShowSubmenu (this);
			}
		}
		
		for (var indexItemsSub = 0; indexItemsSub < arrItems [indexItems].childNodes.length; indexItemsSub++)
		{
			if (arrItems [indexItems].childNodes [indexItemsSub].tagName == 'UL')
			{
				arrItems [indexItems].childNodes [indexItemsSub].style.display = 'none';
				
				doParseMenu (arrItems [indexItems].childNodes [indexItemsSub]);
			}
		}
	}
}

/* *************************************************************************
*
*  function 
*
************************************************************************* */

function doShowSubmenu (_objItem, _display)
{
	var arrElements = _objItem.childNodes;
	
	for (var indexElements = 0; indexElements < arrElements.length; indexElements++)
	{
		if (arrElements [indexElements].tagName == 'UL')
		{
			arrElements [indexElements].style.display = _display ? '' : 'none';
			
			return false;
		}
	}
}