/**
* @version      $Id: vertical.js v 1.0
* @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 VerticalScroller()
{
	this.NewsScrollingContainer = null;
	this.NewsScrollingVisible   = null;
	this.NewsScrollingHidden    = null;
	this.ScrollingSpeed = 0;
	this.BackgroundColor = "";
	this.TextColor = "";
	this.BorderColor = "";
	this.BorderSize = 0;
	this.ScrollerHeight = 0;
	this.NewFeeds = new Array();
	this.StopScrolling = false;
	this.NewsMargin = 5;
	this.NewsIdx = 1;
	this.ID = 0;
}

VerticalScroller.prototype.ShowScroller = function()
{
	var DivCssStyle = 'width:100%;height:'+this.ScrollerHeight+'px;position:relative;overflow:hidden;';
	
	if(this.BackgroundColor != "") DivCssStyle += 'background-color:'+this.BackgroundColor+';';
	if(this.TextColor != "") 
	{
		DivCssStyle += 'color:'+this.TextColor+';';
		document.write('<style type="text/css">div.Scroller'+this.ID+' a:link, div.Scroller'+this.ID+' a:visited, div.Scroller'+this.ID+' a:active {color:'+this.TextColor+';}</style>'); 
	}
	if(this.BorderSize > 0)
	{
		DivCssStyle += "border-width:"+this.BorderSize+"px; border-style:solid;";
		if(this.BorderColor != "") DivCssStyle += "border-color:"+this.BorderColor+";";
	}
	
	document.write('<div id="myrssreader_scrolling_news_container_'+this.ID+'" style="'+DivCssStyle+'" onMouseover="Scroller'+this.ID+'.StopScrolling=true;" onMouseout="Scroller'+this.ID+'.StopScrolling=false;" class="Scroller'+this.ID+'">');
	document.write('<div class="innerDiv" style="position:absolute; width:100%; height:100%;" id="myrssreader_scrolling_news_visible_'+this.ID+'"></div>');
	document.write('<div class="innerDiv" style="position:absolute; width:100%; height:100%; visibility:hidden;" id="myrssreader_scrolling_news_hidden_'+this.ID+'"></div>');
	document.write('</div>');
	
	this.StartScrolling();
}

VerticalScroller.prototype.StartScrolling = function()
{
	this.NewsScrollingContainer = document.getElementById("myrssreader_scrolling_news_container_"+this.ID);
	this.NewsScrollingVisible   = document.getElementById("myrssreader_scrolling_news_visible_"+this.ID);
	this.NewsScrollingHidden    = document.getElementById("myrssreader_scrolling_news_hidden_"+this.ID);

	if(this.NewFeeds.length > 1)
	{
		var ScrollerInstance = this;
		
		this.NewsScrollingVisible.innerHTML = this.NewFeeds[0];
		this.NewsScrollingHidden.innerHTML  = this.NewFeeds[1];

		this.NewsScrollingVisible.style.margin = this.NewsScrollingHidden.style.margin = (this.NewsMargin + "px");
		this.NewsScrollingVisible.style.width = this.NewsScrollingHidden.style.width = (this.NewsScrollingContainer.offsetWidth - (this.NewsMargin * 2) + "px");
		
		this.GetInline(this.NewsScrollingVisible, this.NewsScrollingHidden);
		
		this.NewsScrollingHidden.style.visibility = "visible";
		
		setTimeout(function(){ScrollerInstance.ScrollingNewsUp()}, this.ScrollingSpeed)
	}
	else if(this.NewFeeds.length == 1)
	{
		this.NewsScrollingVisible.innerHTML = this.NewFeeds[0];
	}
}

VerticalScroller.prototype.GetInline = function(NewsDiv1, NewsDiv2)
{
	NewsDiv1.style.top = (this.NewsMargin + "px");
	NewsDiv2.style.top = (Math.max(NewsDiv1.parentNode.offsetHeight, NewsDiv1.offsetHeight) + "px");
}

VerticalScroller.prototype.SwapNewsDivs = function()
{
	var NewsScrollingSwap 	  = this.NewsScrollingVisible;
	this.NewsScrollingVisible = this.NewsScrollingHidden;
	this.NewsScrollingHidden  = NewsScrollingSwap;
}

VerticalScroller.prototype.SetNextNews = function()
{
	var ScrollerInstance = this;
	
	if(this.StopScrolling == true)
	{
		setTimeout(function(){ScrollerInstance.SetNextNews()}, 100);
	}
	else
	{
		this.NewsIdx++;
		if(this.NewsIdx >= this.NewFeeds.length) this.NewsIdx = 0;
		this.NewsScrollingHidden.innerHTML = this.NewFeeds[this.NewsIdx];
		setTimeout(function(){ScrollerInstance.ScrollingNewsUp()}, 10);
	}
}

VerticalScroller.prototype.ScrollingNewsUp = function()
{
	var ScrollerInstance = this;
	
	if(parseInt(this.NewsScrollingHidden.style.top) > (this.NewsMargin + 5))
	{
		this.NewsScrollingVisible.style.top = (parseInt(this.NewsScrollingVisible.style.top) - 5 + "px");
		this.NewsScrollingHidden.style.top  = (parseInt(this.NewsScrollingHidden.style.top) - 5 + "px");
		setTimeout(function(){ScrollerInstance.ScrollingNewsUp()}, 50);
	}
	else
	{
		this.GetInline(this.NewsScrollingHidden, this.NewsScrollingVisible);
		this.SwapNewsDivs();
		setTimeout(function(){ScrollerInstance.SetNextNews()}, this.ScrollingSpeed);
	}
}


