window.onload = init;

function init()
{
	initInterface();
}

function alertSize()
{
	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;
}

function getOffsets(e)
{
	var o = {
	 height: e.offsetHeight,
	 width: e.offsetWidth
	};
	
	var x = e.offsetLeft;
	var y = e.offsetTop;
	var p = e.offsetParent;
	
	while(p && (p.nodeType != 9))
	{
	 x += p.offsetLeft;
	 y += p.offsetTop;
	 p = p.offsetParent;
	}
	
	o.left = x;
	o.top = y;
	return o;
}

function initInterface()
{
	var pageHeight = (getOffsets(document.getElementById("copyright")).top)+50;
	
	// Get divs by ID
	var wrapDiv = document.getElementById("wrap");
	var sidebarDiv = document.getElementById("sidebar");
	var mainContentDiv = document.getElementById("main_content");
	
	if (pageHeight < alertSize())
	{
		sidebarDiv.style.height = alertSize()+"px";
		wrapDiv.style.height = alertSize()+"px";
	}
	else
	{
		sidebarDiv.style.height = pageHeight + "px";
		wrapDiv.style.height = pageHeight + "px";
	}
	
	initMouseovers();
	initAdmin();
}

function initMouseovers()
{
	var nav = document.getElementById('navigation');
	var imgs = nav.getElementsByTagName('img');
	
	if (document.getElementById('navigation').className == 'Home')
	{
		for (var i=0; i<imgs.length; i++)
		{
			imgs[i].onmouseover = mouseGoesOver;
			imgs[i].onmouseout = mouseGoesOut;
		}
	}
}

function mouseGoesOver()
{
	var navDetails = document.getElementById('navigation_details');
	
	if (this.alt != '')
	{
		i = this.id.replace('nav_button_', '');
		navDetails.style.marginLeft = ((69*(i-1))+32)+'px';
		navDetails.style.display = 'inline';
		navDetails.innerHTML = this.alt;
	}
}

function mouseGoesOut()
{
	var navDetails = document.getElementById('navigation_details');
	
	if (this.alt != '')
	{
		navDetails.style.display = 'none';
	}
}

function initAdmin()
{
	if (document.getElementById("button_toggle_status"))
	{
		document.getElementById("button_toggle_status").onclick = clickToggle;
	}
}

function clickToggle()
{
	toggleDiv = document.getElementById("toggle_status");
	toggleHiddenDiv = document.getElementById("toggle_status_hidden");
	
	if (toggleHiddenDiv.value == 0)
	{
		toggleDiv.innerHTML = '<img src="/img/admin/icon-green-dot.gif" border="0" /> Published';
		toggleHiddenDiv.value = 1;
	}
	else if (toggleHiddenDiv.value == 1)
	{
		toggleDiv.innerHTML = '<img src="/img/admin/icon-red-dot.gif" border="0" /> Not Published';
		toggleHiddenDiv.value = 0;
	}
}