function RollingItem(key, objWindow, direct, delaySec, speed){
	this.key=key;
	this.direct=direct;
	this.pidTimer=null;
	this.nextSecond=0;
	this.startSecond=0;
	this.BlockLength=0;
	this.BlockPos=0;
	this.CellLength = new Array();
	delaySec = parseInt(delaySec, 10);
	if(isNaN(delaySec) || delaySec < 1){
		delaySec = 2;
	}
	delaySec*=1000;
	this.waitTime=delaySec;
	this.RollerPos=0;
	this.Roller = new Array();
	this.Roller[0] = objWindow.childNodes[0];
	this.Roller[1] = objWindow.childNodes[1];
	this.Roller[1].innerHTML=this.Roller[0].innerHTML;
	this.NowMoveLength=0;
	this.RollSpeed=speed;
	this.init();
}
RollingItem.prototype.init=function(){
	var objEles=null;
	switch(this.direct){
		case 6:case 12://¼¼·Î¹æÇâÀÌµ¿
			this.BlockLength=this.Roller[0].childNodes[0].clientHeight;
			break;
		case 3:case 9://°¡·Î¹æÇâÀÌµ¿
			this.BlockLength=this.Roller[0].childNodes[0].clientWidth;
			break;
	}

	if(this.BlockLength == 0){
		this.pidTimer=setTimeout("initRoller("+this.key+")", 100);
	}else{
		switch(this.direct){
			case 6:case 12://¼¼·Î¹æÇâÀÌµ¿
				objEles=this.Roller[0].childNodes[0].rows;
				for(var intCnt=0; intCnt<objEles.length; intCnt++){
					this.CellLength[intCnt] = objEles[intCnt].clientHeight;
				}
				break;
			case 3:case 9://°¡·Î¹æÇâÀÌµ¿
				objEles=this.Roller[0].childNodes[0].rows[0].cells;
				for(var intCnt=0; intCnt<objEles.length; intCnt++){
					this.CellLength[intCnt] = objEles[intCnt].clientWidth;
				}
				break;
		}
		switch(this.direct){
			case 6:this.Roller[1].style.pixelTop=-this.BlockLength;break;
			case 12:this.Roller[1].style.pixelTop=this.BlockLength;break;
			case 3:this.Roller[1].style.pixelLeft=-this.BlockLength;break;
			case 9:this.Roller[1].style.pixelLeft=this.BlockLength;break;
		}
		if(objEles.length==0) return;
		this.NowMoveLength=this.CellLength[this.RollerPos];
		this.pidTimer=setTimeout("rollingRoller("+this.key+")", 100);
	}
}

RollingItem.prototype.rolling=function(){
	var movePx=this.RollSpeed;
	var dtmNow = new Date();
	this.destory();
	if( this.CellLength.length < 2 ){
		//ÀÌµ¿ÇÒ ¼¿ÀÌ ÇÏ³ª¸¸ ÀÖÀ½ ·Ñ¸µ ºÒ°¡´É
		this.pidTimer=setTimeout("detorySelfRoller("+this.key+")", 300);
		return;
	}

	if( (this.NowMoveLength - movePx) <= 0 ){
		movePx=this.NowMoveLength;
		switch(this.direct){
			case 6:case 3:
				this.RollerPos--;
				if(this.RollerPos == 0){
					switch(this.direct){
						case 6:
							if(this.BlockPos==0){
								this.Roller[1].style.pixelTop=-(this.BlockLength+movePx);
							}else{
								this.Roller[0].style.pixelTop=-(this.BlockLength+movePx);
							}
							break;
						case 3:
							if(this.BlockPos==0){
								this.Roller[1].style.pixelLeft=-(this.BlockLength+movePx);
							}else{
								this.Roller[0].style.pixelLeft=-(this.BlockLength+movePx);
							}
							break;
					}
				}
				break;
			case 12:case 9:this.RollerPos++;break;
		}
		this.nextSecond=this.waitTime;
	}else{
		this.nextSecond=100;
	}

	switch(this.direct){
		case 6:
			this.Roller[0].style.pixelTop+=movePx;
			this.Roller[1].style.pixelTop+=movePx;
			break;
		case 12://¼¼·Î¹æÇâÀÌµ¿
			this.Roller[0].style.pixelTop-=movePx;
			this.Roller[1].style.pixelTop-=movePx;
			break;
		case 3:
			this.Roller[0].style.pixelLeft+=movePx;
			this.Roller[1].style.pixelLeft+=movePx;
			break;
		case 9://°¡·Î¹æÇâÀÌµ¿
			this.Roller[0].style.pixelLeft-=movePx;
			this.Roller[1].style.pixelLeft-=movePx;
			break;
	}
	this.NowMoveLength-=movePx;

	switch(this.direct){
		case 6:case 3:
			if(this.RollerPos<0){
				if(this.BlockPos==0){this.BlockPos=1;}else{this.BlockPos=0;}
				this.RollerPos = this.CellLength.length - 1;
			}
			break;
		case 12:case 9:
			if(this.RollerPos>=this.CellLength.length){
				switch(this.direct){
					case 12://¼¼·Î¹æÇâÀÌµ¿
						this.Roller[this.BlockPos].style.pixelTop=this.BlockLength;
						break;
					case 9://°¡·Î¹æÇâÀÌµ¿
						this.Roller[this.BlockPos].style.pixelLeft=this.BlockLength;
						break;
				}
				
				if(this.BlockPos==0){this.BlockPos=1;}else{this.BlockPos=0;}
				this.RollerPos = 0;
			}
			break;
	}

	if(this.NowMoveLength<=0){this.NowMoveLength=this.CellLength[this.RollerPos];}
	this.startSecond=dtmNow.getTime();
	this.pidTimer=setTimeout("rollingRoller("+this.key+")", this.nextSecond);
}
RollingItem.prototype.pause=function(){
	var dtmNow = new Date();
	if(this.pidTimer!=null){
		clearTimeout(this.pidTimer);
		this.pidTimer=null;
		this.nextSecond=this.nextSecond-(dtmNow.getTime()-this.startSecond);
		if(this.nextSecond<0) this.nextSecond = 0;
	}
}

RollingItem.prototype.restart=function(){
	var dtmNow = new Date();
	if(this.pidTimer!=null){
		clearTimeout(this.pidTimer);
		this.pidTimer=null;
		this.nextSecond=this.nextSecond-(dtmNow.getTime()-this.startSecond);
		if(this.nextSecond<0) this.nextSecond = 0;
	}
	this.startSecond=dtmNow.getTime();
	this.pidTimer=setTimeout("rollingRoller("+this.key+")", this.nextSecond);
}

RollingItem.prototype.destory=function(){
	if(this.pidTimer!=null){
		clearTimeout(this.pidTimer);
		this.pidTimer=null;
	}
}

function RollingControl(){
	this.items = new Array();
	//debug
	this.msg = "";
}

RollingControl.prototype.isExists=function(key){
	var intCnt=0;
	for(intCnt=0; intCnt<this.items.length; intCnt++){
		if(this.items[intCnt].key==key){
			break;
		}
	}
	if(intCnt<this.items.length){
		return true;
	}else{
		return false;
	}
}

RollingControl.prototype.getIndex=function(key){
	var intCnt=0;
	for(intCnt=0; intCnt<this.items.length; intCnt++){
		if(this.items[intCnt].key==key){
			break;
		}
	}
	if(intCnt<this.items.length){
		return intCnt;
	}else{
		return -1;
	}
}

RollingControl.prototype.setMassage=function(strMsg){
	this.msg=strMsg;
	//alert(strMsg);
}

RollingControl.prototype.pushItem=function(key, objWindow, direct, delaySec, speed){
	if(this.isExists(key)){this.setMassage("item push : ÀÌ¹Ìµî·ÏµÈ Key["+key+"]");return;};
	if(objWindow == null){this.setMassage("item push : ÀÌº¥Æ® °³Ã¼°¡ null");return;};
	if(objWindow == undefined){this.setMassage("item push : ÀÌº¥Æ® °³Ã¼°¡ undefined");return;};
	try{
		if(objWindow.childNodes.length<1){this.setMassage("item push : 1Â÷ ¾Ù¸®¸ÕÆ® 0°³ ÀÔ´Ï´Ù.["+objWindow.childNodes.length+"]");return;};
	}catch(e){
		this.setMassage("item push : 1Â÷ childNodeÁ¢±Ù¿¡·¯");return;
	}
	if(objWindow.childNodes[0].tagName!="TABLE"){this.setMassage("item push : 1Â÷ ¾Ù¸®¸ÕÆ® TABLE°¡ ¾Æ´Ô["+objWindow.childNodes[0].tagName+"]");return;};
	try{
		objWindow = objWindow.childNodes[0].rows[0].cells[0];
		if(objWindow.childNodes.length!=1){this.setMassage("item push : 1Â÷ ¾Ù¸®¸ÕÆ® 1°³°¡ ¾Æ´Ô["+objWindow.childNodes.length+"]");return;};
	}catch(e){
		this.setMassage("item push : 1Â÷ childNodeÁ¢±Ù¿¡·¯");return;
	}

	if(objWindow.childNodes[0].tagName!="DIV"){this.setMassage("item push : 1Â÷ ¾Ù¸®¸ÕÆ® DIV°¡ ¾Æ´Ô["+objWindow.childNodes[0].tagName+"]");return;};
	if(objWindow.childNodes[0].childNodes.length!=2){this.setMassage("item push : 2Â÷ ¾Ù¸®¸ÕÆ® 2°³°¡ ¾Æ´Ô["+objWindow.childNodes[0].childNodes.length+"]");return;};
	if(objWindow.childNodes[0].childNodes[0].tagName!="DIV"){this.setMassage("item push : 2Â÷ ¾Ù¸®¸ÕÆ® DIV°¡ ¾Æ´Ô["+objWindow.childNodes[0].childNodes[0].tagName+"]");return;};
	if(objWindow.childNodes[0].childNodes[1].tagName!="DIV"){this.setMassage("item push : 2Â÷ ¾Ù¸®¸ÕÆ® DIV°¡ ¾Æ´Ô["+objWindow.childNodes[0].childNodes[1].tagName+"]");return;};
	if(typeof(direct) != "number"){
		direct=parseInt(direct,10);
	}
	switch(direct){
		case 3:case 6:case 9:case 12:break;
		default:
			this.setMassage("item push : ¾Ë¼ö ¾ø´Â ÀÌµ¿¹æÇâ["+direct+"]");
			return;
	}
	speed=parseInt(speed,10);
	if(isNaN(speed) || speed < 1){
		speed = 8;
	}
	this.items.push(new RollingItem(key, objWindow.childNodes[0], direct, delaySec, speed));
}

RollingControl.prototype.popItem=function(key){
	var intCnt=0;
	for(intCnt=0; intCnt<this.items.length; intCnt++){
		if(this.items[intCnt].key==key){
			break;
		}
	}
	if(intCnt<this.items.length){
		this.items[intCnt].destory();
		this.items[intCnt]=null;
		this.items.splice(intCnt, 1);
	}
}
var objRoll = new RollingControl();

function initRoller(key){
	var intPos=objRoll.getIndex(key);
	if(intPos > -1){
		objRoll.items[intPos].init();
	}
}

function rollingRoller(key){
	var intPos=objRoll.getIndex(key);
	if(intPos > -1){
		objRoll.items[intPos].rolling();
	}
}

function pauseRoller(key){
	var intPos=objRoll.getIndex(key);
	if(intPos > -1){
		objRoll.items[intPos].pause();
	}
}

function restartRoller(key){
	var intPos=objRoll.getIndex(key);
	if(intPos > -1){
		objRoll.items[intPos].restart();
	}
}

function detorySelfRoller(key){
	objRoll.popItem(key);
}