

// these globals that can be used from other routines
var pageWidth;
var pageHeight;

// window.onload	= function() { findDimensions(); };
// window.onresize	= function() { findDimensions(); };

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


/*
 * this is called to reset the background image and height/width
 */
function setBackground (url, width, height)
{
    var obj = myGetElementById ('background_image');
    if ( obj )
    {
	obj.onload = function () { 
	    if ( width ) this.style.width = width;
	    if ( height ) this.style.height = height;
	    findDimensions();
	}
	obj.src = url;
    }
}