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

	return 0;
}

function correctHeights()
{
	var bdiv=document.getElementById('body');
	var hdiv=document.getElementById('header');

	if (!bdiv || !hdiv)
		return;

	var viewporth=windowHeight();

	if (!bdiv.origHeight)
		bdiv.origHeight=bdiv.offsetHeight;

	if (bdiv.origHeight < (viewporth - hdiv.offsetHeight - 2))
	{
		var minh= (viewporth - hdiv.offsetHeight - 2) + "px";
		bdiv.style.height=minh;
		bdiv.firstChild.style.height=minh;
	}
}

var ct;

function resizeWindow()
{
	if (ct)
		clearTimeout(ct);

	var bdiv=document.getElementById('body');
	bdiv.style.height='auto';
	bdiv.firstChild.style.height='auto';
	bdiv.origHeight=0;

	ct=setTimeout('correctHeights()', 10);
}

function addEvent(element, eventname, func, use_capture)
{
	if (element.addEventListener) 
	{
		element.addEventListener(eventname, func, use_capture);
		return true;
	}
	else if (element.attachEvent)
	{
		var r=element.attachEvent('on'+eventname, func);
		return r;
	}
	else
	{
		element['on'+eventname]=func;
		return true;
	}

	return false;
}

function setupMouseovers()
{
	var menubar=document.getElementById('menu');

	for(var i=0; i < menubar.childNodes.length; i++)
	{
		addEvent(menubar.childNodes[i].firstChild, 'mouseover', mouseOver, false);
		addEvent(menubar.childNodes[i].firstChild, 'mouseout', mouseOut, false);
	}

	var inputs=document.getElementsByTagName('input');

	for (var i=0; i < inputs.length; i++)
	{
		if (inputs[i].getAttribute('type').toLowerCase() == 'image')
		{
			addEvent(inputs[i], 'mouseover', mouseOver, false);
			addEvent(inputs[i], 'mouseout', mouseOut, false);
		}
	}
}

function getEventSource(e)
{
	if (window.event && window.event.srcElement)
		return window.event.srcElement;
	else if (e && e.target)
		return e.target;
}

function mouseOver(e)
{
	var se=getEventSource(e);

	se.src=se.src.replace(/but_(.*)\.png$/, 'but_$1_on.png');
}

function mouseOut(e)
{
	var se=getEventSource(e);

	se.src=se.src.replace(/but_(.*)_on\.png$/, 'but_$1.png');
	
}

function loadEvents()
{
	correctHeights();
	if (navigator.appName != 'Microsoft Internet Explorer' || window.opera)
		addEvent(window, 'resize', resizeWindow, false);

	setupMouseovers();
}

addEvent(window, 'load', loadEvents, false);
