window.onload = function()
{
	place 	= getQueryVariable("place");
	action 	= getQueryVariable("action");
	
	if ( place==undefined)
		place = 'front';
	
	/*	
	if( place == "front" )
		swfobject.embedSWF('main.swf', 'contentHolder', '900', '560', '9.0.0');
	else if (place == "tre")
		swfobject.embedSWF('treetIntro.swf', 'contentHolder', '900', '560', '9.0.0');
	else if ( place == "bukta3" )
		swfobject.embedSWF('bukta.swf', 'contentHolder', '900', '560', '9.0.0');
	else if (place == 'kirka')
		swfobject.embedSWF('kirke.swf', 'contentHolder', '900', '560', '9.0.0');
	
	else*/
	
	xajax_gotoPlace(place, action);

	av_height = getWinHeight();
	pageDim = getPageSizeWithScroll();
	if( pageDim[1] > av_height )
		av_height = pageDim[1];
   av_height = av_height + 'px';
	document.getElementById('overlegg').style.height = av_height;
}

window.onresize = function()
{
	if( document.getElementById('overlegg').style.display == '' )
		sizeOverlegg( 'overlegg' );
}

function getQueryVariable(variable) 
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  //alert('Query Variable ' + variable + ' not found');
}

function leaveFront( place )
{
	if ( place==undefined)
		place = 'front';
	
	/*	
	if( place == "front" )
		swfobject.embedSWF('main.swf', 'contentHolder', '900', '560', '9.0.0');
	else if (place == "tre")
		swfobject.embedSWF('treetIntro.swf', 'contentHolder', '900', '560', '9.0.0');
	else if ( place == "bukta" )
		swfobject.embedSWF('bukta.swf', 'contentHolder', '900', '560', '9.0.0');
	else if (place == "kirka")
		swfobject.embedSWF('kirke.swf', 'contentHolder', '900', '560', '9.0.0');
	else*/
	
	xajax_gotoPlace(place);
}

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

function kinoVisFilm(visId)
{
	xajax_visKinoFilm(visId);
}
function kinoBlaMeny(dir, targetId, antPx)
{
	var height = document.getElementById(targetId).offsetHeight;

	sidePos = document.getElementById(targetId).offsetTop;

	if (dir == "next")
	{
		limit = -height + antPx;
		//alert( height + ' ' +  limit );
		if( sidePos <= limit )
			new Effect.Move (targetId,{ x: 0, y: limit, duration: 0.4, mode: 'absolute'});
		else
			new Effect.Move (targetId,{ x: 0, y: -antPx, duration: 0.4, mode: 'relative'});
	}
	else if (dir == "prev")
	{	
		if( sidePos >= 0 )
			new Effect.Move (targetId,{ x: 0, y: 0, duration: 0.4, mode: 'absolute'});
		else
			new Effect.Move (targetId,{ x: 0, y: antPx, duration: 0.4, mode: 'relative'});
	}
}


function searchSsk()
{
	// Find the search box in the DOM
	var theElement = document.getElementById('sokFeltSsk');
	// Create a function for when the user presses a key
	theElement.onkeyup = function(){ search_delay(this); };
}

function search_delay(element)
{
	// Create a function to get the search results
	var func = function() {
	   var sok = element.value.replace(/(<([^>]+)>)/ig,"");
		if( sok.length > 1 )
		{
			if( element.id == "sokFeltSsk" )
			{
				xajax_sskSok(sok);
			}
		}
	};

	// Check to see if there is already a timeout and if so...
	// ...cancel it and create a new one
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}

function initialize(address, centermap) 
{
	if (GBrowserIsCompatible()) 
	{
		geocoder = new GClientGeocoder();
		map = new GMap2(document.getElementById("map_canvas"));
		if( centermap )
			geocoder.getLatLng(address, function(point) { map.setCenter(point, 13);} );
		map.setUIToDefault();
	}
}

function showAddress(address, info, lat, lng )
{
	var found = false;

	if( lat != "" && lng != "" )
	{
		point = new GLatLng(lat,lng);
		
		var marker = new GMarker(point);
		map.addOverlay(marker);
		map.setCenter(point, 13);
		marker.openInfoWindowHtml(info);
	}	
	else if (geocoder) 
	{
		geocoder.getLatLng(
		address,
			function(point) 
			{
				if (!point) 
				{
					found = false;
					//alert(address + " not found");
				} 
				else 
				{
					found = true;
					map.setCenter(point, 13);
					var marker = new GMarker(point);
					map.addOverlay(marker);
					marker.openInfoWindowHtml(info);
				}
			}
		);
	}
}

function initNorway() 
{

	stop_Int();
	if (GBrowserIsCompatible()) 
	{
		geocoder = new GClientGeocoder();
		map = new GMap2(document.getElementById("map_canvas"));
		geocoder.getLatLng("Norway", function(point) { map.setCenter(point, 5); } );
		map.setUIToDefault();
	}
}

function showFylke(address)
{
	if (geocoder) 
	{
		geocoder.getLatLng(
		address,
		function(point) 
		{
			if (!point) 
			{
				//alert(address + " not found");
			} 
			else 
			{
				map.setCenter(point, 8);
				//var marker = new GMarker(point);
				//map.addOverlay(marker);
				//marker.openInfoWindowHtml(info);
			}
		}
		);
	}
}

function visButikkKart()
{
	document.getElementById('spalte1').style.height = "576px";
	xajax_visJSKart();
}

function hideOverlegg()
{
	if( document.getElementById('overlegg').style.display=='' )
	{
		if( a = document.getElementById('overlegg') )
		{
			a.style.display='none';
			a.innerHTML = '';
			document.getElementById('rtMainContentHolder').innerHTML = '';
		}
		new Effect.Fade('rtMainWrapper', {duration:0.4,queue: 'front'});
	}
}

function sizeOverlegg( overlegg )
{
	overlegg = document.getElementById(overlegg);
   av_width = getWinWidth();
	overlegg.style.width = av_width +'px';
	av_height = getWinHeight();
	pageDim = getPageSizeWithScroll();
	if( pageDim[1] > av_height )
		av_height = pageDim[1];
   av_height = av_height + 'px';
	document.getElementById('overlegg').style.height = av_height;
}



function getWinWidth()
{
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.body.clientWidth) {
		return document.body.clientWidth;
	} else {
		return 0;
	}
}

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;
}

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 SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}
