var UIL = function(func){window.attachEvent?window.attachEvent("onload",func):window.addEventListener("load",func,false)},
Ex = function(o){for(var k in o)this[k]=o[k];return this},
UI = function(id){return document.getElementById(id)},
UIs = function(tag){return Ex.call([],this.getElementsByTagName(tag))},
Each = function(a,fn){for(var i=0;i<a.length;i++)fn.call(a[i],i,a)},
dhooo = function(ini){
	this.bind(ini, this);
	this.autoIndex = 0;
	this.speed = 3000;
	this.setbtnseat = false;
	this.btnparent = null;
};
Ex.call(dhooo.prototype,{
	bind:function(ini, _this){
		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;
				_this.autoIndex = o.index;
				_this.begin(o.index, pan, ini.len, dir);
		};
		pan.onmouseover = function(){_this.stop=true};
		pan.onmouseout = function(){_this.stop=false};
		Each(ini.btns, function(i){
			this.index = i;
			if(ini.overout){
				this.onmouseover = function(){_this.stop=true;start(this)}
				pan.onmouseout = this.onmouseout = function(){_this.stop=false}
			}else{
				this.onclick = function(){start(this)}
			}
		});
		var auto = function(){
				if(!_this.stop){
					_this.autoIndex = _this.autoIndex==(ini.btns.length-1)?0:++_this.autoIndex;
					start(ini.btns[_this.autoIndex]);
				}
		};
		if(ini.auto) this.autoPlay = window.setInterval(auto, ini.speed);
		if(ini.setbtnseat && ini.btnparent!=null){
			UIL(function(){
				var mainwidth = pan.offsetWidth;
				var mainheight = pan.offsetHeight;
				var btn = UI(ini.btnparent);
				var btnwidth = btn.offsetWidth;
				var btnheight = btn.offsetHeight;
				var uw = (mainwidth - btnwidth - 10) + "px";
				var uh = (mainheight - btnheight - 10) + "px";
				uw = uh+" 0 0 "+uw;
				btn.style.margin = uw;
			});
		}
	}
	,begin:function(i, o, len, dir){
		(function(_this){
			clearInterval(_this.only);
			_this.only = setInterval(function(){
				var diff = (i*len-o[dir])*0.1;
				o[dir] += Math[diff>0?"ceil":"floor"](diff);
				if(diff==0) clearInterval(_this.only);
			},10);
		})(this)
	}
})
