/***********************************************************************
The following code is based on and including code originally created by
Travis Beckam of http://www.squidfingers.com | http://www.podlob.com
and Shaun Inman of http://www.shauninman.com
***********************************************************************/
UF.ScrollWin = {
	onbeforeload : function()
	{
		if (!document.getElementsByTagName) return;
		var navigation = document.getElementById('nav');
		// Opera doesn't get the scoll feature at the moment
		if (window.opera)
		{
			return;
		}
		var anks = navigation.getElementsByTagName("a");
		var anksLength = anks.length;
		for (var i=0; i<anksLength; i++)
		{
			var a =  anks[i];
			a.onclick = function ()
			{
				UF.ScrollWin.Scroll.to(this.href.replace(/^[^#]*#/,''));
				return false;
			}
		}
		var main = document.getElementById('main-column');
		var topLinks = main.getElementsByTagName("ul");
		var topLinksLength = topLinks.length;
		for (var j=0; j<topLinksLength; j++)
		{
			var thisLink = topLinks[j];
			if(thisLink.className == "top-link")
			{
				thisLink.className += " no-show";
			}
		}
		/////////////////////////////////////////////////////////
		if (ie == 1){
			window.onscroll = function () {
				navigation.style.paddingTop = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			}
		}
	},
	Scroll	: {
		scrollLoop 		: false, 
		scrollInterval	: null,
		getWindowHeight	: function() 
		{
			if (document.all)
			{
				return (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight; 
			}
			else
			{
				return window.innerHeight; 
			}
		},
		getScrollLeft	: function() 
		{
			if (document.all)
			{
				return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			}
			else 
			{
				return window.pageXOffset; 
			}
		},
		getScrollTop	: function() 
		{
			if (document.all)
			{
				return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; 
			}
			else
			{
				return window.pageYOffset;
			}
		},
		getElementYpos	: function(el)
		{
			var y = 0;
			while(el.offsetParent)
			{
				y += el.offsetTop
				el = el.offsetParent;
			}
			return y;
		},
		to : function(id)
		{
			if(this.scrollLoop)
			{
				clearInterval(this.scrollInterval);
				this.scrollLoop = false;
				this.scrollInterval = null;
			}
			var container = document.getElementById('container');
			var documentHeight = this.getElementYpos(container) + container.offsetHeight;
			var windowHeight = this.getWindowHeight();
			var ypos = this.getElementYpos(document.getElementById(id));
			if(ypos > documentHeight - windowHeight)
			{
				ypos = documentHeight - windowHeight;
			}
			this.scrollTo(0,ypos);
		},
		scrollTo : function(x,y)
		{
			if(this.scrollLoop)
			{
				var left = this.getScrollLeft();
				var top = this.getScrollTop();
				if(Math.abs(left-x) <= 1 && Math.abs(top-y) <= 1)
				{
					window.scrollTo(x,y);
					clearInterval(this.scrollInterval);
					this.scrollLoop = false;
					this.scrollInterval = null;
				}
				else
				{
					window.scrollTo(left+(x-left)/2, top+(y-top)/2);
				}
			}
			else
			{
				this.scrollInterval = setInterval("UF.ScrollWin.Scroll.scrollTo("+x+","+y+")",100);
				this.scrollLoop = true;
			}
		}
	}
}