// JavaScript Document

var currentBlogListPosition = 0;
var blogListScrollIncrement = 18;

function ScrollBlogListUp()
{
	currentBlogListPosition += blogListScrollIncrement;
	if (currentBlogListPosition > 0) currentBlogListPosition = 0;
	document.getElementById("BlogEntriesList").style.top = currentBlogListPosition + "px";
}

function ScrollBlogListDown()
{
	currentBlogListPosition -= blogListScrollIncrement;
	scrollHeight = document.getElementById("BlogEntriesList").offsetHeight - document.getElementById("BlogEntryListContainer").offsetHeight;
	if (currentBlogListPosition < (-1 * scrollHeight)) currentBlogListPosition = (-1 * scrollHeight);
	document.getElementById("BlogEntriesList").style.top = currentBlogListPosition + "px";
}

function ScrollBlogListHover(elem, isTop, isHoverOn)
{
	newColor = (isHoverOn) ? "CE560C" : "8CA9B6";
	container = document.getElementById("BlogEntryListContainer");
	
	if (isTop)
		container.style.borderTop = "1px solid #" + newColor;
	else
		container.style.borderBottom = "1px solid #" + newColor;
}

var currentLabsListPosition = 0;
var labsListScrollIncrement = 15;

function ScrollLabsListUp()
{
	currentLabsListPosition += labsListScrollIncrement;
	if (currentLabsListPosition > 0) currentLabsListPosition = 0;
	document.getElementById("LabsEntriesList").style.top = currentLabsListPosition + "px";
}

function ScrollLabsListDown()
{
	currentLabsListPosition -= labsListScrollIncrement;
	scrollHeight = document.getElementById("LabsEntriesList").offsetHeight - document.getElementById("LabsEntryListContainer").offsetHeight;
	if (currentLabsListPosition < (-1 * scrollHeight)) currentLabsListPosition = (-1 * scrollHeight);
	document.getElementById("LabsEntriesList").style.top = currentLabsListPosition + "px";
}

function ScrollLabsListHover(elem, isTop, isHoverOn)
{
	newColor = (isHoverOn) ? "B6C8D0" : "FFFFFF";
	container = document.getElementById("LabsEntriesList");
	
	container.style.backgroundColor = "#" + newColor;
}

var footerMessages = new Array();
footerMessages[0] = '<s>Reserved</s> <i>repealed by GWB</i>';
footerMessages[1] = '<s>Reserved</s> <i>traded for "security"</i>';
footerMessages[2] = '<s>Reserved</s> <i>violations of the DMCA</i>';
footerMessages[3] = '<s>Reserved</s> <i>traded on Napster</i>';
footerMessages[4] = '<s>Reserved</s> <i>sold for oil</i>';
footerMessages[5] = 'Reserved <i>for the wealthy</i>';
footerMessages[6] = 'Reserved <i>while supplies last</i>';
footerMessages[7] = '<s>Reserved</s> <i>Metro\'d</i>';

function GetFooterMessage()
{
	var rand=Math.floor(Math.random()*footerMessages.length);
	document.write(footerMessages[rand]);
}

function TabMouseOver(elem)
{
	setOpacity(elem, 100);
}

function TabMouseOut(elem)
{
	setOpacity(elem, 55);
}

function setOpacity(elem, opacityAsInt)
{
	if (opacityAsInt < 1)
	{
		// fixes IE7 bug - text rendering loses style, anti-alias if opacity hits 0 on an element
		opacityAsInt = 1;
	}
	
	elem.style.opacity = (opacityAsInt / 100);
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function WindowOnload(f) {
    var prev=window.onload;
    window.onload=function(){ if(prev)prev(); f(); }
}

function nothing()
{
	
}

var scheduleOn = false;
function ToggleSchedule(containerID)
{
	if (scheduleOn)
	{
		document.getElementById(containerID).style.display = 'none';
		scheduleOn = false;
	}
	else
	{
		document.getElementById(containerID).style.display = 'block';
		scheduleOn = true;
	}
}

function IncrementTextBox(textbox, increment, minValue)
{
	var theInput = document.getElementById(textbox);
	var newValue = parseFloat(theInput.value) + increment;
	
	if (newValue < minValue)
		newValue = minValue;
	
	theInput.value = newValue;
}

function GoToFirstChildLink(elem)
{
	for (var z=0; z < elem.childNodes.length; z++)
		if (elem.childNodes[z].nodeName.toLowerCase() == 'a')
			document.location.href = elem.childNodes[z].href;
		else
			GoToFirstChildLink(elem.childNodes[z]);
}

function Get(o) { return document.getElementById(o); }