var speed = 5;
var speed2 = 4;

var scrollHeight;
var scrollWidth;

var dom = document.getElementById ? true : false;
var nn4 = document.layers ? true : false;
var ie4 = document.all ? true : false;

var timer = setTimeout("", 20);
var timer2 = setTimeout("", 50);

var contentY;
var contentHeight;
var contentClipHeight;

var cl;
var locationX
var locationWidth;
var locationClipWidth;
var direction = -1;
function getY()
{
	if (ie4)
		contentY = document.all.content.style.pixelTop;
	else if (nn4)
		contentY = document.contentClip.document.content.top;
	else if (dom)
		contentY = parseInt(document.getElementById("content").style.top);
}

function getX()
{
	if (!cl)
		return;
	if (ie4)
		locationX = document.all.cl.style.pixelLeft;
	else if (nn4)
		locationX = document.clclip.document.cl.left;
	else if (dom)
		locationX = parseInt(document.getElementById("cl").style.left);
}

function up(e)
{
	clearTimeout(timer);
	return true;
}


function moveTo()
{
	if (dom)
	{
		document.getElementById("content").style.top = contentY + "px";
	}
	else if (ie4)
	{
		document.all.content.style.top = contentY;
	}
	else if (nn4)
	{
		document.contentClip.document.content.top = contentY;
	}
}

function scrollUp()
{
	getY();
	if (contentY < 0)
	{
		contentY = contentY + speed;
		if (contentY > 0)
			contentY = 0;

		moveTo();
		timer = setTimeout("scrollUp()", 1);
	}
	return false;
}

function scrollDown()
{
	getY();

	if (contentY > -(contentHeight - contentClipHeight))
	{
		contentY = contentY - speed;
		if (contentY < -(contentHeight - contentClipHeight))
			contentY = -(contentHeight - contentClipHeight);

		timer = setTimeout("scrollDown()", 1);
	}

	moveTo();
	return false;
}

function reloadPage()
{
	location.reload();
}

function doLocationScroll()
{
	if (!cl)
		return;
	getX();
	locationX += (direction * speed2);

	if (locationX < -(locationWidth - locationClipWidth))
	{
		direction = +1;
		timer2 = setTimeout("doLocationScroll()", 2000);
		return;
	}
	if (locationX > 0)
	{
		direction= -1;
		timer2 = setTimeout("doLocationScroll()", 2000);
		return;
	}

	if (dom)
	{
		document.getElementById("cl").style.left = locationX + "px";
	}
	else if (ie4)
	{
		document.all.cl.style.left = locationX;
	}
	else if (nn4)
	{
		document.clclip.document.cl.left = locationX;
	}

	timer2 = setTimeout("doLocationScroll()", 200);
}

function init()
{
	cl = document.getElementById("cl")
	if (window.opera && cl)
	{
		document.getElementById('cl').style.position = 'absolute';
	}
	if (dom)
	{
		contentHeight = parseInt(document.getElementById("content").offsetHeight);
		document.getElementById("content").style.top = 0 + "px";
		contentClipHeight = parseInt(document.getElementById("contentClip").offsetHeight);
		if(cl)
		{
			locationWidth = parseInt(document.getElementById("cl").offsetWidth);
			document.getElementById("cl").style.left = 0 + "px";
			locationClipWidth = parseInt(document.getElementById("clclip").offsetWidth);
		}
	}
	else if (ie4)
	{
		contentHeight = parseInt(document.all.content.scrollHeight);
		contentClipHeight = parseInt(document.all.contentClip.scrollHeight);
		locationWidth = parseInt(document.all.currentlocation.scrollWidth);
		locationClipWidth = parseInt(document.all.clclip.scrollWidth);
	}
	else if (nn4)
	{
		contentHeight = document.contentClip.document.content.bottom;
		contentClipHeight = document.contentClip.document.contentClip.bottom;
		locationWidth = document.bottombar.document.currentlocation.right;
		locationClipHeight = 640;
	}
	if (nn4)
	{
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}

	if (contentHeight > contentClipHeight)
	{
		document.getElementById("scrollArea").style.visibility = "visible";
	}

	if ((locationWidth > locationClipWidth) && cl)
	{
		timer2 = setTimeout("doLocationScroll()", 2000);
	}
}
