
// **************************** Rollover kod *********************************

var pageRollOvers = [];
var rollOverCounter = 0;
var skipnav_counter=1;

/**
 * Called by document.onLoad to create the rollover objects
 * Createing a rollover object cause it's on image to be
 * preloaded
 * 
 * @param rollOverArray - an array of rollovers records in the form:
 *		  [0] = the name/id of the image object as is in the img tag
 *		  [1] = the off rollover image href
 *	      [2] = the on rollover image href
 */
function createRollOvers(rollOverArray)
{
	for (var i=0; i<rollOverArray.length; i++)
		addRollOver(new RollOver(rollOverArray[i][0], rollOverArray[i][1], rollOverArray[i][2]));
}
/** 
 * helper for createRollOvers
 */
function addRollOver(rollOver){  pageRollOvers[rollOverCounter++] = rollOver;}


/**
 * used by the anchor tags onMouseOver and onMouseOut calls
 * to retrieve the RollOver object that you can call rollOn()
 * or rollOff on
 *
 * @param rolloverName - the name/id of the img href associate
 * 	      with a rollover
 *
 * @return a RollOver object
 */
function getRollOver(rollOverName)
{
	for (var i=0; i<rollOverCounter; i++)
	{
		if (pageRollOvers[i].imageObject == rollOverName)
			return pageRollOvers[i];
	}
	return null;
}

/**
 * RollOver object, a simple object that can toggle
 * the src of an ImageObject
 * 
 * @param imgObject - the name/id of the image as it
 *		  appears in the img tag
 * @param offImageSrc - the href of the off state image
 * @param onImageSrc - the href of the on state image
 */
function RollOver(imgObject, offImageSrc, onImageSrc)
{
	//preload rollover images
	this.preLoadOnImg     = new Image();
	this.preLoadOnImg.src = onImageSrc;

	//object properties	
	this.imageObject = imgObject;
	this.offImageSrc = offImageSrc;
	this.onImageSrc  = onImageSrc;

	//object methods	
	this.rollOn = RollOver_rollOn;
	this.rollOff = RollOver_rollOff;
}

function RollOver_rollOn(){  var img =  DOMGetElement(this.imageObject); if (img)img.src=this.onImageSrc;}
function RollOver_rollOff(){ var img =  DOMGetElement(this.imageObject); if (img)img.src=this.offImageSrc;}


// ******************************* Menykod *********************************

/**
 * Menu Data Structures
 *
 *  Menu Record
 * [0] = arbitrary, unique, identifier of the menu state.  This 
 *	     determines which menu element is "active" and which sub
 *		 menus are displayed
 * [1] = OPTIONAL(if this is a text menu): Image name and id as 
 *		 designated in the img tag
 * [2] = OPTIONAL(if this is a text menu): image width
 * [3] = OPTIONAL(if this is a text menu): image height
 * [4] = OPTIONAL(if this is a text menu): href to the image 
 *		 minus the naming convention extensions such as '_dn'
 * 		 and the file type.  The default menu printing functions 
 *		 will create RollOver obejcts according to the '_dn' & '_ro'
 *		 naming convention.  All menu graphics are assumed to be gifs.
 * [5] = The 'alt' value of an img tag if this is a graphic menu or the 
 *		 menu text if this is a text menu
 * [6] = The link for this menu option to link to 
 * [7] = OPTIONAL: An array of nested menu elements.  This is used to create
 *       a single level of nesting on the left nav but it could
 *       be used to create create tree menus of arbitrary depth		 
 */

/**
 * Menu Object, prints out a menu based on the above menu data structure.
 * The menus were done in an object oriented way to maximize flexibility
 * and reusability of functions.  LeftNavMenu modifies the behavior
 * of Menu by using a different printMenuOption method
 * 
 * @param inMenuOptions = an array of menu options.  Each array 
 *		  element is a 7 element list as outlined above 
 * @param choice = an indicator of the current page.  The 
 *        choice will be compared against the first element
 * 		  of each menu option record.
 * @returns an initialized menu object that can print a menu
 */
function Menu(inMenuOptions, choice)
{
	//Object Properties
	this.menuOptions  = inMenuOptions
	this.choice       = choice;
	
	//Object Functions
	this.print           	= Menu_Print;
	this.printMenuOption    = Menu_PrintMenuOption;
	this.optionSelected  	= Menu_optionSelected;
}

/**
 * Used by menu objects to loop over an array of menu 
 * option arrays...to loop over each menu choice and 
 * have a replaceable helper function print out the 
 * menu line item.  A helper function does the printing
 * so that the object can switch out the function to 
 * print differet types of menus
 */
function Menu_Print()
{
	document.write('<span><a href=\"#skip_group_'+ skipnav_counter + '\" title=\"skip navigation links\"> </a></span>');
	for (var i=0; i<this.menuOptions.length; i++)
	{
		this.printMenuOption(this.menuOptions[i], this.choice1);
	}
	document.write('<span><a name=\"skip_group_'+ skipnav_counter +'\"> </a></span>');

	skipnav_counter++;
}

/**
 * Seaches a menuOption and it's sub menus (contained in an 
 * array in item [7], for a menu option that has matches
 * this objects currently selected option.  The function 
 * is recursive and work for an menu structure of 
 * arbitrary depth.
 *
 * @param the record to search fro this.choice
 */
function Menu_optionSelected(menuOption)
{
	
	if (menuOption[0] == this.choice)
		return true;
	else if (menuOption[7]!=null)
		for (var i=0; i<menuOption[7].length; i++)
			if (this.optionSelected(menuOption[7][i]))
				return true;
	return false;
}

/**
 * This method is designed to print out each
 * option in a graphical horizontal menu
 */
function Menu_PrintMenuOption(menuOption)
{	
	if (this.optionSelected(menuOption))
	{
		if (NS4)
		{
			document.write('<td><a href="'+menuOption[6]+'">');
			document.write('<img src="'+menuOption[4]+'_ro.gif" width="'+menuOption[2]+'" height="'+menuOption[3]+'" border="0" name="' + menuOption[1] + '" id="' + menuOption[1] + '" alt="'+ menuOption[5]+'"></a></td>');
		}
		else
		{
		document.write('<td><a href="' + menuOption[6] +'" onMouseOver="'+menuOption[1]+'_am.hideSubMenu(); '+menuOption[1]+'_am.show(); '+menuOption[1]+'_am.activeColor(); selectHide();" onMouseOut="'+menuOption[1]+'_am.menubar.startTimer(); '+menuOption[1]+'_am.normalColor(); selectShow();">');
		document.write('<img src="'+menuOption[4]+'_ro.gif" width="'+menuOption[2]+'" height="'+menuOption[3]+'" border="0" name="' + menuOption[1] + '" id="' + menuOption[1] + '" alt="'+ menuOption[5]+'"></a></td>');
		}
	}
	else
	{
		if (NS4)
		{
			addRollOver(new RollOver(menuOption[1], menuOption[4]+'.gif', menuOption[4]+'_ro.gif'));
			document.write('<td><a href="'+menuOption[6]+'" onMouseOut="getRollOver(\'' + menuOption[1] + '\').rollOff(); selectShow();" onMouseOver="getRollOver(\'' + menuOption[1] + '\').rollOn(); selectHide();">');
			document.write('<img src="'+menuOption[4]+'.gif" width="'+menuOption[2]+'" height="'+menuOption[3]+'" border="0" name="' + menuOption[1] + '" id="' + menuOption[1] + '" alt="'+ menuOption[5]+'"></a></td>');
		}
		else
		{	
		addRollOver(new RollOver(menuOption[1], menuOption[4]+'.gif', menuOption[4]+'_ro.gif'));

		document.write('<td><a href="' + menuOption[6] +'" onMouseOut="getRollOver(\'' + menuOption[1] + '\').rollOff(); '+menuOption[1]+'_am.menubar.startTimer(); '+menuOption[1]+'_am.normalColor(); selectShow();" onMouseOver="getRollOver(\'' + menuOption[1] + '\').rollOn(); '+menuOption[1]+'_am.hideSubMenu(); '+menuOption[1]+'_am.show(); '+menuOption[1]+'_am.activeColor(); selectHide();">');
		document.write('<img src="'+menuOption[4]+'.gif" width="'+menuOption[2]+'" height="'+menuOption[3]+'" border="0" name="' + menuOption[1] + '" id="' + menuOption[1] + '" alt="'+ menuOption[5]+'"></a></td>');
		}
	}
}

/** 
 * A specialization of the Menu object that replaces
 * the printmenuOptions method with one that is 
 * designed to print out a vertical text based menu
 * 
 * @param inMenuOptions = an array of menu options.  Eacy array 
 *		  element is a 7 element list as outlined above 
 * @param choice = an indicator of the current page.  The 
 *        choice will be compared against the first element
 * 		  of each menu option record.
 * @returns an initialized menu object that can print a menu
 */
function LeftNavMenu(inMenuOptions, choice)
{
	//data
	this.menuOptions  = inMenuOptions
	this.choice       = choice;
	
	//functions
	this.print           = Menu_Print;
	this.optionSelected     = Menu_optionSelected;
	this.printMenuOption    = LeftNavMenu_printMenuOption;
	this.printSubOptions = LeftNavMenu_printSubOptions;

}

/*
 * Vertikal sidomeny - nivå 1 del
 *
 */
function LeftNavMenu_printMenuOption(menuOption)
{
	
	if (this.optionSelected(menuOption))
	{
		if (menuOption[7])
		{
			document.write('<tr><td valign="top" width="8%"><img src="../img/menu/navtree_arrow_active.gif" width="11" height="11"></td><td class="copy-navtree" width="92%"><a href="'+menuOption[6]+'" class="copy-navtree-on">'+menuOption[5]+'</a></td></tr>');
			document.write('<tr><td>&nbsp;</td><td><table border=0 cellspacing=0 cellpadding=0>');
			this.printSubOptions(menuOption);
			document.write('</table></td></tr>');
		}
		else
		{
			document.write('<tr><td valign="top" width="8%"><img src="../img/menu/navtree_mark_active.gif" width="11" height="11"></td><td class="copy-navtree" width="92%"><a href="'+menuOption[6]+'" class="copy-navtree-on">'+menuOption[5]+'</a></td></tr>');
		}
	}
	else
	{
		if (menuOption[7] == "") //= "" istället för konstanten "undefined" var buggat på mac!!!
		{
			document.write('<tr><td valign="top" width="8%"><img src="../img/menu/navtree_mark.gif" width="11" height="11"></td>');
			document.write('<td class="copy-navtree" width="92%"><a href="'+menuOption[6]+'" class="copy-navtree">'+menuOption[5]+'</a></td></tr>');
		}
		else
		{
			document.write('<tr><td valign="top" width="8%"><img src="../img/menu/navtree_arrow.gif" width="11" height="11"></td>');
			document.write('<td class="copy-navtree" width="92%"><a href="'+menuOption[6]+'" class="copy-navtree">'+menuOption[5]+'</a></td></tr>');
		}

	}   
}

/*
 * Vertikal sidomeny - nivå 2 del
 *
 */
 
function LeftNavMenu_printSubOptions(menuOption)
{
	for (var i=0; i<menuOption[7].length; i++)
	{
		if (this.optionSelected(menuOption[7][i]))
		{
			// vald
			document.write('<tr><td class="copy-navtree-on" valign="top" width="12%"><img src="../img/menu/navtree_mark_active.gif" width="11" height="11"></td>');
			document.write('<td class="copy-navtree-on" valign="middle" width="88%"><a href="'+menuOption[7][i][6]+'" class="copy-navtree-on">'+menuOption[7][i][5]+'</a></td></tr>');
		}
		else
		{
			// ej vald
			document.write('<tr><td class="copy-navtree" width="12%" valign="top"><img src="../img/menu/navtree_mark.gif" width="11" height="11"></td>');
			document.write('<td class="copy-navtree" width="88%"><a href="'+menuOption[7][i][6]+'" class="copy-navtree">'+menuOption[7][i][5]+'</a></td></tr>');
		}
	}
}
//This will bury error messages so the users cannot see them

window.onerror = null;

/**
 * Menu printing functions. 
 * Call each function where the menu should be printed out.
 * the identifier of the current page should be passed into the call
 *
 * The data that drives the menus and sets up the page identifiers
 * should b passed in in the menu_data.js file
 */

function printMenuLevel1(currentPage){new Menu(levelMenuOptionsArray, currentPage).print();}
function printMenuLevel2(currentPage){new Menu(levelMenuOptionsArray, currentPage).print();}

function printMenuLevel3(currentPage)
{
	new LeftNavMenu(level3MenuOptionsArray, currentPage).print();
}





