/* ------------------------------------ hgRoll ------------------------------//
	create : 2006.08
	version : 0.9.0
	use : °³ÀÎÈ­ ¸Þ¼¼Áö
	by hong
	
	<div width=300 id='rollDivName'></div>
	<script>
	var hgRollName = new HgRoll();
	hgRoll.name = 'hgRollName';
	hgRoll.divId = 'rollDivName';
	hgRoll.width = 300;
	hgRoll.directiontype = 0; // (0:¼öÆò, 1:¼öÁ÷)
	hgRoll.direction = 1; //(1:¾Æ·¡ or ¿À¸¥ÂÊ -1:À§ or ¿ÞÂÊ)
	hgRoll.hor_speed = 30; // ¼öÆò ÀÌµ¿ ¼Óµµ
	hgRoll.pause = 3000; // ¸ØÃã ½Ã°£
	
	hgRoll.add('roll message 1');
	hgRoll.add('roll message 2');
	hgRoll.add('roll message 3');
	hgRoll.display();
	hgRoll.start();
	</script>
// --------------------------------------------------------------------------*/

var HgRoll = function(){
	this.timer;
	this.name = 'hgRoll';
	this.item = new Array();
	this.itemcnt = 0;
	this.divId = 'rollDiv';
	this.width = 250;
	this.height = 16;
	this.ver_speed = 30;
	this.hor_speed = 20;
	this.pause = 5000;
	this.directiontype = 1;
	this.direction = -1;
	this.stop = false;
	
	this.add = function(){
		var text = arguments[0];
		this.item[this.itemcnt] = text;
		this.itemcnt = this.itemcnt+1;
	}
	
	this.getDirection = function(){
		if(this.direction!=1&&this.direction!=-1){
			this.direction = 1;
		}
		return this.direction;
	}
	
	this.display = function(){
		var htmlC = '';
		
		htmlC = htmlC + '<div id="privatemsg" style="width:'+this.width+'px;height:'+this.height+'px;position:relative;overflow:hidden;" onmouseover="'+this.name+'.stop=true;" onmouseout="'+this.name+'.stop=false;">'
		for(var i=0;i<this.itemcnt;i++){
			if(this.directiontype==0){
				var left_pos = (i*this.width*(-1*this.getDirection()));
				htmlC = htmlC + '<div id="pmsg'+i+'" style="left:'+left_pos+'px;top:0px;width:'+this.width+'px;height:'+this.height+'px;position:absolute;overflow:hidden">'+this.item[i]+'</div>';
			}else{
				var top_pos = (i*this.height*(-1*this.getDirection()));
				htmlC = htmlC + '<div id="pmsg'+i+'" style="left:0px;top:'+top_pos+'px;width:'+this.width+'px;height:'+this.height+'px;position:absolute;overflow:hidden">'+this.item[i]+'</div>';
			}
		}
		htmlC = htmlC+'</div>'
		
		document.getElementById(this.divId).innerHTML=htmlC;
	}
	
	this.start = function() {
		setTimeout(this.name+'.rollmsg();',this.pause);
	}
	
	this.rollmsg = function() {
		
		if(this.itemcnt<2) return;
		
		var delay = 1;
		var isDelay = false;
		
		
		for(var i=0;i<this.itemcnt;i++){
			if(this.stop) break;
			sty = document.getElementById("pmsg"+(i)).style;
			if(this.directiontype==0){
				sty.left = parseInt(sty.left) + (1*this.getDirection());
				if(parseInt(sty.left)==((this.width-1)*this.getDirection())){ 
					isDelay=true;
					sty.left=parseInt(sty.left) + (this.width*this.itemcnt);
				}
			}else{
				sty.top = parseInt(sty.top) + (1*this.getDirection());
				if(parseInt(sty.top)==((this.height-1)*this.getDirection())){ 
					isDelay=true;
					sty.top=parseInt(sty.top) + (this.height*this.itemcnt);
				}
			}
		}
		if(isDelay) delay = this.pause;
		else delay = (this.directiontype==0)?this.hor_speed:this.ver_speed;
		
		this.timer = setTimeout(this.name+'.rollmsg();',delay);
	}		
}
