/**
 * @author Nate Hayden
 */
 
window.onload = preload;
var cur;
var curParentID;
var originalTop;
var timeToTransition = 100; //(in milliseconds) time allocated for transition
var timeForFadeIn = 1000;
var destTop = 0; //The desired style.top (in pixels)
var dist = 33; //(in pixels) distance for the object to travel
var increment = 3; //(in pixels) distance to travel with each iteration
var topTimer;
var opacityTimer;

var pagedefID;
var pagedefparentID;
var mousetimer;
function startMtimer()
{
	mousetimer = setTimeout(restoreDefault, 10);
}
function stopMtimer()
{
	clearTimeout(mousetimer);
}
function restoreDefault()
{
	if(cur != document.getElementById(pagedefID))
	{
		transitionID(pagedefID, pagedefparentID);
	}
}

function specialNav0()
{
	if(cur != null)
	{
		hideCur();		
	}
	darken("nav0");
	curParentID = "nav0";
	cur = document.getElementById("subnav0");
}
function transitionID(eID, parentID)
{
	if(cur != null)
	{
		hideCur();
	}
	var obb = document.getElementById(eID);
	obb.style.display = "block";
	cur = obb;
	curParentID = parentID;
	originalTop = getStyle_top(obb);
	topTimer = setInterval(function(){slideUp(obb);},(timeToTransition / dist));
	opacityTimer = setInterval(function(){incStyle_opacity(obb, 0.11);}, 50); //0.11 is an excellent delta for fading in and out
	darken(parentID);
}
function darken(eID)
{
	if(eID == "nav0")  //For "Home" tab
	{
		document.getElementById(eID).style.backgroundImage = "url(psdcuts/nav/noshadowdark.gif)";
	}
	else //For other tabs
	{
		document.getElementById(eID).style.backgroundImage = "url(psdcuts/nav/shadowdark.gif)";
	}
	document.getElementById(eID).firstChild.style.color = "#ffffff";
	//setTimeout(function(){document.getElementById(eID).style.backgroundImage = "url(psdcuts/nav/shadowlight.gif)";}, 2000);
}
function lighten(eID)
{
	if(eID == "nav0")
	{
		document.getElementById(eID).style.backgroundImage = "url(psdcuts/nav/noshadowlight.gif)";
	}
	else
	{
		document.getElementById(eID).style.backgroundImage = "url(psdcuts/nav/shadowlight.gif)";
	}
	document.getElementById(eID).firstChild.style.color = "#7f7f7f";
}

function hideCur()
{
	if(topTimer != null && opacityTimer != null)
	{
		clearInterval(topTimer);
		clearInterval(opacityTimer);
	}
	if(cur != null)
	{
		cur.style.top = "33px";
		cur.style.display = "none";
		setStyle_opacity(cur, 0);
	}
	if(curParentID != null)
	{
		lighten(curParentID);
	}
}






function setStyle_opacity(obb, newOp)
{
	if(obb.style.opacity && navigator.appName != "Microsoft Internet Explorer")
	{
		obb.style.opacity = newOp;
	}
	else if(obb.filters)
	{
		obb.filters.alpha.opacity = newOp * 100;
	}
	else if(obb.style.MozOpacity)
	{
		obb.style.MozOpacity = newOp;
	}
	else if(obb.style.KhtmlOpacity)
	{
		obb.style.KhtmlOpacity = newOp;
	}
}
function incStyle_opacity(obb, newOp) //short for "increment"
{
	if(getStyle_opacity(obb) <= 0.98 || (navigator.appName == "Microsoft Internet Explorer" && getStyle_opacity(obb) <= 98))
	{
		if(obb.style.opacity && navigator.appName != "Microsoft Internet Explorer") //if recent Mozilla, Safari, or Opera
		{
			obb.style.opacity = parseFloat(getStyle_opacity(obb)) + newOp;
		}
		else if(obb.filters) //if IE
		{
			//alert(parseInt(getStyle_opacity(obb)) + newOp * 100);
			obb.filters.alpha.opacity = parseInt(getStyle_opacity(obb)) + newOp * 100;
		}
		else if(obb.style.MozOpacity) //Old Mozilla
		{
			obb.style.MozOpacity = parseFloat(getStyle_opacity(obb)) + newOp;
		}
		else if(obb.style.KhtmlOpacity)
		{
			obb.style.KhtmlOpacity = parseFloat(getStyle_opacity(obb)) + newOp;
		}
		return;
	}
}

















function slideUp(obb)
{
	var curTop = getStyle_top(obb);
	if(originalTop - curTop < dist && curTop > destTop)
	{
		obb.style.top = curTop - increment + "px";
	}
}
function getStyle_opacity(obb)
{
	if(obb.style.opacity)
	{
		x = obb.style.opacity;
		//DO NOT return x here, or IE will fail to execute!
	}
	if(obb.filters) //WILL NOT WORK IN IE6-
	{
		x = obb.filters.alpha.opacity;
		return x;
	}
	if(obb.style.MozOpacity)
	{
		return obb.style.MozOpacity;
	}
	if(obb.style.KhtmlOpacity)
	{
		return obb.style.KhtmlOpacity;
	}
}
function getStyle_top(obb)
{
	var top = getStyle(obb, 'top');
	top = parseInt(top);
	return top;
}
function getStyle(obb, eStyle) //THIS FUNCTION WILL NOT WORK IN SAFARI v2-
{
	if(obb.currentStyle) //if IE
	{
		var y = obb.currentStyle[eStyle];
	}
	else if(window.getComputedStyle) //if Mozilla or Opera
	{
		var y = document.defaultView.getComputedStyle(obb,null).getPropertyValue(eStyle);
	}
	return y;
}


function preload()
{
	if(document.images)
	{
		var noshadowlight = new Image(182,32);
		noshadowlight.src = "psdcuts/nav/noshadowlight.gif";
		var noshadowdark = new Image(182,32);
		noshadowdark.src = "psdcuts/nav/noshadowdark.gif";
		
		var shadowlight = new Image(179,32);
		shadowlight.src = "psdcuts/nav/shadowlight.gif";
		var shadowdark = new Image(179,32);
		shadowdark.src = "psdcuts/nav/shadowdark.gif";
	}
	document.getElementById("nav").onmouseout = function(){startMtimer()}
	document.getElementById("nav").onmouseover = function(){stopMtimer()}
}