// Preload our Collapsed and Expanded Menu Icon images
menu_collapsed = new Image();
menu_collapsed.src = 'bilder/help/open.gif';
menu_collapsed_hover = new Image();
menu_collapsed_hover.src = 'bilder/help/open_hover.gif';
menu_collapsed.alt = '�ppna';
menu_expanded = new Image();
menu_expanded.src = 'bilder/help/close.gif';
menu_expanded_hover = new Image();
menu_expanded_hover.src = 'bilder/help/close_hover.gif';
menu_expanded.alt = 'st�ng';

link_color = "rgb(0, 0, 0)";
hover_color = "rgb(30, 30, 30)";

// All according to http://devnull.tagsoup.com/fixed/vertical.html
// See extra CSS property for IE browsers when a 'div' is encountered with class 'content'
// in function collapseAllMenus()
function setIEFixedWindowStyle(){
	if(bw.ie){
		// document.body.style.overflow = "hidden";
		;
	}
}


// Derivate from browsercheck
function displayBrowser(){
	alert("version : " + bw.ver + "\n" +
		"agent : " + bw.agent + "\n" +
		"dom : " + bw.dom + "\n" +
		"opera5 : " + bw.opera5  + "\n" +
		"opera6 : " + bw.opera6  + "\n" +
		"opera7 : " + bw.opera7  + "\n" +
		"ie5 : " + bw.ie5  + "\n" +
		"ie6 : " + bw.ie6  + "\n" +
		"ie4 : " + bw.ie4  + "\n" +
		"ie : " + bw.ie  + "\n" +
		"mac : " + bw.mac  + "\n" +
		"ns6 : " + bw.ns6  + "\n" +
		"ns4 : " + bw.ns4  + "\n" +
		"bw : " + bw.bw);
}

// Browsercheck (needed)
function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.opera6=this.agent.indexOf("Opera 6")>-1
	this.opera7=this.agent.indexOf("Opera 7")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5)?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

// This function collapses all the menus when the page loads. (The page
// initially loads with menu expanded so that those with JS disabled
// can still use them.)
function collapseAllMenus() {
	//displayBrowser();
	//setBackgroundImage();
	//setIEFixedWindowStyle();

  	if (document.getElementsByTagName) {
    	div_nodes = document.getElementsByTagName("div");
    	for (i = 0; i < div_nodes.length; i++) {
      		div_node = div_nodes[i];
      		id_attr = div_node.getAttribute("id");
	      	//browsercheck
	      	if (bw.ie) {
	        	class_attr = div_node.className;
	      	}
	      	else{
		  		class_attr = div_node.getAttribute("class");
		  	}
	      	if (id_attr && class_attr && (id_attr.indexOf("beskr") != -1) && (class_attr == "beskr")) {
	        	div_node.style.display = "none";
	      	}
	      	// fix for IE browsers
	      	// All according to http://devnull.tagsoup.com/fixed/vertical.html
			// Extra CSS property for IE browsers when a 'div' is encountered with class 'content'
	      	/*if (class_attr && bw.ie && class_attr == "content") {
	        	div_node.style.height = "100%";
	        	div_node.style.overflow = "auto";
	      	}*/
	    }
	    for (i = 0; i < document.images.length; i++) {
	      	if (document.images[i].src.indexOf("close.gif") != -1) {
	        	document.images[i].src = menu_collapsed.src;
	      	}
		}
  	}
}

// This is the code for expanding and collapsing individual divs.
// This toggles the div we want to expand or collapse from display:block
// to display:none and back again depending on its current state
function toggleMenuDisplay(menu_in) {
  	if (document.getElementById) {
    	menu_id = document.getElementById(menu_in);
    	if ((menu_id.style.display == "block") || (menu_id.style.display == null)) {
      		menu_id.style.display = "none";
    	}
    	else {
    		menu_id.style.display = "block";
    	}
  	}
}

// This toggles the icon for the menu we want to collapse or expand from
// the collapsed icon to the expanded icon depending on current state
// Also dictates the alt text
function toggleMenuIcon(icon) {
  	if (document.getElementById) {
    	var icon_id = document.getElementById(icon);
    	if (icon_id.src.indexOf("close.gif") != -1) {
      		icon_id.src = menu_collapsed.src;
      		icon_id.alt = menu_collapsed.alt;
    	}
    	else if (icon_id.src.indexOf("close_hover.gif") != -1) {
      		icon_id.src = menu_collapsed_hover.src;
      		icon_id.alt = menu_collapsed.alt;
    	}
    	else {
    		icon_id.src = menu_expanded_hover.src;
    		icon_id.alt = menu_expanded.alt;
    	}
  	}
}

// This toggles the hover icon for the menu we want to collapse or expand
// This toggles the color of the link on
function toggleHoverIconOver(icon, link_in) {
  	if (document.getElementById) {
  		icon_node = icon;
  		icon_id_attr = icon_node.getAttribute("id");
    	icon_in = document.getElementById(icon_id_attr);
    	link_in_node = link_in;
    	//link is expanded, mouse is coming over
    	if (icon_in.src.indexOf("close.gif") != -1) {
      		icon_in.src = menu_expanded_hover.src;
      		link_in_node.style.color = hover_color;
    	}
    	//link is collapsed, mouse is coming over
    	else if (icon_in.src.indexOf("open.gif") != -1){
    		icon_in.src = menu_collapsed_hover.src;
    		link_in.style.color = hover_color;
    	}
    	//link is expanded, mouse is coming over
    	else if (icon_in.src.indexOf("close_hover.gif") != -1) {
      		icon_in.src = menu_expanded.src;
      		link_in_node.style.color = hover_color;
    	}
    	//link is collapsed, mouse is coming over
    	else if (icon_in.src.indexOf("open_hover.gif") != -1){
    		icon_in.src = menu_collapsed.src;
    		link_in.style.color = hover_color;
    	}
  	}
}

// This toggles the hover icon for the menu we want to collapse or expand
// This toggles the color of the link off
function toggleHoverIconOut(icon, link_in) {
  	if (document.getElementById) {
  		icon_node = icon;
  		icon_id_attr = icon_node.getAttribute("id");
    	icon_in = document.getElementById(icon_id_attr);
    	link_in_node = link_in;
    	//link is expanded, mouse is going out
    	if (icon_in.src.indexOf("close.gif") != -1) {
      		icon_in.src = menu_expanded_hover.src;
      		link_in_node.style.color = hover_color;
    	}
    	//link is collapsed, mouse is going out
    	else if (icon_in.src.indexOf("open.gif") != -1){
    		icon_in.src = menu_collapsed_hover.src;
    		link_in.style.color = link_color;
    	}
    	//link is expanded, mouse is going out
    	else if (icon_in.src.indexOf("close_hover.gif") != -1) {
      		icon_in.src = menu_expanded.src;
      		link_in_node.style.color = hover_color;
    	}
    	//link is collapsed, mouse is going out
    	else if (icon_in.src.indexOf("open_hover.gif") != -1){
    		icon_in.src = menu_collapsed.src;
    		link_in.style.color = link_color;
    	}
  	}
}

// Takes the icon id and figures out the id of the link to be shown
function toggleMenu(icon) {
  	icon_node = icon;
  	icon_id_attr = icon_node.getAttribute("id");
  	menu_id_attr = icon_id_attr + "-beskr";
  	toggleMenuDisplay(menu_id_attr);
  	toggleMenuIcon(icon_id_attr);
}

if(bw.bw) onload = collapseAllMenus;



