
var timeoutInterval = 20;
var gapHandler = 0;

/* KGB: update for status display in headernavigation - 09/17/07 */
var	menuRootStatus = new Array();
menuRootStatus[0] = new Object();

var MSIE = ( document.all && !window.opera );

function openPopup(url) {
  myWin = window.open(url, 'popup', 'width=620,height=680,scrollbars=yes, toolbar=no,status=no, resizable=no,menubar=no,location=no,directories=no');
}

function playVideo(id, video, thumbnail, width, height) {
  document.write("<div>");
  document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='" + width + "' height='" + height + "' id='" + id + "_1' name='" + id + "_1'>");
  document.write("<param name='movie' value='http://www.cognis.com/player.swf'/>");
  document.write("<param name='allowfullscreen' value='true'/>");
  document.write("<param name='allowscriptaccess' value='always'/>");
  document.write("<param name='wmode' value='transparent'/>");
  document.write("<param name='flashvars' value='file=" + video + "&image=" + thumbnail + "'/>");
  document.write("<embed ");
  document.write("type='application/x-shockwave-flash' ");
  document.write("id='" + id + "_2' ");
  document.write("name='" + id + "_2' ");
  document.write("src='http://www.cognis.com/player.swf' ");
  document.write("width='" + width + "' ");
  document.write("height='" + height + "' ");
  document.write("bgcolor='undefined' ");
  document.write("allowscriptaccess='always' ");
  document.write("allowfullscreen='true' ");
  document.write("wmode='transparent' ");
  document.write("flashvars='file=" + video + "&image=" + thumbnail + "'/>");
  document.write("</object>");
  document.write("</div>");
}

function registerMenu(menuRoot, menuLayer) {
	/* KGB: update for status display in headernavigation - 09/17/07 */
	menuRootStatus[0][menuRoot.id] = menuRoot.className;
	
	menuRoot.setAttribute('menuLayer', menuLayer.id);
	menuLayer.setAttribute('menuRoot', menuRoot.id);
}

function openMenu(menuRoot) {
	var menuLayer = document.getElementById(menuRoot.getAttribute('menuLayer'));
	var process_id = menuRoot.getAttribute('process_id');

	dbgLog('openMenu(' + menuRoot.id + ')');
	if ( process_id ) {
		window.clearTimeout(process_id);
		menuRoot.setAttribute('process_id', 0);
	}
	menuLayer.style.top = (menuRoot.parentNode.offsetTop + menuRoot.parentNode.offsetHeight) + 'px';
	menuLayer.style.left = (menuRoot.parentNode.offsetLeft + menuRoot.offsetLeft) + 'px';
	menuLayer.className = 'headermenu_open';
	menuRoot.className = 'master active';
}

function startcloseMenu(menuRoot) {
	dbgLog('startcloseMenu(' + menuRoot.id + ')');
	menuRoot.setAttribute('process_id', window.setTimeout("closeMenu('" + menuRoot.id + "');", timeoutInterval));
}

function releaseMenuitem(menuItem) {
	var menuLayer;

	if ( menuItem.tagName == 'LI' ) {
		menuLayer = menuItem.parentNode;
	} else {
		menuLayer = menuItem;
	}

	dbgLog('releaseMenuitem(' + menuLayer.id + ')');

	var menuRoot = document.getElementById(menuLayer.getAttribute('menuRoot'));
	startcloseMenu(menuRoot);
}

function touchMenu(menuItem) {
	var menuLayer;

	if ( menuItem.tagName == 'LI' ) menuLayer = menuItem.parentNode;
	else menuLayer = menuItem;

	dbgLog('touchMenu(' + menuLayer.id + ')');

	var menuRoot = document.getElementById(menuLayer.getAttribute('menuRoot'));
	window.clearTimeout(menuRoot.getAttribute('process_id'));
	menuRoot.setAttribute('process_id', 0);
}

function closeMenu(menuRootID) {
	var menuRoot;
	var menuLayer = document.getElementById((menuRoot = document.getElementById(menuRootID)).getAttribute('menuLayer'));

	dbgLog('closeMenu(' + menuRootID + ')');

	menuRoot.setAttribute('process_id', 0);
	menuLayer.className = 'headermenu';

	/* KGB: update for status display in headernavigation - 09/17/07 */
	if( menuRootStatus[0][menuRoot.id] == 'master active' ) menuRoot.className = 'master active';
	else menuRoot.className = 'master';
}

function dbgLog(str) {
	var elem = document.getElementById('dbgLog');

	if ( elem ) {
		elem.innerHTML = str + '<br>' + elem.innerHTML;
	}
}

function dbgGap() {
	var elem = document.getElementById('dbgLog');

	if ( elem ) {
		if ( gapHandler == 0 ) gapHandler = window.setInterval('dbgGap()', 2000);
		elem.innerHTML = '<br>' + elem.innerHTML;
	}
}

