//	global variables
var W3CDOM = (document.createElement && document.getElementsByTagName) ;
var resolution = "low" ;
var normalColor = "#1E2E6E" ; 		//	multibyggs blue
var highlightColor = "#D40026" ; 	//	multibyggs red
var et_toggleElements = [] ;    	//  initialize a global, empty array
var leaderPicCurr ;

//
//
function loadStylesheet()
{
  var b = document.getElementById("highResolutionStyles") ;

	if( !b ) return ;	//	break off processing

	if ( screen.height >= 1024 )  //  high resolution
  {
    //	b.setAttribute( "href", "_css/screenstyles_highresolution3.css" ) ;
		//	resolution = "high" ;
  }

} //  end of *loadStylesheet*


//
//
function init()
{
	var bodyClass = document.getElementById("www-multibygg-no").className ;

	if( !bodyClass ) return ;	//	break off processing/initializing

	//alert( "bodyClass: " + bodyClass ) ;

	//	initialize homepage *index.html*
	if( bodyClass == "index" ) initHomepage() ;
	//	initialize *referanse_prosjekter.html*
	else if( bodyClass == "referanse-prosjekter" ) initReferanseProsjekter() ;				//	OBS: plural
	//	initialize ...
	else if( bodyClass == "referanse-prosjekt" ) initReferanseProsjekt() ;			//	OBS: singular
	//	initialize *ledelse.html*
	else if( bodyClass == "ledelse" ) initLedelse() ;
	//	initialize *stikkord.html*
	else if( bodyClass == "stikkord" ) initStikkord() ;
	//	initialize *tjenester_og_produkter.html*
	else if( bodyClass == "tjenester" ) initTjenester() ;
	//	initialize *stillinger.html*
	else if( bodyClass == "stillinger" ) initStillinger() ;
	//	initialize *telefonliste.html*
	else if( bodyClass == 'telefonliste' ) initTelefonliste() ;
	//
	else if( bodyClass == 'historie' ) initHistorie() ;
	//
	else if( bodyClass == 'nokkelinfo' )  initNoekkelInfo() ;

	//	initialize #linkToTop
	initTopLink() ;

} //  end of *init()*

//	The onload event of the window object fires after all content and processes coded in the HTML
//	have finished loading and self-initializing.
window.onload = function ()
{
	if( !W3CDOM ) return ;

  loadStylesheet() ;
  init() ;
}

// ###################


//
//	initialize #linkToTop
function initTopLink()
{
	var topLink = document.getElementById( 'linkToTop' ) ;
	var header = document.getElementById( 'Header' ) ;
	if ( !topLink || !header ) return  ; 	//	break off processing / avbryt

	var header = document.getElementById( 'Header' ) ;
	if( !header ) return true ; 		//	break off processing / avbryt

	topLink.onclick = gotoHeader ;

}	//	end of *initTopLink*

//	...
function gotoHeader(e)
{
	var header = document.getElementById( 'Header' ) ;
	if( !header ) return true ; 		//	break off processing / avbryt

	header.scrollIntoView( true ) ;	//	IE-DOM !!!
	return false ;

}	//	end of *gotoHeader*


//
//	initialize index.html
function initHomepage()
{  return ;  }


//
//  init historie.html
function initHistorie()
{  initLinkOmsetning() ;  }


//
//  init nokkelinfo.html
function initNoekkelInfo()
{  initLinkOmsetning() ;  }


//
//	initialize referanse_prosjekter.html
function initReferanseProsjekter()
{
	var refProjectLinkClass = "ref-project-link" ;

	var mainContent = document.getElementById( 'mainContent' ) ;
	if( mainContent )
	{
		var myLinks = mainContent.getElementsByTagName('a') ;
		for ( var j=0, length=myLinks.length; j<length; j++ )
		{
			if ( myLinks[j].className == refProjectLinkClass )
			{
				//  binding handlers to objects
				myLinks[j].onmouseover = mouseGoesOverReferanceLink ;
				myLinks[j].onfocus = mouseGoesOverReferanceLink ;
				//
				myLinks[j].onmouseout = mouseLeavesReferanceLink ;
				myLinks[j].onblur = mouseLeavesReferanceLink ;
			}
		}	//	end for-loop
	}

}	//	end of *initReferanseProsjekter*


//
//	*initialize* a page for a specific reference project
function initReferanseProsjekt()
{
	var pictureBox = document.getElementById('pictureBoxLeft') ;

	if( pictureBox )
	{
		var pictures = pictureBox.getElementsByTagName('img') ;
		for ( var j=0, length=pictures.length; j<length; j++ )
		{
			//  binding handlers to objects
			pictures[j].onclick = clickOnReferencePicture ;
		}	//	end of for-loop
	}

	//	hide the big photo (when existing) - it acts as a placeholder
	var bigPhoto = document.getElementById('bigPhoto') ;
	if( bigPhoto ) bigPhoto.style.display = 'none' ;

	//alert('initReferanseProsjekt done!');

}	//	end of *initReferanseProsjekt*


//
//	initialize ledelse.html
function initLedelse()
{
	var leaderPicCurr = document.getElementById('skogseidePicture') ; ;
	//var column2 = document.getElementById('column2') ;
	var column2 = document.getElementById('ledelseInfo') ;
	if ( column2 )
	{
		var closePic = document.getElementById('closePic') ;	//	close-button / lukk-knappen
		var leaderDivs = column2.getElementsByTagName('div') ;
		for ( var j=0, length=leaderDivs.length; j<length; j++ )
		{
			if( leaderDivs[j].className != 'leaderPosition' ) continue ;
			//  binding handlers to objects
			//leaderDivs[j].onmouseover = mouseGoesOverLeaderDiv ;
			//leaderDivs[j].onmouseout = mouseLeavesLeaderDiv ;
			leaderDivs[j].onclick = mouseClicksLeaderDiv ;
		}	//	end of for-loop

		var hideLeaderInfoLinks = column2.getElementsByTagName('a') ;
		for ( var j=0, length=hideLeaderInfoLinks.length; j<length; j++ )
		{
			//  binding handlers to objects
			hideLeaderInfoLinks[j].onclick = mouseClicksCloseLeaderInfo ;
		}	//	end for-loop

		if( closePic )
		{
			closePic.onclick = mouseClicksCloseLeaderInfo ;
			closePic.onmouseover = mouseGoesOverCloseButton ;
			closePic.onmouseout = mouseLeavesCloseButton ;
		}
	}

	//var pictureBox = document.getElementById('pictureBox') ;
	var pictureBox = document.getElementById('pictureBoxLeft') ;
	if ( pictureBox )
	{
		var leaderPictures = pictureBox.getElementsByTagName('img') ;
		for ( var j=0, length=leaderPictures.length; j<length; j++ )
		{
			//  binding handlers to objects
			//leaderPictures[j].onmouseover = mouseGoesOverLeaderPicture ;
			//leaderPictures[j].onmouseout = mouseLeavesLeaderPicture ;
			leaderPictures[j].onclick = mouseClicksLeaderPicture ;
		}	//	end of for-loop
	}

}	//	end of *initLedelse*


//	DEV
function initLedelseNew()
{
	alert('initLedelseNew') ;
	var pattern = /\bleader-link\b/ ;
	et_init( pattern, 'listeLedergruppen' ) ;

	var closePic = document.getElementById('closePic') ;	//	lukk-knappen
	if( closePic )
	{
		//closePic.onclick = mouseClicksCloseLeaderInfo ;
		closePic.onclick = closePic.et_toggle ;
		closePic.onmouseover = mouseGoesOverCloseButton ;
		closePic.onmouseout = mouseLeavesCloseButton ;
	}
}


//
//	initialize stikkord.html
function initStikkord()
{
	sortList() ;
	splitListIntoTwo() ;
	initLinkOmsetning() ;

}	//	end of *initStikkord*


//
//	initialize tjenester_og_produkter.html
function initTjenester()
{
	var tjenesterListe = document.getElementById('tjenesterListe') ;
	if ( tjenesterListe )
	{
		var tjenesterLinks = tjenesterListe.getElementsByTagName('a') ;
		for( var j=0, length=tjenesterLinks.length; j<length; j++ )
		{
			if( !tjenesterLinks[j].id ) continue ;
			tjenesterLinks[j].onclick = mouseClicksTjenesterLink ;
		}	//	end for loop
	}

	var infoBox = document.getElementById('tjenesterInfo') ;
	if ( infoBox )
	{
		var tjenesterDivs = infoBox.getElementsByTagName('div') ;
	}

	//alert('initTjenester done') ;

}	//	end of *initTjenester*


//
//	initialize stillinger.html
function initStillinger()
{

	//	regExp
	//	\b: word boundary
	var pattern = /\btoggleJobAdvertisement\b/ ;

	//	check if there was linked *directly* to the jobb advertisement
	//	à la *stillinger.html#tomrer*
	var loc = document.location.toString() ;
	var target = loc.split('#')[1] ;

	if ( target && document.getElementById(target) )
	{
		//alert('target: ' + target ) ;
		et_init( pattern, target, null ) ;
	}
	else
	{
		et_init( pattern, null, null ) ;
	}

}	//	end of *initStillinger*


//
//	initialize telefonliste.html
function initTelefonliste()
{
	var table = document.getElementById( 'tableTelefonListe' ) ;

	if ( table && (table.tagName.toLowerCase() == 'table') )
	{
		var trs = table.getElementsByTagName('tr') ;
		for ( var j=0, length=trs.length; j<length; j++ )
		{
			if (  trs[j].parentNode.nodeName.toLowerCase() == 'tbody' &&
						trs[j].parentNode.nodeName.toLowerCase() != 'tfoot'
				 )
			{
				if(trs[j].className == 'firstEntry' )
				{
					//	preserve className for first row in table body
					trs[j].onmouseover = function() { this.className = 'firstEntry ruled'; return false; }
					trs[j].onmouseout  = function() { this.className = 'firstEntry'; return false; }
				}
				else
				{
					trs[j].onmouseover = function() { this.className = 'ruled'; return false; }
					trs[j].onmouseout  = function() { this.className = ''; return false; }
				}
			}
		}	//	end for loop

	}

}	//	end of *initTelefonliste*

//
//	initialize easyToggle
function et_init( pattern, standardDiv, showFirst )
{
	//alert('standardDiv is: *' + standardDiv + '*' ) ;
	var link, id, target, first ;
	first = true ;

	var docLinks = document.getElementsByTagName('a') ;

	// DEV
	if  ( standardDiv )
	{
		var standardDivTarget = document.getElementById(standardDiv) ;
		et_toggleElements[0] = standardDivTarget ;
		//alert('standardDivTarget is now in et_toggleElements') ;
	}


	for ( var i=0, length=docLinks.length ; i<length ; i++ )
	{
		link = docLinks.item(i) ;

		//  exec( string )
		//  Matches string against this RegExp and returns an array containing the results of the match, or null if no match was found.
		//  Element 0 of the array is the matching text. Subsequent elements of the array contain the substrings
		//	that matched the subexpressions within the RegExp.
		//  The returned array also has an index property that specifies the start position of the match.
		//
		//  Anchoring match position:
		//  \b, \B : Require match at a word boundary/non-boundary


		if ( pattern.exec(link.className) )
		{
			//  split( delimiter, limit):
			//  Returns an array of strings, created by splitting string into substrings at the boundaries specified by delimiter.
			//  delimiter may be a string or a RegExp. If delimiter is a RegExp with a parenthesized subexpression,
			//  the delimiter text that matches the subexpression is included in the returned array.

			id = link.href.split('#')[1] ;
			//alert(id) ;
			target = document.getElementById(id) ;
			et_toggleElements[et_toggleElements.length] = target ;
			if ( standardDiv == null && first )
			{
					first = false ;
					target.style.display = 'none' ;	/* TMP !!!*/
			}
			else if ( standardDiv == id )
			{
					target.style.display = 'block' ;
					//first = false ;
			}
			else
			{
					target.style.display = 'none' ;
			}
			link.onclick = et_toggle ;
		}
	}	//	end for loop
}



//
//	FUNCTIONS FOR REFERANSE_PROSJEKTER.HTML
//	FUNKSJONER TIL REFERANSE_PROSJEKTER.HTML

function mouseGoesOverReferanceLink()
{
  highlightReference(this.id, 'on') ;
}

function mouseLeavesReferanceLink()
{
  highlightReference(this.id, 'off') ;
}

function mouseGoesOverReferancePicture()
{
	var newId = this.id ;
	var newId = newId.slice( 0, -7 ) ;	//	chopps off 'picture', ergo: *havretunPicture* goes *havretun*
	highlightReference( newId, 'on' ) ;
}

function mouseLeavesReferancePicture()
{
	var newId = this.id ;
	var newId = newId.slice( 0, -7 ) ;	//	chopps off 'picture', ergo: *havretunPicture* goes *havretun*
  highlightReference( newId, 'off' ) ;
}

function highlightReference( target, state )	//	event handler function
{
	var targetText = document.getElementById( target + "Text" ) ;
	//var targetPicture = document.getElementById( target + "Picture" ) ;

  if( state == 'on' )
  {
		if ( targetText ) { targetText.style.display = "block" ; }
    //if ( targetPicture ) { targetPicture.style.border = "solid red 1px" ; }
  }
  else
  {
		if ( targetText ) { targetText.style.display = "none" ; }
    //if ( targetPicture ) { targetPicture.style.border = "solid white 1px" ; }
  }
} //  end of *highlightReference*



//
//	FUNCTIONS FOR THE PAGES ABOUT REFERANCE PROSJEKTS
//	FUNKSJONER TIL DE ENKELTE REFERANSER
function clickOnReferencePicture()
{
	//	showBigPhoto( 'bigPhoto', this.src, 'text' + this.id ) ;

	showPictureText( this, 'text' + this.id ) ;

}	//	end of *clickOnReferencePicture*

function showBigPhoto( targetPicture, srcPicture , targetText )	// OLD - KILL ???
{

	var parent = document.getElementById('pictureComments') ;
	if( !parent ) return ; //	break off processing / avbryt

  var children = parent.getElementsByTagName('div') ;

  //  loop through the children, make all text boxes disappear which have an id
  for( var i=0, length=children.length; i<length; i++ )
  {
		if( children[i].id )
		{
			//alert( children[i].id + ': display is set to none' ) ;
			children[i].style.display = "none" ;
		}
	}

  document.getElementById( targetPicture ).style.display = "none" ;         //  first erase the old picture
  document.getElementById( targetPicture ).src = srcPicture ;  							//  now set the source for the new picture
  document.getElementById( targetPicture ).style.display = "block" ;        //  make the picture visible

	if( document.getElementById(targetText) )	//	ask first to make the function more robust
  {
		//alert('targetText found!') ;
		document.getElementById( targetText ).style.display = "block" ;
	}

	//alert('picture: ' + srcPicture + ' was clicked - targetText was: ' + targetText ) ;

} //  end of *showBigPhoto*

//
function showPictureText( sourcePicture , targetText )
{
	var parent = document.getElementById('pictureComments') ;
	if( !parent ) return ; //	break off processing / avbryt

  var children = parent.getElementsByTagName('div') ;

  //  loop through the children, make all text boxes disappear which have an id
  for( var i=0, length=children.length; i<length; i++ )
  {
		if( children[i].id )
		{
			//alert( children[i].id + ': display is set to none' ) ;
			children[i].style.display = 'none' ;
		}

	}	//	end for loop

	var targetElement = document.getElementById( targetText ) ;

	if( targetElement )	//	ask first to make the function more robust
  {
		//alert('targetText found!') ;
		document.getElementById( 'klikkTipp' ).style.display = 'none' ;
		//document.getElementById( targetText ).style.display = "block" ;
		targetElement.style.display = "block" ;

		targetElement.scrollIntoView() ;	//	IE-DOM-method
		unsetImageBorders() ;
		sourcePicture.style.borderRight = '10px solid #D40026' ;
	}

}	//	end of *showPictureText*

//	utility function for showPictureText
function unsetImageBorders()
{
	var picturebox = document.getElementById( 'pictureBoxLeft' ) ;
	if( !picturebox ) return ;	//	break off processing / avbryt

	var imageChildren = picturebox.getElementsByTagName( 'img' ) ;

	for ( var j=0, length=imageChildren.length; j<length; j++ )
	{
		imageChildren[j].style.border = '0' ;
	}	//	end for loop

}	//	end of *unsetImageBorders*

// ???
function showLinks()
{
  //alert("test showLinks") ;
  var parent = document.getElementById( "pictureComments" ) ;
  var children = parent.getElementsByTagName('div') ;

  //  loop through the children, make all text boxes disappear
  for( var i=0, length=children.length; i<length; i++ )
  {
		children[i].style.display = "none" ;
  }

  document.getElementById("bigPhoto").style.display = "none" ;
  document.getElementById("linkRef").style.display = "block" ;
} //  end of *showLinks*


//
//	FUNCTIONS FOR LEDELSE.HTML
//	FUNKSJONER TIL LEDELSE.HTML
function mouseGoesOverLeaderDiv()
{
	highlightLeader( this.id, 'on' ) ;
}	//	end of *mouseGoesOverLeaderDiv*

function mouseLeavesLeaderDiv()
{
	highlightLeader( this.id, 'off' ) ;
}	//	end of *mouseLeavesLeaderDiv*

function mouseGoesOverLeaderPicture()
{
	var newId = this.id ;
	if ( newId )
	{
		newId = newId.slice( 0, -7 ) ;	//	chopps off 'picture', ergo: *skogseidePicture* goes *skogseide*
		highlightLeader( newId, 'on' ) ;
	}
}	//	end of *mouseGoesOverLeaderPicture*

function mouseLeavesLeaderPicture()
{
	var newId = this.id ;
	if ( newId )
	{
		newId = newId.slice( 0, -7 ) ;	//	chopps off 'picture', ergo: *skogseidePicture* goes *skogseide*
		highlightLeader( newId, 'off' ) ;
	}
}	//	end of *mouseLeavesLeaderPicture*

function mouseClicksLeaderPicture()
{
	var newId = this.id ;
	leaderPicCurr = this ;
	//alert('leaderPicCurr: ' + leaderPicCurr.id) ;
	//alert(newId) ;
	if ( newId )
	{
		newId = newId.slice( 0, -7 ) ;	//	chopps off 'picture', ergo: *skogseidePicture* goes *skogseide*
		showLeaderInfo( newId ) ;
	}
}

function mouseClicksLeaderDiv()
{
	showLeaderInfo( this.id ) ;
}	//	end of *mouseClicksLeaderDiv*

function mouseClicksCloseLeaderInfo()
{
	hideLeaderInfo() ;
}	//	end of *mouseClicksCloseLeaderInfo*

function highlightLeader( target, state )
{
	var color = normalColor ;

  if( state == 'on' )
  {
		color = highlightColor ;
  }


	document.getElementById( target ).style.color = color ;
	document.getElementById( target + "Picture" ).style.borderTop = 'solid ' +  color + ' 1px' ;
	document.getElementById( target + "Picture" ).style.borderLeft = 'solid ' +  color + ' 1px' ;
	document.getElementById( target + "Picture" ).style.borderRight = 'solid ' +  color + ' 1px' ;

	//if ( target == leaderPicCurr.id )
	//{ alert ('leaderPicCurr!!! LEFT/HOVERED') ;}

} //  end of *highlightLeader*

function mouseGoesOverCloseButton()
{
	var closePic = document.getElementById('closePic') ;
	if( closePic ) closePic.src = '_bilder/lukkOver.gif' ;
}

function mouseLeavesCloseButton()
{
	var closePic = document.getElementById('closePic') ;
	if( closePic ) closePic.src = '_bilder/lukk.gif' ;
}

function showLeaderInfo( target )
{
	//alert(target) ;
	var leaderInfo = document.getElementById( target + 'Info' ) ;
	if( !leaderInfo ) return ;

	//var column2 = document.getElementById('column2') ;
	var column2 = document.getElementById('ledelseInfo') ;
	var col2Divs = column2.getElementsByTagName('div') ;
	var closePic = document.getElementById('closePic') ;

	//var leaderPics = document.getElementById('pictureBox').getElementsByTagName('img') ;
	var leaderPics = document.getElementById('pictureBoxLeft').getElementsByTagName('img') ;

	//	make all DIVs in *column2* disappear
	for( var j=0, length=col2Divs.length; j<length; j++ )
	{
		col2Divs[j].style.display = 'none' ;
	}	//	end for-loop

	document.getElementById(target).style.display = 'none' ;
	leaderInfo.style.display = 'block' ;	// block
	closePic.style.display = 'block' ;

	//	make all leaderPictures's bottom border diseppear
	for( var j=0, length=leaderPics.length; j<length; j++ )
	{
		//leaderPics[j].style.borderBottom = 'solid ' + normalColor + ' 1px'  ;
		leaderPics[j].style.borderRight = 'solid ' + normalColor + ' 1px'  ;
	}

  //document.getElementById( target + "Picture" ).style.border = 'solid '+ normalColor + ' 1px' ;
  //document.getElementById( target + "Picture" ).style.borderBottom = 'solid '+ normalColor + ' 10px' ;
  document.getElementById( target + "Picture" ).style.borderRight = 'solid '+ highlightColor + ' 10px' ;

}	//	end of *showLeaderInfo*

function hideLeaderInfo()
{
	//var column2 = document.getElementById('column2') ;
	var column2 = document.getElementById('ledelseInfo') ;
	var col2Divs = column2.getElementsByTagName('div') ;
	var closePic = document.getElementById('closePic') ;

	//var leaderPics = document.getElementById('pictureBox').getElementsByTagName('img') ;
	var leaderPics = document.getElementById('pictureBoxLeft').getElementsByTagName('img') ;


	for(var j=0, length=col2Divs.length; j<length; j++ )
	{
		if( col2Divs[j].className == 'leaderPosition' )
		{
			col2Divs[j].style.display = 'block' ;
		}
		else if( col2Divs[j].className == 'leaderInfo' )
		{
			col2Divs[j].style.display = 'none' ;
		}
	}	//	end for-loop

	if ( closePic )
	{
		closePic.src = '_bilder/lukk.gif' ;
		closePic.style.display = 'none' ;
	}

	//	make all leaderPictures's bottom border diseppear
	for( var j=0, length=leaderPics.length; j<length; j++ )
	{
		leaderPics[j].style.borderRight = 'solid ' + normalColor + ' 1px'  ;
	}

}	//	end of *hideLeaderInfo*


//
//	FUNCTIONs FOR TJENESTER_OG_PRODUKTER.HTML
//	FUNKSJONER TIL TJENESTER_OG_PRODUKTER.HTML
function mouseClicksTjenesterLink()
{
	var newId = this.id ;
	if( !newId ) return true ;	//	follow default link

	var target = newId.slice( 0, -4 ) ;	//	chopps off 'Links', ergo: *skoleByggLink* goes *skoleBygg*

	return showTjenesterInfo( target ) ;

}	//	end of *mouseClicksTjenesterLink*

function showTjenesterInfo( target )
{
	var infoDiv = document.getElementById( target ) ;
	if( !infoDiv ) return true ;	//	break off processing

	var parent = infoDiv.parentNode ;
	var siblings = parent.getElementsByTagName('div') ;
	for( var j=0, length=siblings.length; j<length; j++ )
	{
		if ( siblings[j].id == target )
		{
			siblings[j].style.display = 'block' ;
			siblings[j].scrollIntoView() ;
		}
		else
		{
			siblings[j].style.display = 'none' ;
		}
	}	//	end for loop

	var closePic = document.getElementById('closePic') ;
	if( closePic ) closePic.style.display = 'block' ;

	parent.style.display = 'block' ;

	return false ;	//	so the default links is not loaded

}	//	end of *showTjenesterInfo*


//
//	FUNCTIONS FOR STIKKORD.HTML
//	FUNKSJONER TIL STIKKORD.HTML
function sortList()
{

	var list = document.getElementById('listeStikkord');

	//	hide list during manipulation - ???
	list.style.display = 'none' ;

	var listItems = list.getElementsByTagName('li') ;

	var listItemsArray = new Array();
	for ( var i=0, length=listItems.length; i<length; i++ )
	{
		//	cloneNode(): ... The method takes a single Boolean argument
		//	indicating whether the copy should include all children of the node
		//	(called a deep clone) or just the element itself.
		listItemsArray[i] = listItems[i].cloneNode( true ) ;
	}

	//
	listItemsArray.sort( itemCompare ) ;

	var newList = document.createElement('ul');
	for (var i=0, length=listItemsArray.length; i<length; i++)
	{
		newList.appendChild( listItemsArray[i] ) ;
	}

	newList.id = 'listeStikkord' ;
	newList.className = 'liste-stikkord-left' ;

	list.parentNode.replaceChild(newList, list) ;

	//	hide list during manipulation - ???
	list.style.display = 'none' ;

}	//	end of *sortList*

//
function itemCompare( a, b )
{
	//	toLowerCase makes the sorting case-insensitive
	var aVal = a.getElementsByTagName('a')[0].lastChild.nodeValue.toLowerCase() ;
	var bVal = b.getElementsByTagName('a')[0].lastChild.nodeValue.toLowerCase() ;
	//alert('aVal: ' + aVal + ' - bVal: ' + bVal ) ;
	return ( aVal == bVal ? 0 : (aVal > bVal ? 1 : -1) ) ;

}	//	end of *itemCompare*

//
function splitListIntoTwo()
{
	var stikkordListe = document.getElementById('listeStikkord') ;
	if( !stikkordListe ) return ;	//	break off processing

	//	hide list during manipulation
	stikkordListe.style.display = 'none' ;

	var listItems = stikkordListe.getElementsByTagName('li') ;
	if( !listItems ) return ; //	break off processing

	var listLength = listItems.length ;
	if( listLength <=5 ) return ; // break off processing, list is too small

	var breakListHere = Math.ceil( listLength / 2 ) ;	//	break the list into two parts

	var rightList = document.createElement('ul') ;
	//	hide list during manipulation
	rightList.style.display = 'none' ;


	//	...
	//	NB: i begin with the last item
	for ( var j=listLength-1; j>=breakListHere; j-- )
	{
		var currentListItem = listItems[j] ;
		var removedNode = currentListItem.parentNode.removeChild( listItems[j] ) ;

		if( !rightList.firstChild )
		{
			rightList.appendChild( removedNode ) ;
		}
		else
		{
			rightList.insertBefore( removedNode, rightList.firstChild ) ;
		}
	}	//	end for-loop

	//
	var nextElement = document.getElementById( 'listePublikasjoner' ) ;
	if (nextElement && nextElement.previousSibling )
	{
		nextElement.parentNode.insertBefore( rightList, nextElement.previousSibling )
	}
	else
	{
		stikkordListe.parentNode.appendChild( rightList ) ;
	}


	//	assign classes
	stikkordListe.className = 'liste-stikkord-left' ;
	rightList.className = 'liste-stikkord-right' ;

	//	show list(s) again
	stikkordListe.style.display = 'block' ;
	rightList.style.display = 'block' ;

	//alert('*' + rightList.className + '*') ;

	//	problems in mozilla firefox, ie 6 slightly buggy

}	//	end of *splitListIntoTwo*


// DEV
function getWindowHeight()
{
	var windowHeight = 0;
	var whichHeigh = '' ;

	if ( typeof(window.innerHeight) == 'number' )
	{
		windowHeight = window.innerHeight;
		whichHeigh = 'innerHeight' ;
	}
	else
	{
		if ( document.documentElement && document.documentElement.clientHeight )
		{
			windowHeight = document.documentElement.clientHeight;
			whichHeigh = 'document.documentElement.clientHeight' ;
		}
		else
		{
			if ( document.body && document.body.clientHeight )
			{
				windowHeight = document.body.clientHeight;
				whichHeigh = 'document.body.clientHeight' ;
			}
		}
	}

	alert ( whichHeigh + ' -- ' + windowHeight ) ;
	return windowHeight;

}	//	end of *getWindowHeight*


// DEV
function setFooter()
{
	if (document.getElementById)
	{
		var windowHeight = getWindowHeight();
		if (windowHeight > 0)
		{
			var contentHeight = document.getElementById('testContainer').offsetHeight;
			alert('contentHeight - ' + contentHeight ) ;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			alert('footerHeight - ' + footerHeight ) ;
			if (windowHeight - (contentHeight + footerHeight) >= 0)
			{
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else
			{
				footerElement.style.position = 'static';
			}
		}
	}
}

//	DEV
//
//	utility function
// 	...
function et_toggle(e)
{
	/* Adapted from http://www.quirksmode.org/js/events_properties.html */

	//  the typeof operator:
	//  Applied to a variable or literal, it returns a string indicating the type of its argument.

	if ( typeof e == 'undefined' )
	{
			var e = window.event ;
	}

	var source ;
	if ( typeof e.target != 'undefined' )
	{
		source = e.target ;
	}
	else if ( typeof e.srcElement != 'undefined' )
	{
		source = e.srcElement ;
	}
	else
	{
		return true ;
	}

	//alert( 'tagName: --' + source.tagName.toLowerCase() + '--' ) ;
	if ( source.tagName.toLowerCase() != 'a' ) source = source.parentNode ;
	//alert( 'tagName again: ' + source.tagName ) ;



	/* For most browsers, targ would now be a link element ; Safari however
		 returns a text node so we need to check the node type to make sure */
	/*
	if (source.nodeType == 3)
	{
		source = source.parentNode ;
		if ( source.tagName.toLowerCase != 'a' ) source = source.parentNode ;
	}
	*/

	var id = source.href.split('#')[1] ;
	//alert('id: ' + id) ;
	var elem ;
	for (var i = 0 ; (elem = et_toggleElements[i]) ; i++)
	{
		if (elem.id != id)
		{
				elem.style.display = 'none' ;
		}
		else
		{
				elem.style.display = 'block' ;

				//	scrollIntoView( top )
				//	Scrolls the document so this element is visible at the top or bottom of the window.
				//	If top is true or is omitted, the element appears at the top of the window.
				//	If false, the element appears at the bottom.

				elem.scrollIntoView( true ) ;
		}
	}
	return false ;

}	//	end of *et_toggle*


//	TMP
//
function qs( el )
{
	// from www.google.com
	if ( window.RegExp && window.encodeURIComponent )
	{
		//document.f.q.value  = encodeURIComponent( document.f.q.value ) ;
		//document.f.q.value  = escape( document.f.q.value ) ;
		//alert( document.f.q.value ) ;
		return true ;
	}
}	//	end of *qs*

function qs_pg( el )
{
	var q_value = document.f.q.value ;
	q_value = q_value.replace( /\xE5|\xC5/i , 'aa' ) ;
	q_value = q_value.replace( /\xF8|\xD8/gi , 'oe' ) ;
	q_value = q_value.replace( /\xE6|\xC6/gi , "ae" ) ;
	q_value = q_value.replace( /test/gi , "TEST" ) ;

	document.f.q.value = q_value ;
	//alert ( document.f.q.value ) ;
	return true ;
}


//
//
function initLinkOmsetning()
{
	var linkOmsetning = document.getElementById('linkOmsetning') ;
	if( !linkOmsetning ) return ;	//	break off processing

	linkOmsetning.onclick = linkOmsetningClicked ;
	//alert('linkOmsetning initialized') ;
}


function linkOmsetningClicked()
{
	window.open ('http://www.multibygg.no/omsetning.html', 'popupOmsetning', 'height=500,width=750' ) ;
	return false ;
}

