
// ¿©·¯°³ÀÇ ¸®½ºÆ®¸¦ ºÎµå·´°Ô ·Ñ¸µ
// ÀÛ¼ºÀÚ : ÀÌÃ¢¿ë (v 0.9)
/* 
 * params
 * className		: °´Ã¼ »ý¼º½Ã °´Ã¼¸í
 * _objID			: ¸®½ºÆ®µÉ ¾ÆÀÌÅÛµéÀÇ ·¹ÀÌ¾î ID°ª
 * _width			: ¸®½ºÆ®ÀüÃ¼ width
 * _height			: ¸®½ºÆ®ÀüÃ¼ height
 * _size			: ·Ñ¸µµÉ ¾ÆÀÌÅÛÇÏ³ªÀÇ Å©±â(·Ñ¸µ±âÁØ ÁÂ¿ìÃøÀº width À§¾Æ·¡´Â height)  
 * _pixel			: ·Ñ¸µ½Ã ¿òÁ÷ÀÏ ÇÈ¼¿¼ö			 
 * _speed			: ·Ñ¸µ½Ã°£	//¿©±â±îÁö ÇÊ¼ö
 * [_direction]		: ·Ñ¸µ ¹æÇâ	(±âº»°ªleft)
 * [_movespeed]	    : ÀÌµ¿¹öÆ° Å¬¸¯½Ã ¿òÁ÷ÀÏ ¼Óµµ	(±âº»°ª10)
*/
	rollItem=function(className, _objID, _width, _height, _size, _pixel, _speed, _direction, _movespeed)	{

		//°øÅë »ç¿ëº¯¼ö
		this.className=className;		//»ý¼ºµÉ °´Ã¼¸í
		this.r_direction;				//·Ñ¸µ¹æÇâ
		this.r_start=1;					//½ÃÀÛ ¾ÆÀÌÅÛ¹øÈ£
		this.r_cid;						//Å¸ÀÓÇÔ¼ö ID
		this.r_objID=_objID;;	 		//¾ÆÀÌÅÛ ·¹ÀÌ¾î
		this.r_width=0;					//ÀüÃ¼ width
		this.r_height=0;				//ÀüÃ¼ height
		this.r_size=0;					//¾ÆÀÌÅÛ size
		this.r_pixel=1;					//½ºÅ©·ÑµÉ ÇÈ¼¿¼ö
		this.r_speed=5;					//½ºÅ©·ÑµÉ ½ºÇÇµå
		this.sr_outerframe=null;
		this.sr_innerframe=null;
		this.oversize=0;
		this.movestart=0;
		this.movedirection="left";		//ÀÌµ¿¹öÆ°¿ë ¹æÇâ
		this.defaultxy=0;
		this.rollCnt=0;
		this.movebase=10;
		this.r_direction="left";
		//·Ñ¸µ ÃÊ±âÈ­
		if(_direction)													this.r_direction=_direction;
		if(_movespeed>0&&!isNaN(_movespeed))			this.movebase=_movespeed;
		if(_pixel>0&&!isNaN(_pixel))							this.r_pixel=_pixel;
		if(_speed>0&&!isNaN(_speed))						this.r_speed=_speed;
		document.write("<div id='"+this.r_objID+"' style='display:none'></div>");		
		document.write("<div id='"+this.r_objID+"' style='display:none'></div>");			
		this.innerOBJ = eval("document.all."+this.r_objID);	
		this.length=this.innerOBJ.length-2;

		this.r_width=_width;
		this.r_height=_height;
		this.r_size=_size;
		this.r_pixel=_pixel;
		this.r_speed=_speed;
		if(this.length==0)	{
			this.oversize=0;
		}	else	{
			this.oversize=Math.ceil(this.r_width/this.r_size);
		}
		this.defaultxy=-(( this.oversize)*this.r_size);
		

 
		this.rollCnt=this.defaultxy;
		document.write("<div id='sr_outerframe"+this.className+"' style='overflow:hidden;border-width:0px;border-style:solid;vertical-align:bottom;'><div id='sr_innerframe"+this.className+"' style='position:relative;overflow:hidden;border-width:0px;border-style:solid;'></div></div>");
	    this.sr_outerframe = eval("document.all.sr_outerframe"+this.className);
		this.sr_innerframe = eval("document.all.sr_innerframe"+this.className);

		with (this.sr_outerframe.style) {
			width	= this.r_width	+"px";
			height	= this.r_height	+"px";
		}
 
		with (this.sr_innerframe.style) {
 
			if(this.r_direction=="left"||this.r_direction=="right")	{
				width	=this.r_size*(this.length+(this.oversize*2))+"px";
				left	=this.defaultxy;
				
				height	=this.r_height;
				top		= 0;		
			}	else if(this.r_direction=="up"||this.r_direction=="down")	{
				width	=this.r_width;
				left	=0
				height	=this.r_size*(this.length+(this.oversize*2))+"px";
				top		= this.defaultxy;
			}	 
	}
	
	//·Ñ¸µ½ÃÀÛ
	rollItem.prototype.rollingStart=function(startFlag)	{			
		if(startFlag!=false)	{
	 		this.printAllLayer();	
		}
	    this.r_cid = setInterval(this.className+".move()", this.r_speed);
	}
	//·Ñ¸µ¸ØÃã
	rollItem.prototype.rollingStop=function()	{
		clearTimeout(this.r_cid);
	}
	//·Ñ¸µ ºÎºÐ
	rollItem.prototype.move=function()	{
			var movepixel,movedirection;
			if(this.movestart>0)	 {
				movepixel=this.movebase;
				movedirection=this.movedirection;
				this.movestart-=this.movebase;
			}	else	{
				movepixel=this.r_pixel;
				movedirection=this.r_direction;
			}
			var currentstatus=Math.abs(this.rollCnt);
			var maxstatus= (this.length+this.oversize)*this.r_size;
			if(movedirection=="left"||movedirection=="up")	{
				if(currentstatus>=maxstatus)	{
					 this.rollCnt=this.defaultxy;
				}
				this.rollCnt-=movepixel;
			}else  if(movedirection=="right"||movedirection=="down")	{
 				if(currentstatus<=Math.abs(this.defaultxy))	{
					this.rollCnt=-(Math.abs(this.defaultxy)+(this.length*this.r_size));
				}
				this.rollCnt+=movepixel;		
			}
			if(movedirection=="left"||movedirection=="right")	{
				this.sr_innerframe.style.left=this.rollCnt;
			}	else	{
				this.sr_innerframe.style.top=this.rollCnt;
			}
			if(this.rollCnt!=0 &&this.rollCnt%this.r_size==0)	{
				clearTimeout(this.r_cid);
				this.r_cid=setTimeout(this.className+".rollingStart(false)",400);
			}
	}
	//¾ÆÀÌÅÛÀÌµ¿
	rollItem.prototype.moveImg=function(direction,cnt)	{
		this.movedirection=direction;
		if(cnt>0&&!isNaN(cnt))	 {
			this.movestart=(this.r_size*cnt);
		}	else	{
			this.movestart=this.r_size;
		}
	} 
	//·Ñ¸µ ¾ÆÀÌÅÛ Ãâ·Â

	rollItem.prototype.printAllLayer=function()	{
		var html="";
		if(this.r_direction=="up"||this.r_direction=="down") 	html+="<table border='0' cellpadding='0' cellspacing='0'  cellspacing='0' cellpadding='0' onMouseover='" + this.className + ".rollingStop()' onMouseout='" + this.className + ".rollingStart(false)'>";		
		else						html+="<table border='0' cellpadding='0' cellspacing='0'  cellspacing='0' cellpadding='0' onMouseover='" + this.className + ".rollingStop()' onMouseout='" + this.className + ".rollingStart(false)'><tr>";
		for(i=0-this.oversize;i<this.length+this.oversize;i++)	{ 
			if(i>=0)
				imgcnt=i%this.length;
			else	
				imgcnt=(this.length-1)-(Math.abs(i))%this.length;
			if(this.r_direction=="up"||this.r_direction=="down") 	html += "<tr><td  style='overflow:hidden'>" + this.innerOBJ[imgcnt].innerHTML + "</td>";
			else 						html += "<td  style='overflow:hidden'>" + this.innerOBJ[imgcnt].innerHTML + "</td>";		 
		}
		if(this.r_direction=="up"||this.r_direction=="down")		html+="</table>";
		else							html+="</tr></table>"
		html="<div  >"+html;
		html=html+"</div>";

		this.sr_innerframe.innerHTML=html;
	}
}
