/**
* Creates an object that handles the scrolling of the homepage news box
*/
function ScrollingNews()
	{
	// Step 1. Define Properties

	news = this;

	this.newsTimer = null;
	this.newsHeight = 0;
	this.newsPos = 0;
	this.newsPaused = false;



	// Step 2. Define Methods

	/**
	* Sets up the news box
	*/
	this.init = function()
		{
		// Get the container for the initial content
		var tile = document.getElementById('wrapper').getElementsByTagName('div')[0];

		// Calculate the number times we need to repeat the initial content to fill the news box twice
		var duplicates = Math.ceil(document.getElementById('scrollingNewsContent').offsetHeight / tile.offsetHeight) * 2;
		if (duplicates < 2)
			{
			// duplicates must be an even number greater than zero
			duplicates = 2;
			}

		// Duplicate the initial content
		for (var x = 0; x < duplicates; x++)
			{
			document.getElementById('wrapper').appendChild( tile.cloneNode(true) );
			}

		// Add event handlers to container div
		document.getElementById('wrapper').onmouseover = __eventHandlerNewsOver;
		document.getElementById('wrapper').onmouseout = __eventHandlerNewsOut;

		// Store the news content height
		this.newsHeight = tile.offsetHeight * duplicates / 2;

		// Start the animation
		this.newsTimer = setInterval("news.scrollNews();", 40);
		}


	/**
	* Scrolls the news content
	*/
	this.scrollNews = function()
		{
		// Check if the scrolling has been paused, due to mouse over
		if (news.newsPaused === true)
			{
			return;
			}

		// Calculate the new scroll position
		news.newsPos+=1;
		if (news.newsHeight < news.newsPos)
			{
			news.newsPos = 0;
			}

		// Scroll the image
		document.getElementById('wrapper').style.top = (news.newsPos*-1) + 'px';
		}



	// Step 3. Define Private Methods

	/**
	* Event Handler: Mouse over the news content
	*/
	function __eventHandlerNewsOver()
		{
		news.newsPaused = true;
		}


	/**
	* Event Handler: Mouse out of the news content
	*/
	function __eventHandlerNewsOut()
		{
		news.newsPaused = false;
		}



	// Step 4. Initialize class
	this.init();
	}