
function PML_XPos()
{
// Determines the left (x) position of the popups
	var lObj = coElementId("MenuPopupAnchor");
	var lX= 0;
	while (lObj.offsetParent)
	{
		lX += lObj.offsetLeft;
		lObj = lObj.offsetParent;
	};
	return lX + 1;
}

function PopMenuItemObj()
{
	this.Div = null;
	this.Img = null;
	this.ImgHigh = null;
	this.Popup = null;
	this.Color = null;
	this.BColor = null;
	this.over = function(pDiv,pColor,pBColor,pPopup,pPlacement,pImg,pImgHigh)
		{
			this.out(); // The previous one
			this.Div = pDiv;
			this.Img = pImg;
			this.ImgHigh = pImgHigh;
			this.Color = this.Div.style.color; // Save
			this.BColor = this.Div.style.backgroundColor;  // Save
			// Change image only when one is specified:
			if (this.Img != null) this.Img.style.display = "none";
			if (this.ImgHigh != null) this.ImgHigh.style.display = "";
			// Change color only when one is specified:
			if (pColor != null) this.Div.style.color = pColor;
			if (pBColor != null) this.Div.style.backgroundColor = pBColor;
			this.Popup = pPopup;
			if (pPopup == null) return;	
			this.showPopup(pPlacement);
		};
	this.out = function()
		{
			if (this.Div == null) return;
			this.Div.style.color = this.Color;
			this.Div.style.backgroundColor = this.BColor;
			if (this.ImgHigh != null) this.ImgHigh.style.display = "none";
			if (this.Img != null) this.Img.style.display = "";
			this.Div = null;
			this.Img = null;
			this.ImgHigh = null;
			this.hidePopup();
		};
	this.showPopup = function(pPlacement)
		// Positions and shows the popup of the id given. The x position is fixed and given by the stylesheet.
		{
			var lX = 0;		// Popup position relative to the top right corner
			var lY = 0;
			var lLeftDistance= 1;	// Distance between the divs
			var lTopDistance= 4;	// Distance between the divs
			//Determine position of the element and add the width:
			var lObj = this.Div;
			while (lObj.offsetParent)
			{
				lX += lObj.offsetLeft;
				lY += lObj.offsetTop;
				lObj = lObj.offsetParent;
			};
			if (pPlacement == 0) // 0 means to the left, currently reserved for left menu
			{
				var lBodyBottom = document.body.scrollTop + document.body.clientHeight;
				lX= PML_XPos();
				if ((lY + this.Popup.offsetHeight) >= lBodyBottom) lY = lBodyBottom - this.Popup.offsetHeight; //Correct top if on buttom
			} else if (pPlacement == 1)
			{ // 1 means bottom left
				lX = lX + this.Div.offsetWidth - 8;
				lY = lY + lTopDistance + this.Div.offsetHeight;
			} else if (pPlacement == 2)
			{ // 2 means bottom right
				lX = lX + this.Div.offsetWidth - this.Popup.offsetWidth;
				lY = lY + lTopDistance + this.Div.offsetHeight;
			};
			this.Popup.style.left = lX;
			this.Popup.style.top = lY;
			this.Popup.style.visibility = 'visible';
		};
	this.hidePopup = function()
		{
			if (this.Popup == null) return;
			this.Popup.style.visibility = 'hidden';
			this.Popup.style.top = 0;
			this.Popup = null;
		};
}

function PopObjectWithId(pId)
{
	if (pId == null) return null;
	return coElementId(pId); // Compatibility module
}

var PopMenuTimerId = 0; // The id of the timer, 0 is no timer active
var PopMenuItem = new PopMenuItemObj();
var PopMenuPopupItem = new PopMenuItemObj();

function PopMenuClear()
// Hides any current popup, and turns off any active timer.
{
	PopMenuStopTimer();
	PopMenuPopupItem.out();
	PopMenuItem.out();
}

function PopMenuStartTimer(pTime)
// Starts a timer which turns off the current popup on timeout.
{
	PopMenuTimerId  = setTimeout("PopMenuClear()", pTime);
}

function PopMenuStopTimer() {
// Stops any active timer for a popup.
	if (PopMenuTimerId != 0) {
		clearTimeout(PopMenuTimerId);
		PopMenuTimerId = 0;
	};
}



//////////////////////// Left Menu ////////////////////////


function PML_ItemOver(pDiv,pHiBColor,pPopupId,pImgId,pImgHighId)
{
	PopMenuStopTimer();
	PopMenuPopupItem.out();
	PopMenuItem.over(pDiv,"#FFFFFF",pHiBColor,PopObjectWithId(pPopupId),0,PopObjectWithId(pImgId),PopObjectWithId(pImgHighId));
}

function PML_ItemOut(pDiv)
{
	PopMenuStartTimer(500);
}

function PL_ItemOver(pDiv,pHiBColor)
{
	PopMenuStopTimer();
	PopMenuPopupItem.over(pDiv,"#FFFFFF",pHiBColor);
}

function PL_ItemOut(pDiv)
{
	PopMenuStartTimer(500);
}



//////////////////////// Top Menu ////////////////////////

function PMT_ItemOver(pPopupId,pPlacement)
{
	PopMenuStopTimer();
	PopMenuPopupItem.out();
	PopMenuItem.over(PopObjectWithId(pPopupId + "_ref"),null,null,PopObjectWithId(pPopupId),pPlacement);
}

function PMT_ItemOut()
{
	PopMenuStartTimer(500);
}

function PT_ItemOver(pDiv,pColor,pHiBColor)
{
	PopMenuStopTimer();
	PopMenuPopupItem.over(pDiv,pColor,pHiBColor);
}

function PT_ItemOut(pDiv)
{
	PopMenuStartTimer(500);
}

// On the top menu some items may be disabled. They are treated like the others because of timeout.

function PT_DisabledItemOver()
{
	PopMenuStopTimer();
	PopMenuPopupItem.out();
}

function PT_DisabledItemOut()
{
	PopMenuStartTimer(500);
}



//////////////////////// Location scroller ////////////////////////


// Constants, influence the behavior:
var LocScrInterval= 30;
var LocScrSlow= 2;
var LocScrFast= 7;


function LocScrElem(pName)
{
	this.Name= pName;
	this.Obj= coElementId(pName);
	this.setPos= function (pX,pY) {
			if (pX!=null) this.Obj.style.left= pX;
			if (pY!=null) this.Obj.style.top= pY;
		}
	this.displayable= function() {
			this.Obj.style.display= "";
		}
	this.show= function() {
			this.Obj.style.visibility= "visible";
		}
	this.hide= function() {
			this.Obj.style.visibility= "hidden";
		}
	this.height= function() {
			return this.Obj.offsetHeight;
		}
	this.width= function() {
			return this.Obj.offsetWidth;
		}
	this.top= function() {
			return this.Obj.offsetTop;
		}
}

function LocScrClass()
{
	this.isVisible= false;
	this.Cont= new LocScrElem("LocScrCont");
	this.Back= new LocScrElem("LocScrBack");
	this.TextCont= new LocScrElem("LocScrTextCont");
	this.Text= new LocScrElem("LocScrText");
	this.UpFast= new LocScrElem("LocScrUpFast");
	this.UpSlow= new LocScrElem("LocScrUpSlow");
	this.DownSlow= new LocScrElem("LocScrDownSlow");
	this.DownFast= new LocScrElem("LocScrDownFast");
	this.Placeholder= new LocScrElem("LocScrPlaceholder");

	this.TimerId= 0;
	this.NrOfPix= 0;
	this.YPos= 0;

	this.Text.displayable(); // Make text displayable

	this.Height= this.Back.height();
	this.TextHeight= this.Text.height();
	this.Range= this.TextHeight - this.Height + 4;
	if (this.Range < 0) this.Range= 0; // when smaller than field
	this.TopPos= this.Back.top() + 2;

	this.XNavPos= this.TextCont.width() + 13;

	if (this.Placeholder.Obj!=null) this.Placeholder.setPos(null,this.TextHeight);

	this.Back.setPos(null,this.TopPos);
	this.TextCont.setPos(10, 2);
	this.UpFast.setPos(this.XNavPos, 0);
	this.UpSlow.setPos(this.XNavPos, 18),
	this.DownSlow.setPos(this.XNavPos, this.Height - 38);
	this.DownFast.setPos(this.XNavPos, this.Height - 20);

	this.show= function() {
		this.Back.show();
		this.TextCont.show();
		this.UpFast.show();
		this.UpSlow.show();
		this.DownSlow.show();
		this.DownFast.show();
		this.Cont.show();
		this.isVisible= true;
	}
	this.hide= function() {
		this.Cont.hide();
		this.UpFast.hide();
		this.UpSlow.hide();
		this.DownSlow.hide();
		this.DownFast.hide();
		this.TextCont.hide();
		this.Back.hide();
		this.isVisible= false;
	}
	this.scroll= function(pNrOfPix) {
			if (pNrOfPix!=null) // when pNrOfPix is null the value already set is used
			{
				this.stopTimer();
				this.NrOfPix= pNrOfPix;
				if (this.NrOfPix==0) return;
			}
			// moving:
			this.YPos += this.NrOfPix;
			if (this.YPos > 0) this.YPos= 0;
			if (this.YPos < -this.Range) this.YPos= -this.Range;
			this.Text.setPos(null,this.YPos);
			this.startTimer(LocScrInterval,"LocScr.scroll()");
		}
	this.startTimer= function(pTime,pAction) {
		// Starts a timer which hides the scroller on timeout.
			if (this.TimerId!=0) clearTimeout(this.TimerId);
			if (pAction==null) pAction= "LocScr.hide()";
			this.TimerId= setTimeout(pAction, pTime);
		}
	this.stopTimer= function() {
		// Stops all timer activity.
			if (this.TimerId==0) return;
			clearTimeout(this.TimerId);
			this.TimerId = 0;
		}		
}

var LocScr;

function LocScrActivatorClicked(pRef)
// Activator is an object pRef, whose location is the reference.
{
	
	if (LocScr==null) LocScr= new LocScrClass();
	if (LocScr.isVisible)
	{
		LocScr.hide();
	} else {
		LocScr.show();
	};
}

function LocScrUpFastOver()
{
	LocScr.scroll(LocScrFast);
}

function LocScrUpFastOut()
{
	LocScr.scroll(0);
}

function LocScrUpSlowOver()
{
	LocScr.scroll(LocScrSlow);
}

function LocScrUpSlowOut()
{
	LocScr.scroll(0);
}

function LocScrDownSlowOver()
{
	LocScr.scroll(-LocScrSlow);
}

function LocScrDownSlowOut()
{
	LocScr.scroll(0);
}

function LocScrDownFastOver()
{
	LocScr.scroll(-LocScrFast);
}

function LocScrDownFastOut()
{
	LocScr.scroll(0);
}


var RolloverLink= null;
var RolloverLinkClassName= "";

function rolloverA(linkId) {
	if (RolloverLink == null) return;
	RolloverLink.className = RolloverLinkClassName;
	RolloverLink= null;
	RolloverLinkClassName= "";
}

function rolloverB(linkId) {
	RolloverLink = coElementId(linkId);
	RolloverLinkClassName = RolloverLink.className;
	RolloverLink.className = RolloverLinkClassName + "B";
}

function postionMenuLogo(){
	var mapLogo= coElementId("menu_map");
	var menuLogo= coElementId("menu_logo");
	var lX= 0;
	var lY= mapLogo.style.height;
	while (mapLogo.offsetParent)
	{
		lX += mapLogo.offsetLeft;
		lY += mapLogo.offsetTop;
		mapLogo = mapLogo.offsetParent;
	}
	menuLogo.style.top =  lY;
	menuLogo.style.left = lX;	
}
function displayMenuLogo(){
	var menuLogo= coElementId("menu_logo");
	menuLogo.style.display= "";
}