///////////////////////////////
// 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;
rollOffSubMenuDelayTimer = null;
columnWidth = 140;
contentwidth = 960;
contentheight = 540;
timeoutdelay = 500;
subMenuParentX = new Array( 0, 2, 2, 2, 2, 2, 2 );
subMenuParentY = new Array( 0, 1, 2, 3, 4, 5, 6 );



///////////////////////////////
// Funktioner                //
///////////////////////////////
function getElement( ID ) {
	return W3C ? document.getElementById( ID ) :
	       IE4 ? document.all[ID] : false;
}

///////////////////////////////
// Togglefunktioner          //
///////////////////////////////

function rollOnMenu( menuID ) {
	clearTimeout( rollOffMenuDelayTimer );
	for( i = 1; i <= menuColumnCount; i++ )
		toggleMenu( i, i == menuID, false );
	//luk submenu
	closeSubMenu( openSubMenu );
	openMenu = menuID;
}

function rollOnSubMenu( subMenuID ) {
	clearTimeout( rollOffSubMenuDelayTimer );
	for( i = 1; i <= subMenuColumnCount; i++ )
		toggleMenu( i, i == subMenuID, true );
	openSubMenu = subMenuID;
}

function hoverOnMenu() {
	clearTimeout( rollOffMenuDelayTimer );
}

function hoverOnSubMenu() {
	clearTimeout( rollOffMenuDelayTimer );
	clearTimeout( rollOffSubMenuDelayTimer );
}

function rollOffMenu() {
	rollOffMenuDelayTimer = setTimeout( "closeMenu(" + openMenu + ")", timeoutdelay );
}

function rollOffSubMenu() {
	rollOffMenuDelayTimer = setTimeout( "closeMenu(" + openMenu + ")", timeoutdelay );
	rollOffSubMenuDelayTimer = setTimeout( "closeSubMenu(" + openSubMenu + ");", timeoutdelay );
}

function rollOffSubMenuHead() {
	rollOffSubMenuDelayTimer = setTimeout( "closeSubMenu(" + openSubMenu + ");", timeoutdelay );
}

function closeMenu( menuID ) {
	clearTimeout( rollOffMenuDelayTimer );
	toggleMenu( menuID, false );
}

function closeSubMenu( menuID ) {
	clearTimeout( rollOffSubMenuDelayTimer );
	toggleMenu( menuID, false, true );
}

//////////////////////////////////////////////////


function toggleMenu( menuID, status, submenu ) {
	
	var menu = getElement( (submenu?"submenu":"menu") + menuID );
	var menufrm = getElement( (submenu?"submenu":"menu") + menuID + "frm" );
	
	if ( menu != null && menufrm != null ) {
		
		menufrm.style.width = menu.offsetWidth;
		menufrm.style.height = menu.offsetHeight;
		
		if ( submenu ) {
			menu.style.left = calcXCoordinate(subMenuParentX[menuID]-1)+145;
			menu.style.top = calcYCoordinate(subMenuParentX[menuID]-1)+((subMenuParentY[menuID]-1)*20)+0;
		} else {
			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 highlight( element, state ) {
	element.className = (state?"innermenuhover":"innermenu");
}

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 = 540;
	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)*150) -25;
}

function calcYCoordinate( menuID ) {
	return Math.floor((getYExcessSpace())/2)+45+(hasVerticalScrollbar()?16/2:0);
}

function hasVerticalScrollbar() {
	
	maxXsize = 960;
	windowXsize = 0;
	if ( window.innerWidth ) 
		windowXsize = window.innerWidth;
	else if( document.body && document.body.clientWidth )
		windowXsize = document.body.clientWidth;
	return ( windowXsize < maxXsize );
}

function hasHorisontalScrollbar() {
	
	maxYsize = 540;
	windowYsize = 0;
	if ( window.innerHeight )
		windowYsize = window.innerHeight;
	else if( document.body && document.body.clientHeight )
		windowYsize = document.body.clientHeight;
		
	return ( windowYsize < maxYsize );
}

//////////////////////////////////////////////////
// indsæt browser specifikke externe menuer her //
//////////////////////////////////////////////////

innermenulink = "innermenu";
innermenulinkhover = "innermenuhover";
document.write( "<script type='text/javascript' src='/script/menuitems.js' language='JavaScript'></script>" );
