var autok=false;
var movepage=false;
var dpage=1;
var Ex=function(o){for(var k in o)this[k]=o[k];return this}
var UI=function(id){return document.getElementById(id)}
var UIs=function(tag){return Ex.call([],this.getElementsByTagName(tag))}
var Each=function(a,fn){for(var i=0;i<a.length;i++)fn.call(a[i],i,a)}
var dhooo=function(ini){
	this.bind(ini,this);
	this.autoIndex=0;
	this.speed=3000;
	this.btnwidth=23;
	this.shownum=20;
};
Ex.call(dhooo.prototype,{
	bind:function(ini,me){
		movepage=ini.btns.length+1>ini.shownum;
		var dir=ini.dir=="top"?"scrollTop":"scrollLeft",pan=UI(ini.contentID);
		var start=function(o){
				Each(ini.btns,function(){this.className=""});
				o.className=ini.className;
				me.autoIndex=o.index;
				if(movepage){
					var pagesnum = Math.ceil((o.index+1)/ini.shownum);
					if(dpage!=pagesnum)UI(ini.liid).style.left = (-(o.index*ini.btnwidth)+8) + "px";dpage=pagesnum;
				}
				me.begin(o.index,pan,ini.len,dir);
		};
		pan.onmouseover=function(){me.stop=true};
		pan.onmouseout=function(){me.stop=false};
		Each(ini.btns,function(i){
			this.index=i;
			if(ini.overout){
				this.onmouseover=function(){me.stop=true;start(this)}
				pan.onmouseout=this.onmouseout=function(){me.stop=false}
			}else{
				this.onclick=function(){start(this)}
			}
		});
		var auto=function(){
				if(!autok){
					if(!me.stop){
					me.autoIndex=me.autoIndex==(ini.btns.length-1)?0:++me.autoIndex;
					start(ini.btns[me.autoIndex]);
					}
				}
		};
		if(ini.auto)this.autoPlay=window.setInterval(auto,ini.speed);
	}
	,begin:function(i,o,len,dir){
		(function(me){
			clearInterval(me.only);
			me.only=setInterval(function(){
				var diff=(i*len-o[dir])*0.1;
				o[dir]+=Math[diff>0?"ceil":"floor"](diff);
				if(diff==0)clearInterval(me.only);
			},10)
		})(this)
	}
})