function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// Reverses the ul - makes it go up instead of down
// This is done by stacking the list-items on top of eachother by assigning an increasing style-top-value to every li.
// Takes an ul as argument
function make_drop_up(target)
{
	//target = $(target);
	Element.cleanWhitespace(target);	// Get rid of whitespace (from prototype)
	list_items = target.childNodes;		// get all list-items = the childnodes from the ul (target)
	
	target.style.top = "-22px";			// Move the whole ul above the parent li
	target.style.left = "0";			// And align it to the left
	
	// li measurements
	li_height 		= 16;		// height of li. This has to be the same as in the css
	
	// Below values are mutliplied with 2 = top and bottom
	// This has to be the same as in the css
	
	li_margin_vert	= 0 * 2;	// margin
	li_padding_vert = 3 * 2;	// padding
	li_border_vert	= 1 * 2;	// border
	
	li_box_model_height = li_height + li_margin_vert + li_padding_vert + li_border_vert -1; // Total height (-1 to avoid double borders between list-items)
	li_box_model_height = li_box_model_height.toString();									// convert numbers to a string
	
	// Loop list-items
	for(i=0;i<list_items.length;i++)
	{
		list_items[i].style.position 	= 'absolute';			// Set position to absolute
		top_value = '-' + i * li_box_model_height + 'px';		// make it negative, multiply the li-height with the current li number, and add 'px' at the end
		//alert(top_value);
		list_items[i].style.top = top_value;					// Assign the above calculated top value
	}
}

// This is a fix so that ie/win displays hidden blocks on mouseover
// Normally this is done by css (li:hover ul) but to achieve this is ie we need to assign and remove a temporary classname on mouseover and hide it on mouseout
function add_fix_for_ie(sub_list_lis)
{
	if (!document.all || !document.getElementById) return false; // return false if other browser than ie/win (object detection, no stinking browser sniffing)
	
	sub_list_lis = sub_lists[i].getElementsByTagName('li');	// Get all list-items
	for(j=0;j<sub_list_lis.length;j++)						// And loop them
	{
		Element.cleanWhitespace(sub_list_lis[j]); 			// Get rid of whitespace (from prototype)
		
		// Add classnames on mouseover and mouseout if the li has at least one ul-child (first child (0) is <a>)
		if (sub_list_lis[j].childNodes[1] && sub_list_lis[j].childNodes[1].nodeName == 'UL')
		{
			sub_list_lis[j].onmouseover = function() { this.className = "over"; }
			sub_list_lis[j].onmouseout = function() { this.className = ""; }
		}
	}
}

// Parent function that takes use of the make_drop_up- and add_fix_for_ie-functions
function modify_list()
{	
	menu_holder = document.getElementById("menu");	// Get the parent div for all menus
	Element.cleanWhitespace(menu_holder);			// Get rid of whitespace (from prototype)
	
	parent_list = menu_holder.firstChild;				// This is the first level menu
	
	sub_lists = parent_list.getElementsByTagName('ul');	// and these are the sublists
	
	// Loop all sublists
	for(i=0;i<sub_lists.length;i++)
	{
		Element.cleanWhitespace(sub_lists[i]);						// Get rid of whitespace (from prototype)
		
		// If parent node has a classname of 'dir_active' - this is the one to work on
		if (sub_lists[i].parentNode.className == "dir_active")	 
		{	
			add_fix_for_ie(sub_lists[i].getElementsByTagName('li'));	// Apply function for ie
			
			level2_ul = sub_lists[i];								// Get Level 2-lists (hidden if not the current page)
			level3_uls = level2_ul.getElementsByTagName('ul');		// Get level 3-lists (hidden by default)
			
			// Loop level 3-lists
			for(j=0;j<level3_uls.length;j++)
				make_drop_up(level3_uls[j])		// And make them drop-ups instead of drop-downs
		}	
	}
}

function set_logo_top_border()
{	
	document.getElementById('logo').className = 'black_top_border';
	
	if (document.getElementById('left_pic') && document.getElementById('left_pic').height == 275)
		document.getElementById('logo').className = 'white_top_border';
}

addLoadEvent(modify_list);
addLoadEvent(set_logo_top_border);