// Optimized on IE5.5 
// var EXCLASSNAME = new yjh_rolling(direction,totalWidth,totalHeight,itemWidth,itemHeight,speed,length,stoptime); 
// EXCLASSNAME.additem('¾ÆÀÌÅÛ ³»¿ë(html)');    <=input images
// EXCLASSNAME.insert();  <= insert item
// EXCLASSNAME.go();  <= before close body tag

window.yjh_rollingobj = new Array;
function yjh_rolling(){
	this.objindex = window.yjh_rollingobj.length;
	window.yjh_rollingobj[window.yjh_rollingobj.length] = this;
	this.spanp = new Object;
	this.spanc = new Object;
	this.items = new Array();
	this.debug = new Object;
	this.iswrited = false;

	this.direction		= arguments[0]?arguments[0]:"left";
	this.spanp.width	= arguments[1]?arguments[1]:"100%";
	this.spanp.height	= arguments[2]?arguments[2]:"100%";
	this.spanc.width	= arguments[3]?arguments[3]:"100%";
	this.spanc.height	= arguments[4]?arguments[4]:"100%";
	this.speed			= arguments[5]?arguments[5]:"20";
	this.speed2			= arguments[6]?arguments[6]:"1";
	this.stoptime		= arguments[7]?arguments[7]:0;
	
	this.direction = this.direction.toString().toLowerCase().replace(/(^\s*)|(\s*$)/g,"");
	this.direction = this.direction.replace(/(1)/,"left");
	this.direction = this.direction.replace(/(2)/,"right");
	this.direction = this.direction.replace(/(3)/,"top");
	this.direction = this.direction.replace(/(4)/,"bottom");
	if(!this.direction.match(/(left|right|top|bottom)/)) this.direction = "left";

	this.debug.background1 = "";
	this.debug.background2 = "";

	this.debug.start = function(){
		this.debug.background1 = "background:red;";
		this.debug.background2 = "background:blue;";
	}
	this.debug.stop = function(){
		this.debug.background1 = "";
		this.debug.background2 = "";
	}
	this.additem = function(html){
		this.items[this.items.length] = html;
	}
	this.insert = function(){
		var html = "";
		html += "<span id='yjh_spanp_"+this.objindex+"'  style='width:"+this.spanp.width+";height:"+this.spanp.height+";position:absolute;clip:rect(0 "+this.spanp.width+" "+this.spanp.height+" 0);"+this.debug.background1+"'>";
		html += "</span>";
		document.write(html);
	}
	this.write = function(){
		if(this.iswrited) return;

		var tmpobj = document.getElementById("yjh_spanp_"+this.objindex).parentNode;
		if(!this.spanp.width)								this.spanp.width	= tmpobj.clientWidth;
		if(!this.spanp.height)								this.spanp.height	= tmpobj.clientHeight;
		if(!this.spanc.width)								this.spanc.width	= tmpobj.clientWidth;
		if(!this.spanc.height)								this.spanc.height	= tmpobj.clientHeight;
		if(this.spanp.width.toString().indexOf("%")!=-1)	this.spanp.width	= tmpobj.clientWidth*parseInt(this.spanp.width)/100;
		if(this.spanp.height.toString().indexOf("%")!=-1)	this.spanp.height	= tmpobj.clientHeight*parseInt(this.spanp.height)/100;
		if(this.spanc.width.toString().indexOf("%")!=-1)	this.spanc.width	= tmpobj.clientWidth*parseInt(this.spanc.width)/100;
		if(this.spanc.height.toString().indexOf("%")!=-1)	this.spanc.height	= tmpobj.clientHeight*parseInt(this.spanc.height)/100;
		if(!this.items.length){alert("No results for rolling."); return false;}
		
		var html = "";
		for(var i=0;i<this.items.length;i++){
			if(this.direction=="left")	{var spanleft=this.spanc.width*i;var spantop=(this.spanp.height-this.spanc.height)/2;}
			if(this.direction=="right")	{var spanleft=this.spanp.width-this.spanc.width*(i+1);var spantop=(this.spanp.height-this.spanc.height)/2;}
			if(this.direction=="top")	{var spanleft=(this.spanp.width-this.spanc.width)/2;var spantop=this.spanc.height*i;}
			if(this.direction=="bottom"){var spanleft=(this.spanp.width-this.spanc.width)/2;var spantop=this.spanp.height-this.spanc.height*(i+1);}
			html += "<span id=yjh_spanc_"+this.objindex+"_"+i+" style='position:absolute;left:"+spanleft+";top:"+spantop+";width:"+this.spanc.width+";height:"+this.spanc.height+";"+this.debug.background2+"'>";
			html += "<table width="+this.spanc.width+" height="+this.spanc.height+" border=0 cellpadding=0 cellspacing=0><tr><td align=center  nowrap onmouseover='window.yjh_rollingobj["+this.objindex+"].stop(0)' onmouseout='window.yjh_rollingobj["+this.objindex+"].go()'>";
			html += this.items[i];
			html += "</td></tr></table>";
			html += "</span>";
		}
		document.getElementById("yjh_spanp_"+this.objindex).innerHTML = html;
		this.iswrited = true;
	}
	this.move = function(){
		var tmpobj;
		for(var i=0;i<this.items.length;i++){
			tmpobj = document.getElementById("yjh_spanc_"+this.objindex+"_"+i);
			if(this.direction=="left"){
				tmpobj.style.pixelLeft -= parseInt(this.speed2);
				if(tmpobj.style.pixelLeft <- this.spanc.width){
					tmpobj.style.pixelLeft = this.spanc.width * (this.items.length - 1);
					if(this.stoptime) this.stop(this.stoptime);
				}
			}
			if(this.direction=="right"){
				tmpobj.style.pixelLeft += parseInt(this.speed2);
				if(tmpobj.style.pixelLeft > this.spanp.width){
					tmpobj.style.pixelLeft = this.spanp.width-this.spanc.width*this.items.length;
					if(this.stoptime) this.stop(this.stoptime);
				}
			}
			if(this.direction=="top"){
				tmpobj.style.pixelTop -= parseInt(this.speed2);
				if(tmpobj.style.pixelTop <- this.spanc.height){
					tmpobj.style.pixelTop = this.spanc.height * (this.items.length - 1);
					if(this.stoptime) this.stop(this.stoptime);
				}
			}
			if(this.direction=="bottom"){
				tmpobj.style.pixelTop += parseInt(this.speed2);
				if(tmpobj.style.pixelTop > this.spanp.height){
					tmpobj.style.pixelTop = this.spanp.height-this.spanc.height*this.items.length;
					if(this.stoptime) this.stop(this.stoptime);
				}
			}
		}
	}
	this.stop = function(stoptime){
		clearInterval(this.intervalID);
		this.intervalID = "";
		if(stoptime) setTimeout("window.yjh_rollingobj["+this.objindex+"].go()",stoptime);
	}
	this.go = function(){
		if(!this.iswrited) this.write();
		if(this.iswrited && !this.intervalID){
			this.intervalID = setInterval("window.yjh_rollingobj["+this.objindex+"].move()",this.speed);
		}
	}
}

