window.onload = function()
{
	//Sett riktig størrelse på overlegg
	pageDim = getPageSizeWithScroll();
 	av_height = getWinHeight();
	if( pageDim[1] > av_height )
		av_height = pageDim[1];
   document.getElementById('overlegg').style.height = av_height + "px";
}

function bildeserieMove(dir, width) 
{ 
	sidePos = document.getElementById('contentBildeserieSlider').offsetLeft;
	if (dir == "next")
	{
		limit = -width + 445;
		if( sidePos <= limit )
			new Effect.Move ("contentBildeserieSlider",{ x: limit, y: 0, duration: 0.4, mode: 'absolute'});
		else
			new Effect.Move ("contentBildeserieSlider",{ x: -445, y: 0, duration: 0.4, mode: 'relative'});
	}
	else if (dir == "prev")
	{	
		if( sidePos >= 0 )
			new Effect.Move ("contentBildeserieSlider",{ x: 0, y: 0, duration: 0.4, mode: 'absolute'});
		else
			new Effect.Move ("contentBildeserieSlider",{ x: 445, y: 0, duration: 0.4, mode: 'relative'});
	}
}

function hovedsak(linjeNr)
{
	var pilHeight = linjeNr - 1;
	pilHeight *=	22;
	pilHeight +=	15;
	document.getElementById('contentBildeseriePilBunn').style.height = pilHeight + "px";
}

function forside_sak(art_id, nr)
{
	nyHeight = 15 + 20 * (nr - 1);
	document.getElementById('contentBildeseriePilBunn').style.height = nyHeight + 'px';
	xajax_visForside(art_id);
}


function search( sok )
{
	var sok = sok.replace(/(<([^>]+)>)/ig,"");
	if( sok.length > 2 )
	{
		//alert( sok );
		document.getElementById('overlegg').style.display='';
		new Effect.Appear('sokToppBoks', { duration: 1.0 });
		new Effect.Appear('sokResultat', { duration: 1.0 });
		xajax_search(sok);
	}
}

function hideOverlegg()
{
	//xajax_resetPops();
	if( document.getElementById('overlegg').style.display=='' )
	{
		document.getElementById('overlegg').style.display='none';
		document.getElementById('sokResultat').style.display='none';
		document.getElementById('sokToppBoks').style.display='none';
		document.getElementById('sokFelt').value='';
	}
}

function openKampsite(id)
{
	
	if( typeof( window.innerWidth ) == 'number' )
	{
			aWidth 	= screen.availWidth;
			aHeight 	= screen.availHeight;
	}
	else
	{
		aWidth 	= screen.availWidth;
		aHeight	= screen.availHeight;
	}
	
	var top = 0;
	var left = 0;
	
	if(aWidth > 980 )
	{
		aWidth = aWidth - 40;
		aHeight = aHeight - 60;
		top = 30;
		left = 20;
	}
	else if( aWidth > 1200 )
	{
		aWidth = aWidth - 200;
		aHeight = aHeight - 200;
		top = 100;
		left = 100;
	}
	if( id )
		url = 'http://tomb2010.no/'+id;
	else
		url = 'http://tomb2010.no/';
	//alert( url );
	//kamp = window.open('http://www.tomb.no/09/'+id,'Tomb 09','width='+aWidth+',height='+aHeight+',left='+left+',top='+top+',resizable=1, scrollbars=1, toolbar=0, location=0, directories=0, status=0, menubar=0')
	kamp = window.open(url, "Studietilbud", 'width='+aWidth+',height='+aHeight+',left='+left+',top='+top+',resizable=1, scrollbars=0, toolbar=0, location=0, directories=0, status=0, menubar=0');
	kamp.focus();
	/*
	if( kamp == false )
	{
		//alert( "kunne ikke åpne, går til side"); 
		location.href = url;
	}
	*/
	
}

function rotBanner()
{
	var t=setInterval("xrotBanner()",5000);
}

function xrotBanner()
{
	var nr = document.getElementById('b_nr').innerHTML;
	xajax_rotBanner(4, nr);
}

function getWinHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}