/********************************************
* Script for div content scrolling
* (C) SaZ, http://www.d-core.ru/ 
* Written on November 2006
********************************************/

//
// Variables initialization part
//

var ScrollingSpeed = 3; 	// to scroll up/down ScrollingSpeed px per tick
var SpeedAccel = 0;
var hScrollableText;		// getElementById handle - made for caching handles (IE specially)
var hScrollContainer;
var hArrowUp;				//
var hArrowDown;				//
var ScrollTimer;			// browser timer handle - made for ability to STOP scrolling :)

var imgDownHover = new Image(); // Made for image cache to prevent idiotic download progress bar
var imgUpHover = new Image();   // flashing in Opera

//imgDownHover.src = '/img/' + Prefix + '/down_hover.jpg';
//imgUpHover.src = '/img/' + Prefix + '/up_hover.jpg';

function InitHandles()
{
	hScrollableText = document.getElementById("ScrollableText");
	hScrollContainer = document.getElementById("ScrollContainer");
	hArrowUp = document.getElementById("arrow_up");
	hArrowDown = document.getElementById("arrow_down");
	
	RegisterEventHandler (hArrowDown, 'mousemove', SetSpeed);
	//RegisterEventHandler (hArrowUp, 'mousemove', SetBackSpeed);
}

function RegisterEventHandler (object, eventName, handler)
{
	if (object.attachEvent) 
		object.attachEvent ('on' + eventName, handler);
	else if (object.addEventListener)
		object.addEventListener (eventName, handler, true);
}

function GetContentHeight()
{
	return parseInt(hScrollableText.offsetWidth);
}

function GetContainerWidth()
{
	return parseInt(hScrollContainer.offsetWidth);
}

//
// Scrolling Down part - functions, handling text scrolling down
//

function StartScrollingDown(event)
{
	ScrollTimer = setTimeout("ScrollDown()", 20);
	//hArrowDown.style.backgroundImage = "url('/img/" + Prefix + "/down_hover.jpg')";
}

function SetSpeed(event)
{
	if (window.event) event = window.event;	
	
	//SpeedAccel = event.layerX;
}

function SetBackSpeed(event)
{
	if (window.event) event = window.event;	
	
	//SpeedAccel = 37 - event.layerX;
}

function StopScrollingDown()
{
	clearTimeout(ScrollTimer);
	//hArrowDown.style.backgroundImage = "url('/img/" + Prefix + "/down.jpg')";
}

function ScrollDown()
{
	var ContentTop = parseInt(hScrollableText.style.left);
	if (ContentTop == 'NaN' || isNaN(ContentTop))
		ContentTop = 0;
		
	if (ContentTop >= GetContentHeight() * (-1) + GetContainerWidth() + 74)
		hScrollableText.style.left = ContentTop - (ScrollingSpeed + SpeedAccel) + 'px';
		
	ScrollTimer = setTimeout("ScrollDown()", 20);
}

//
// Scrolling Up part - functions, handling text scrolling up
//

function StartScrollingUp()
{
	ScrollTimer = setTimeout("ScrollUp()", 20);
	//hArrowUp.style.backgroundImage = "url('/img/" + Prefix + "/up_hover.jpg')";
}

function StopScrollingUp()
{
	clearTimeout(ScrollTimer);
	//hArrowUp.style.backgroundImage = "url('/img/" + Prefix + "/up.jpg')";
}

function ScrollUp()
{
	var ContentTop = parseInt(hScrollableText.style.left);
	if (ContentTop == 'NaN' || isNaN(ContentTop))
		ContentTop = 0;
		
	if (ContentTop < 0)
		hScrollableText.style.left = ContentTop + (ScrollingSpeed + SpeedAccel) + 'px';
		
	ScrollTimer = setTimeout("ScrollUp()", 20);
}