var menuLength = 3;
var menuItem = new Array();

// init image objects and assign properties
if (document.images)
{
var plusImg = new Image;
var minusImg = new Image;
plusImg.src = "img/struktur/plus.gif"
plusImg.alt = "Utvidde"
minusImg.src = "img/struktur/minus.gif"
minusImg.alt = "Lukke"
}

// test for cookie and set if missing or
// fill menuItem array with current values
if (!cookieVal('menuCookie')) 
{
	for (var i=0; i<menuLength; i++)
	{
		menuItem[i] = 0;
	}	
	document.cookie = "menuCookie="+menuItem.join(',')+";;path=/";
}
else
{
	var cookieData = cookieVal('menuCookie');
	menuItem = cookieData.split(',');
}

// set menus on load
function loadMenu()
{
	for(var i=0; i<menuLength; i++)
	{
		if (document.getElementById)
		{
			var thisMenu = document.getElementById('menu'+i).style;
			if(menuItem[i] == 0)
			{
				thisMenu.display = "none";
				document['menu'+i+'Img'].src = plusImg.src
				document['menu'+i+'Img'].alt = plusImg.alt
			} 
			else 
			{
				thisMenu.display = "block";
				document['menu'+i+'Img'].src = minusImg.src
				document['menu'+i+'Img'].alt = minusImg.alt
			}
		}
	}
}

// expand all
function expandAll()
{
	for(var i=0; i<menuLength; i++)
	{
		if (document.getElementById)
		{
			var thisMenu = document.getElementById('menu'+i).style;
			thisMenu.display = "block";
			document['menu'+i+'Img'].src = minusImg.src
			document['menu'+i+'Img'].alt = minusImg.alt
			menuItem[i] = 1;
		}
	}
	document.cookie = "menuCookie="+menuItem.join(',')+";;path=/";
	return false;
}

// collapse all
function collapseAll()
{
	for(var i=0; i<menuLength; i++)
	{
		if (document.getElementById)
		{
			var thisMenu = document.getElementById('menu'+i).style;
			thisMenu.display = "none";
			document['menu'+i+'Img'].src = plusImg.src
			document['menu'+i+'Img'].alt = plusImg.alt
			menuItem[i] = 0;
		}
	}
	document.cookie = "menuCookie="+menuItem.join(',')+";;path=/";
	return false;
}

// toggle menu and images, set cookie
function toggleMenu(currMenu,menuIndex)
{
	if (document.getElementById)
	{
		var thisMenu = document.getElementById(currMenu).style;
		if(thisMenu.display == "block")
		{
			menuItem[menuIndex] = 0;
			thisMenu.display = "none";
			document[currMenu+'Img'].src = plusImg.src
			document[currMenu+'Img'].alt = plusImg.alt
		} 
		else 
		{
			menuItem[menuIndex] = 1;
			thisMenu.display = "block";
			document[currMenu+'Img'].src = minusImg.src
			document[currMenu+'Img'].alt = minusImg.alt
		}
		document.cookie = "menuCookie="+menuItem.join(',')+";;path=/";
		return false;
	}
	else 
	{
		document.cookie = "menuCookie="+menuItem.join(',')+";;path=/";
		return true;
	}
}

// Global variables
var cookieName, firstVisit;
var now = new Date;
var expireDate = new Date;
expireDate.setYear(expireDate.getYear()+5); // 5 year cookie span

// Comment form
// Grab refering URL as cookie
var refURL
function commentsForm(){
	document.cookie = "refTitle=" + escape(document.title) + ";;path=/";
	document.cookie = "refURL=" + escape(document.location.href) + ";;path=/";
}
//end of addition

// Returns the value of a cookie
function cookieVal(cookieName) 
{
	thisCookie = document.cookie.split("; ");
	for (i=0; i<thisCookie.length; i++) 
	{
		if (cookieName == thisCookie[i].split("=")[0])
		{
			return thisCookie[i].split("=")[1];
		}
	}
	return 0;
}

// Delete cookie function
function deleteCookie(cookieName) 
{
	var now = new Date;
	// set the expiration date to today
	var expireDate = new Date;
	// set the expiration date to one day in the past
	expireDate.setDate(expireDate.getDate()-1);
	// write the expired cookie to delelte it
	document.cookie = cookieName+"=;expires=" + expireDate.toGMTString();	
}

// toggle content hidebox
function toggleHideBox(boxID)
{
	if (document.getElementById)
	{
		var thisHideBox = document.getElementById(boxID).style;
		if(thisHideBox.display == "block")
		{
			thisHideBox.display = "none";
		} 
		else 
		{
			thisHideBox.display = "block";
		}
		return false;
	}
	else 
	{
		return true;
	}
}
//transcriptwindow
function newTransWindow(linkref){
	transWindow = window.open(linkref,'transWin', 'width=580,height=300, scrollbars=yes');
}

