/*the menu uses 2 layers for each button. The visible layers which holds the button. An initially invisible layer which hold the submenu of each button.
The initially visible layer is called 'closed' while the layer with the submenu is called 'open' or 'innerbuttons'.
When the button is clicked the submenu becomes visible and positioned according to the corresponding button. All other buttons are repositioned.*/
//browserdetection
var nn4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var dom = (document.getElementById)? true:false;
var ns6 = (document.getElementById && !document.all)? true:false;

//Number of buttons in the menu, ADD ONE TO THE TOTAL, E.G. IF THERE ARE 8 BUTTONS, THIS VARIABLE SHOULD HOLD THE VALUE 9!!!!
var numberOfButtons=0;
//height of each button plus the amount of spaces UNDERNEATH the button (currently buttonheight @13 px and 3 px space underneath the button)
var factor=19;

// internal: check if theres defined a submenu in html
function hasSubMenu(i){
	
	return typeof(eval('document.all.button'+i+'_open')) != 'undefined'
	
}

function changeUrl(whichUrl) {
	parent.location.href=whichUrl;
}

//initially sets the number of buttons in the menu
function setNumberOfButtons(theNumber) {
	numberOfButtons = theNumber + 1;
}

function resetLayerTops() {
	//where the first button starts
	var startingPoint = 85;
	var leftStart = xsPos("middleofpage");
	leftStart-=151;
	arrowLeft = leftStart + 120;
	//reset all layers to their starting position
	var i = 1
	for(i=1;i<numberOfButtons;i++){  
		
		eval('document.all.button'+i+'_closed.style.left='+leftStart);		
		eval('document.all.button'+i+'_closed.style.top='+startingPoint);
		eval('document.all.button'+i+'_closed.style.visibility="visible"');

		if (hasSubMenu(i)) {
			setArrow(i);
			eval('document.all.button'+i+'_open.style.left='+leftStart);
			eval('document.all.button'+i+'_open.style.top='+startingPoint);
			eval('document.all.arrowSpan'+i+'.style.left='+arrowLeft);
			eval('document.all.arrowSpan'+i+'.style.top='+startingPoint);
			eval('document.all.arrowSpan'+i+'.style.visibility="visible"');	
		}
		//alert(startingPoint);
		startingPoint+=19;
		
		
	}
	
	
}
//only used for productfrontpage and simular pages
function OLDdoFrontMenu(numberOfInnerButtons) {
	var leftStart = xsPos("middleofpage");
	leftStart-=151;
	temp = 300;
	eval('document.all.buttomOfMenu.style.top='+temp);
	/*eval('document.all.buttomOfMenu.style.top='+heightOfLayer);
	eval('document.all.button1_open.style.left='+leftStart);
	//document.button1_open.visibility = "visible";*/
	//alert('asdf');
}

//Receives the number of the button clicked. Sets the corresponding innerlayer to visible
function setLayerOpen(number, numberOfInnerButtons) {
	changeArrow(number);
	//reset all layertops
	resetLayerTops();
	//call hideOpenLayers which assures that all inner (open) layers are set to hidden before setting the current one to visible
	hideOpenLayers();
	//call moveOtherLayers that moves the rest of the buttons
	moveOtherLayers(number, numberOfInnerButtons);
	//show the innerbuttons of the button clicked
	if(nn4) {
		eval('document.layers.button'+number+'_open.visibility="visible"');		
	}
	else if(ie4) {
		eval('document.all.button'+number+'_open.style.visibility="visible"');
	}
	else {
		eval('document.getElementById("button'+number+'_open").style.visibility="visible"');
	}
}

//Hides all open layers
function hideOpenLayers() {
	for(i=1;i<numberOfButtons;i++) {
		
		if (hasSubMenu(i)) {
			if(nn4) {
				eval('document.layers.button'+i+'_open.visibility="hidden"');
			}
			else if(ie4) {
				eval('document.all.button'+i+'_open.style.visibility="hidden"');
			}
			else {
				eval('document.getElementById("button'+i+'_open").style.visibility="hidden"');
			}
		}
	}
	
}

//function that move the rest of the buttons the same height as the sum of the innerbuttons of the layer just set visible. 
//This according to the predefined factor (which is the height of each button plus space)
function moveOtherLayers(number, numberOfInnerButtons) {
	
	innerButtons = parseInt(numberOfInnerButtons);
	number = parseInt(number);
	//start with the next button. The current button should not be moved
	number+=1;
	//alert(number);
	//cycle through the remaining buttons
	for(i=number;i<numberOfButtons;i++) {
		if(nn4) {
			layerTop =  parseInt(eval('document.layers.button'+i+'_closed.top'));
			newLayerTop = (factor*innerButtons)+layerTop;
			eval('document.layers.button'+i+'_closed.top='+newLayerTop);
		}
		else if(ie4) {
			layerTop =  parseInt(eval('document.all.button'+i+'_closed.style.top'));
			newLayerTop = (factor*innerButtons)+layerTop;
			eval('document.all.button'+i+'_closed.style.top='+newLayerTop);
			eval('document.all.arrowSpan'+i+'.style.top='+newLayerTop);
		}
		else {
			layerTop = parseInt(eval('document.getElementById("button'+i+'_closed").style.top'));
			//alert(layerTop);
			newLayerTop = factor*innerButtons+layerTop;
			//alert(newLayerTop);
			eval('document.getElementById("button'+i+'_closed").style.top='+newLayerTop);
		}
	}
	//subtrack one from the number so we have the button clicked
	number-=1;
	//move the corresponding innerbuttons
	if(nn4) {
		layerTop =  parseInt(eval('document.layers.button'+number+'_closed.top'));
		newTopForClosed = layerTop+20;
		eval('document.layers.button'+number+'_open.top='+newTopForClosed);
	}
	else if(ie4) {
		layerTop =  parseInt(eval('document.all.button'+number+'_closed.style.top'));
		newTopForClosed = layerTop+20;
		eval('document.all.button'+number+'_open.style.top='+newTopForClosed);
	}
	else {
		layerTop =  parseInt(eval('document.getElementById("button'+number+'_closed").style.top'));
		//alert(layerTop);
		newTopForClosed = layerTop+20;
		//alert(newTopForClosed);
		eval('document.getElementById("button'+number+'_open").style.top='+newTopForClosed);
	}
	
	//alert('newtop = ' + newTopForClosed);
}

function over(value){
			value.children(0).className = "over"
		}
		function out(value)	{
			value.children(0).className = "off"
		}
		function down(value){
			value.children(0).className = "hit"
		}
function setArrow(i) {
	

		ref="arrowid";
		ref2="document.all.arrowSpan";
		ref+=i;
		ref2+=i;
		ref2+=".style";
		//arrowGifYPos=ysPos("arrowid1");
		arrowGifYPos=eval('ysPos("'+ref+'")');
		arrowGifXPos=eval('xsPos("'+ref+'")');
		arrowGifXPos-=10;
		arrowGifYPos-=3;
		eval(ref2+'.left = '+arrowGifXPos);
		eval(ref2+'.top = '+arrowGifYPos);

}

function setSquares(howMany) {
	howMamy++;
	for(i=1;i<howMany;i++) {
		ref="innerarrowid";
		ref2="document.all.squareSpan";
		ref+=i;
		ref2+=i;
		ref2+=".style";
		//arrowGifYPos=ysPos("arrowid1");
		arrowGifYPos=eval('ysPos("'+ref+'")');
		arrowGifXPos=eval('xsPos("'+ref+'")');
		eval(ref2+'.left = '+arrowGifXPos);
		eval(ref2+'.top = '+arrowGifYPos);
	}
}

function changeArrow(which) {			
	for(i=1;i<=numberOfButtons;i++) {
		if(hasSubMenu(i)){
			eval('document.all.spanArrow'+i+'.src = arrowUp.src');
		}
	}
	eval('document.all.spanArrow'+which+'.src = arrowDown.src');
}

