// Which way should the text go? (top | bottom)
var animationDirection = 'top';

// The speed of the animation (in miliseconds)
var animationSpeed = 10;

// The ratio to use in the animation (how many pixels to move the text at each call)
// Using a value lower than 1 causes the animation to stop
var animationRatio = 5;

// The images used to 'navigate'
var arrowsList = new Array(4);
arrowsList['top_active'] = mainWebsiteURL+'images/scroll_up_active.jpg';
arrowsList['top_inactive'] = mainWebsiteURL+'images/scroll_up.jpg';
arrowsList['bottom_active'] = mainWebsiteURL+'images/scroll_down_active.jpg';
arrowsList['bottom_inactive'] = mainWebsiteURL+'images/scroll_down.jpg';

/*---------------------------------------------------------*/
/*														   */
/* INTERNAL STUFF - DON'T MODIFY ANYTHING BELOW THIS LINE! */
/*														   */
/*---------------------------------------------------------*/
// Define our internal variables
var mainContainer = null; 		// the main container
var messagesContainer = null; 	// the container of the messages (inside the mainContainer)
var timer = null; 				// the timer used throughout the script
var totalLength = 0;			// the length of the messagesContainer

// Go: bottom
function xanimatebottom()
{
	// We're at the end, reset the animation back to the beginning
	if( parseInt(messagesContainer.style.top) == 0 )
	{
		clearTimeout(timer);
	}
	else
	{
		// Set the new position
		messagesContainer.style.top = ( parseInt(messagesContainer.style.top) + animationRatio ) + 'px';
		
		// Continue...
		timer = setTimeout(xanimatebottom, animationSpeed);
	}
}

// Go: top
function xanimatetop()
{
	// We're at the end, reset the animation back to the beginning
	if( parseInt(messagesContainer.style.top) <= ( -totalLength + 160 ) )
	{
		clearTimeout(timer);
	}
	else
	{
		// Set the new position
		messagesContainer.style.top = ( parseInt(messagesContainer.style.top) - animationRatio ) + 'px';
		
		// Continue...
		timer = setTimeout(xanimatetop, animationSpeed);
	}
}

// Pauses the animation on the mouseover event
function xPause()
{
	if( timer )
	{
		clearTimeout(timer);
	}
}

// Resumes the animation
function xResume( startAnimation )
{
	// The direction of the animation was...
	if( startAnimation == 'bottom' && parseInt(messagesContainer.style.top) >= ( -totalLength + 160 ) )
	{
		// Resume the animation
		timer = setTimeout( xanimatetop, animationSpeed );
	}
	else if( startAnimation == 'top' && parseInt(messagesContainer.style.top) != 0 )
	{
		// Resume the animation
		timer = setTimeout( xanimatebottom, animationSpeed );
	}
	else
	{
		xPause();
	}
}

// Swaps an arrow
function xChangeArrow( imageName, imageSource )
{
	document[imageName].src = imageSource;
}

function xinit(mainCont, messageCont)
{
	// Get the main container
	mainContainer = document.getElementById(mainCont);
	
	// Get the destination container, its length, set the current position and start the animation
	messagesContainer = document.getElementById(messageCont);
	totalLength = messagesContainer.offsetHeight;
	messagesContainer.style.top = '0px';
	
	xPause();
	
}