var pageWidth;
var pageHeight;

scaleWidth = true;
scaleHeight = true;
imSRC = "/img/cms/design/background.jpg";	

window.onresize = findDimensions;
window.onload = findDimensions;

var isIE = (document.getElementById && document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isNS6 = (document.getElementById && !document.all) ? true : false;

function myGetElementById (id)
{
	if (isIE) {
		var str = "document.all('" + id + "')";
		var o = eval(str);
		return o;
	}

	return document.getElementById(id);
}

function setBackgroundImage(bild)
{
	imSRC = bild;
}

function findDimensions ()
{
	var frameWidth;
	var frameHeight;
	var obj;

	if (self.innerWidth) {
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body) {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else
	return;

	// if there's valid info, update the globals so they can be used elsehere
	pageWidth = frameWidth;
	pageHeight = frameHeight;

	if (obj = myGetElementById('background')) {
		obj.style.width = frameWidth;
		obj.style.height = frameHeight;
	}

	if (obj = myGetElementById('background_image'))	{
		var iWidth = obj.width; 
		var iHeight = obj.height;
		var iRatio = iWidth / iHeight;
		var fRatio = frameWidth / frameHeight;	
	
		// reset to default position on resize/load
		obj.style.top = obj.style.left = 0;
	
		if (iRatio < fRatio) {
		obj.style.width = frameWidth;
		obj.style.height = frameWidth / iRatio;
		} else {
			obj.style.height = frameHeight;
			obj.style.width = frameHeight * iRatio;
		}
	}
}
