/*
	francis,
	20 Feb 2008
	- fixed css padding problem
*/
var RollSetting={};
RollSetting.speed=25;
var Roll = Class.create(
	{
		
		initialize:function(ele,options){
			this.ele = $(ele);
			this.ele.makeClipping();
			this.ele.show();
			this.options = Object.extend({
				speed:RollSetting.speed,
				direction:"hori",
				width:this.ele.getWidth(),
				height:this.ele.getHeight(),
				start_play:true
			},options);
			
			//this.ele.setStyle({width:this.options.width,height:this.options.height});
			
			//this.ele.observe("mouseover",function(){this.stop()}.bind(this));
			//this.ele.observe("mouseout",function(){this.play()}.bind(this));
			
			this.content_html = this.ele.innerHTML;
			this.ele.undoClipping();

			if(this.options.direction=="hori"){
				var aw=0;
				this.ele.childElements().each(function(e){if(e.getStyle("display")=="block")e.setStyle({display:"inline"})});
				this.ele.childElements().each(function(e){if(e.tagName!="BR")aw+=e.getWidth()});
				this._offsetwidth=aw;
				//$("debug").update(this._offsetwidth);
				//return;
			}else{
				var ah=0;
				this.ele.childElements().each(function(e){if(e.tagName!="BR")ah+=e.getHeight()});
				this._offsetheight=ah;
			}
			this.ele.makeClipping();
			
			if(this.options.direction=="hori"){
				
				if(this._offsetwidth>this.options.width){
					this.ele.update("<table cellpadding='0' cellspacing='0'><tr><td>"+this.content_html+"</td><td>"+this.content_html+"</td></table>");
					
				}
			}else{
				if(this._offsetheight>this.options.height){
					this.ele.update("<table cellpadding='0' cellspacing='0'><tr><td>"+this.content_html+"</td></tr><tr><td>"+this.content_html+"</td></tr></table>");
					
				}
			}
			if(this.options.start_play){
				this.play();
			}
		},
		play:function(){
			this.stop();
			if(this.options.direction=="hori"){
				this._intarvalID = setInterval(function(){
					$(this.ele).scrollLeft+=1;
					if(this.ele.scrollLeft>=this._offsetwidth) this.ele.scrollLeft=0;
				}.bind(this),this.options.speed);
			}else{
				this._intarvalID = setInterval(function(){
					this.ele.scrollTop+=1;
					
					if(this.ele.scrollTop>this._offsetheight) this.ele.scrollTop=0;
				}.bind(this),this.options.speed);
			}
		},
		rewind:function(){
			this.stop();
			if(this.options.direction=="hori"){
				this._intarvalID = setInterval(function(){
					this.ele.scrollLeft-=1;
					if(this.ele.scrollLeft<=0) this.ele.scrollLeft=this._offsetwidth;
				}.bind(this),this.options.speed);
			}else{
				this._intarvalID = setInterval(function(){
					this.ele.scrollTop-=1;
					
					if(this.ele.scrollTop<=0) this.ele.scrollTop=this._offsetheight;
				}.bind(this),this.options.speed);
			}
		},
		stop:function(){
			clearInterval(this._intarvalID);
		}
	}
);




document.observe(
	"dom:loaded",
	function(){
		
		(function(){
		$$(".roll_vert").each(
			function(ele){
				regcmp(new Roll(ele.identify(),{direction:"vert"}),ele.identify());
			}
		);
		$$(".roll_hori").each(
			function(ele){
				regcmp(new Roll(ele.identify(),{direction:"hori"}),ele.identify());
			}
		);
		$$(".roll_vert_over").each(			   
			function(ele){
				
				var c=new Roll(ele.identify(),{direction:"vert"});
				regcmp(c,ele.identify());
				ele.observe("mouseover",function(){this.stop()}.bind(c));
				ele.observe("mouseout",function(){this.play()}.bind(c));
			}
		);
		$$(".roll_hori_over").each(
			function(ele){
				var c=new Roll(ele.identify(),{direction:"hori"});
				regcmp(c,ele.identify());
				ele.observe("mouseover",function(){this.stop()}.bind(c));
				ele.observe("mouseout",function(){this.play()}.bind(c));
			}
		);
		
		
		//this.ele.observe("mouseover",function(){this.stop()}.bind(this));
			//this.ele.observe("mouseout",function(){this.play()}.bind(this));
		
		
		}).defer();
	}
);