///////////////////////////////
// Kontroller Browser Type   //
///////////////////////////////
IE4 = !!document.all;
W3C = !!document.getElementById;

///////////////////////////////
// Cookie Control            //
///////////////////////////////
doccookies = document.cookie;

function getCookie(name) {
	var index = doccookies.indexOf(name + "=");
	if (index == -1) return null;
	
	index = doccookies.indexOf("=", index) + 1;
	var endstr = doccookies.indexOf(";", index);
	if (endstr == -1) endstr = doccookies.length;
	
	return unescape(doccookies.substring(index, endstr));
}

function setCookie(name, value) {
	if (value != null && value != "") {
		expiretime = new Date;
  	expiretime.setYear(expiretime.getYear()+1);
 
		document.cookie = ( name+"="+escape(value)+";expires="+expiretime.toGMTString() );
	}
	doccookies = document.cookie;
}

///////////////////////////////
// Variable                  //
///////////////////////////////
rollOffMenuDelayTimer = null;
columnWidth = 140;         //Denne variabel bliver ikke brugt længere.
columnDistance = 100;
contentwidth = 960;
contentheight = 640;

///////////////////////////////
// Funktioner                //
///////////////////////////////
function getElement( ID ) {
	return W3C ? document.getElementById( ID ) :
	       IE4 ? document.all[ID] : false;
}

function rollOnMenu( menuID ) {
	clearTimeout( rollOffMenuDelayTimer );
	for( i = 1; i <= menuColumnCount; i++ ) {
		toggleMenu( i, i == menuID );
	}
	openMenu = menuID;
}

function hoverOnMenu() {
	clearTimeout( rollOffMenuDelayTimer );
}

function rollOffMenu() {
	rollOffMenuDelayTimer = setTimeout( "closeMenu(" + openMenu + ")", 500 );
}

function closeMenu( menuID ) {
	clearTimeout( rollOffMenuDelayTimer );
	toggleMenu( menuID, false );
}

function toggleMenu( menuID, status ) {
	
	var menu = getElement( "menu" + menuID );
	//var menufrm = getElement( "menu" + menuID + "frm" );
	
	//menufrm.style.width = menu.offsetWidth;
	//menufrm.style.height = menu.offsetHeight;
	
	menu.style.left = calcXCoordinate(menuID-1);
	menu.style.top = calcYCoordinate(menuID-1);
	
	//menufrm.style.left = menu.offsetLeft;
	//menufrm.style.top = menu.offsetTop;
	
	
	//menufrm.style.visibility = ( status ? "visible" : "hidden" );
	menu.style.visibility = ( status ? "visible" : "hidden" );
	
}

function getXExcessSpace() {
	
	windowXsize = 960;
	if ( window.innerWidth ) 
		windowXsize = window.innerWidth;
	else if( document.body && document.body.clientWidth )
		windowXsize = document.body.clientWidth;
	
	return (windowXsize-contentwidth<40)?40:(windowXsize-contentwidth);
}

function getYExcessSpace() {
	
	windowYsize = 640;
	if ( window.innerHeight )
		windowYsize = window.innerHeight;
	else if( document.body && document.body.clientHeight )
		windowYsize = document.body.clientHeight;
	
	return (windowYsize-contentheight<40)?40:(windowYsize-contentheight);
}

function calcXCoordinate( menuID ) {
	return Math.floor(getXExcessSpace()/2)+(960-(menuColumnCount-menuID)*columnDistance);
}

function calcYCoordinate( menuID ) {
	return Math.floor((getYExcessSpace())/2)+38;
}

function hoverOnItem( item, hovering, statustext ) {
	item.className = ( hovering ? innermenulinkhover : innermenulink );
	if ( statustext != null )
		window.status = statustext
	else
		window.status = "Bollerup Jensens Sæbefabrik A/S";
		
	return true;
}
function hoverOnItemTop( statustext ) {
	if ( statustext != null )
		window.status = statustext
	else
		window.status = "Bollerup Jensens Sæbefabrik A/S";
		
	return true;
}
function noop()
{
	//javascript nothing routine der eksekveres når man trykker på et link i NS4 der ikke
	//skal gøre andet end at holde onmouseover eller onmouseout events, da den ikke kan
	//fatte mouseevents på <td> tags... SUCKS!
}

//////////////////////////////////////////////////
// indsæt browser specifikke externe menuer her //
//////////////////////////////////////////////////
if ( IE4 ) {
	innermenulink = "innermenu";
	innermenulinkhover = "innermenuhover";
	document.write( "<scr"+"ipt type='text/javascript' src='/script/ie4menu.js.asp' language='JavaScript'></scr"+"ipt>" );
} else {
	innermenulink = "innermenu";
	innermenulinkhover = "innermenuhover";
	document.write( "<scr"+"ipt type='text/javascript' src='/script/w3cmenu.js' language='JavaScript'></scr"+"ipt>" );
}

