//#################################################
// ½ºÅ©·Ñ 
//#################################################
function NewsTicker( Skin, DisplayCell, ArgvName, Elapse, MoveSpeed, ShowLength, MoveLength, MoveSize ){
	NewsTicker.Bases[NewsTicker.Bases.length] = this;
	this.BasesIndex = NewsTicker.Bases.length-1;
	this.Skin = Skin;
	this.DisplayCell = DisplayCell;
	this.DisplayCell.Ticker = this;
	this.ArgvName = ArgvName;

	this.DisplayCell.onmouseover = new Function( "this.Ticker.Stop();" );
	this.DisplayCell.onmouseout = new Function( "this.Ticker.MoveFlag = true; if( this.Ticker.ElapseTimer == null ){ this.Ticker.Move(); }" );

	if( Elapse ) this.Elapse = Elapse;
	if( MoveSpeed ) this.MoveSpeed = MoveSpeed;
	if( ShowLength ) this.ShowLength = ShowLength;
	if( MoveLength ) this.MoveLength = MoveLength;
	if( MoveSize ) this.MoveSize = MoveSize;
}

NewsTicker.prototype.Skin = null;
NewsTicker.prototype.DisplayCell = null;
NewsTicker.prototype.ArgvName = null;
NewsTicker.prototype.Elapse = 1000;			// ´ë±â½Ã°£
NewsTicker.prototype.MoveSpeed = 1;			// ½ºÅ©·Ñ µô·¹ÀÌ
NewsTicker.prototype.Skins = null;
NewsTicker.prototype.CurrentSkins = null;
NewsTicker.prototype.Current = 0;
NewsTicker.prototype.ShowLength = 5;		// ¹Ì¸® ÁØºñµÅ¾î ÀÖ¾î¾ßÇÒ ´ÙÀ½ ÇÁ·¹ÀÓ°¹¼ö
NewsTicker.prototype.MoveLength = 1;			// ÀÌµ¿ÇÒ ÇÁ·¹ÀÓ ¼ö
NewsTicker.prototype.MoveSize= 0;			// ÀÌµ¿ÇÒ ÇÈ¼¿ ¼ö
NewsTicker.Bases = [];
NewsTicker.prototype.BasesIndex = null;
NewsTicker.prototype.Timer = null;
NewsTicker.prototype.MoveFlag = true;

NewsTicker.prototype.Add = function(){
	var argv = arguments;
	var argc = arguments.length;
	if( argc == 0 ) return;
	if( this.Skins == null ) this.Skins = new Array();

	var newSkin = this.Skin.cloneNode( true );
	newSkin.style.display = "";
	this.Skins[this.Skins.length] = newSkin;

	for( var i=0; i<argc; i++ ){
		newSkin.all[this.ArgvName+"["+i+"]"].innerHTML = argv[i];
	}
}

NewsTicker.prototype.InitSkin = function(){
	if( this.CurrentSkins == null ) this.CurrentSkins = new Array();
	if( !this.Current ) this.Current = 0;

	if( this.ShowLength < this.MoveLength ) 
		this.MoveLength = this.ShowLength;
	
	if( this.CurrentSkins.length > 0 ){
		for( var i=0; i < this.MoveLength; i++ ){
			this.CurrentSkins[0].removeNode( true );
			this.CurrentSkins.shift();
		}
	}else{
		this.CurrentSkins = new Array();
	}

	for( var i=0; i<this.CurrentSkins.length; i++ ){
		this.CurrentSkins[i].style.pixelTop=0;	
	}
	
	var Latest = null;
	while( true ){
		if( this.Current > this.Skins.length-1 ) this.Current = 0;
		if( Latest == this.Current ) return;
		Latest = this.Current;
		this.CurrentSkins[this.CurrentSkins.length] = this.Skins[this.Current].cloneNode(true);
		this.DisplayCell.appendChild( this.CurrentSkins[this.CurrentSkins.length-1] ).style.pixelTop=0;
		this.Current++;
		if( this.CurrentSkins.length >= this.ShowLength*2 ) break;
	}
}

NewsTicker.prototype.Start = function(){
	
	if( this.Skins.length < this.ShowLength )
		return;
	
	this.InitSkin();

	this.ElapseTimer = setTimeout( "NewsTicker.Bases["+this.BasesIndex+"].Move();", this.Elapse );
}

NewsTicker.prototype.Stop = function(){
	clearTimeout( this.Timer );
	this.MoveFlag = false;
}

NewsTicker.prototype.Move = function(){
	this.ElapseTimer = null;

	if( !this.MoveFlag  ) return;

	if( this.CurrentSkins[this.MoveLength].offsetTop <= 0  ){
		this.Start();
		return;
	}
	
	var Pixel = 0;
	if( this.MoveSize == 0 )
		Pixel = this.CurrentSkins[this.MoveLength].offsetTop;
	else{
		if( (Pixel = this.CurrentSkins[this.MoveLength].offsetTop/this.MoveSize/2) < 1 ){
			Pixel = 1;
		}
	}

	for( var i=0; i<this.CurrentSkins.length; i++ ){
		this.CurrentSkins[i].style.pixelTop -= Pixel;
	}
	
	if( this.ElapseTimer == null )
		this.Timer = setTimeout( "NewsTicker.Bases["+this.BasesIndex+"].Move();", this.MoveSpeed );
}
