/**
* @version      $Id: horizontal.js v 1.1
* @package      My RSS Reader - Scrolling News
* @copyright    Copyright (C) 2010 FalsinSoft. All rights reserved.
* @license      GNU/GPL2
* @website      http://www.falsinsoft.co.nr
* @email        falsinsoft@gmail.com
* 
*/

function HorizontalScroller()
{
	this.NewsScrollingContainer = null;
	this.NewsScrollingControl   = null;
	this.ScrollerHeight = 0;
	this.ScrollingSpeed = 0;
	this.ScrollRightToLeft = true;
	this.BackgroundColor = "";
	this.TextColor = "";
	this.BorderColor = "";
	this.BorderSize = 0;
	this.NewsLine = "";
	this.ID = 0;
}

HorizontalScroller.prototype.ShowScroller = function()
{
	var DivCssStyle    = "width:100%;height:"+this.ScrollerHeight+"px;position:relative;overflow:hidden;";
	var TableCssStyle  = "width:100%;padding:2px;";

	if(this.BackgroundColor != "") TableCssStyle += 'background-color:'+this.BackgroundColor+';';
	if(this.TextColor != "") 
	{
		TableCssStyle += 'color:'+this.TextColor+';';
		document.write('<style type="text/css">table.Scroller'+this.ID+' a:link, table.Scroller'+this.ID+' a:visited, table.Scroller'+this.ID+' a:active {color:'+this.TextColor+';}</style>'); 
	}
	if(this.BorderSize > 0)
	{
		TableCssStyle += "border-width:"+this.BorderSize+"px; border-style:solid;";
		if(this.BorderColor != "") TableCssStyle += "border-color:"+this.BorderColor+";";
	}

	document.write('<table id="myrssreader_scrolling_news_container_'+this.ID+'" border="0" cellspacing="0" cellpadding="0" style="'+TableCssStyle+'" class="Scroller'+this.ID+'"><td>');
	document.write('<div style="'+DivCssStyle+'" onMouseover="Scroller'+this.ID+'.ScrollingSpeed=0;" onMouseout="Scroller'+this.ID+'.ScrollingSpeed='+this.ScrollingSpeed+';">');
	document.write('<div id="myrssreader_scrolling_news_'+this.ID+'" style="position:absolute; left:0px; top:0px;">');
	document.write('<nobr>'+this.NewsLine+'</nobr>');
	document.write('</div></div>');
	document.write('</td></table>');
	
	this.StartScrolling();
}

HorizontalScroller.prototype.StartScrolling = function()
{
	this.NewsScrollingContainer = document.getElementById("myrssreader_scrolling_news_container_"+this.ID);
	this.NewsScrollingControl   = document.getElementById("myrssreader_scrolling_news_"+this.ID);
	var ScrollerInstance = this;
	
	if(this.ScrollRightToLeft == true)
		this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingContainer.offsetWidth) + 10 + "px";
	else
		this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingControl.offsetWidth) * (-1) + 10 + "px";

	self.setInterval(function(){ScrollerInstance.ScrollNews()}, 20);
}

HorizontalScroller.prototype.ScrollNews = function()
{
	if(this.ScrollRightToLeft == true)
	{
		if(parseInt(this.NewsScrollingControl.style.left) > (parseInt(this.NewsScrollingControl.offsetWidth) * (-1) + 10))
			this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingControl.style.left) - this.ScrollingSpeed + "px";
		else
			this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingContainer.offsetWidth) + 10 + "px";
	}
	else
	{
		if(parseInt(this.NewsScrollingControl.style.left) < (parseInt(this.NewsScrollingContainer.offsetWidth) + 10))
			this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingControl.style.left) + this.ScrollingSpeed + "px";
		else
			this.NewsScrollingControl.style.left = parseInt(this.NewsScrollingControl.offsetWidth) * (-1) + 10 + "px";
	}
}
