/*	[MHz.Effect.RollingText.js]
 *  (c) 2006, 2007 MHZ. (http://www.mediamob.co.kr // http://www.openblog.com)
 *	reference >> prototype.js // 
 *	Last Update : 2007.02.05  Pang
 *
 *	How to use ?
 *	---------------------------------------------------------------------------
 *	+ <script src="./lib/prototype/prototype.js" type="text/javascript"></script>
 * + <script> new RollingText(arr, $('RollingLayer')); </script>
 * + Ã¹¹øÂ° ÆÄ¶ó¹ÌÅÍ´Â ¹è¿­°ª, µÎ¹øÂ° ÆÄ¶ó¹ÌÅÍ´Â º¸¿©ÁÙ ·¹ÀÌ¾î
 * + ¿É¼Ç°ªÀ¸·Î duration / directionÀ» ¹Þ´Â´Ù. [directionºÎºÐ ¹Ì±¸Çö]
 * 
 *
 */

//<![CDATA[

var RollingText = Class.create();
RollingText.prototype = 
{
	initialize: function(element, elementLayer, options) 
	{
		this.element = new Array();
		this.element = $(element);		
		this.Layer = $(elementLayer);
		this.options = Object.extend({duration : '5', direction : 'up', viewcount: '1'}, options);
		
		this.duration = this.options.duration;
		this.direction = this.options.direction;
		this.viewcount = this.options.viewcount;
		if(this.direction == "up"){this.elementCount = this.element.length -1;}
		else{this.elementCount = 0;}
		
		this.Timer = new PeriodicalExecuter(this.rolling, this.duration);
		this.element.component = this;
		this.Timer.component = this;
		this.Layer.component = this;
		
		this.Init();
	},
	
	Init : function()
	{
		this.Layer.onmouseover = this.rollingStop;
		this.Layer.onmouseout = this.rollingStart;
		
		var temp = this.viewCount - 1;
		var html = "";
		
		// ÃÊ±â°ª
		for(i=0 ; i < this.viewcount ; i++)
		{
			html += this.element[i];			
		}
		
		this.Layer.innerHTML = html;
	},
	
	rollingStop : function()
	{
		this.component.Timer.stop();
	},
	
	rollingStart : function()
	{	
		this.component.Timer.registerCallback();
	},	
	
	rolling : function()
	{
		var html = "";
		
		if(this.component.direction == "up")
		{
			for(i=0 ; i < this.component.viewcount ; i++)
			{
				html += this.component.element[this.component.elementCount];
				
				if(this.component.elementCount == 0)
					this.component.elementCount = this.component.element.length - 1;
				else
					this.component.elementCount = this.component.elementCount - 1;
			}
		}
		else
		{
			for(i=0 ; i < this.component.viewcount ; i++)
			{
				html += this.component.element[this.component.elementCount];
				
				if(this.component.elementCount == this.component.element.length - 1)
					this.component.elementCount = 0;
				else
					this.component.elementCount = this.component.elementCount + 1;
			}
		}
		
		this.component.Layer.innerHTML = html;
	}
}

//]]>

