var $_Scroll=function(o){
	this.initialize(o);
}

var active_is=undefined;
$_Scroll.prototype={
	initialize:function(o){
		if(!o.top||!o.down)return null;
		var b;
		if(o.type=='vertical'){
			o.top.onclick=this.scrollTop;
			o.down.onclick=this.scrollDown;
		}else{
			o.top.onclick=this.scrollLeft;
			o.down.onclick=this.scrollRight;
		}
		b=o.top.scroll=o.down.scroll=document.getElementById(o.scrolled);
		o.top.step=o.down.step=o.step;
		
		if( active_is!==undefined ){
			b.scrollLeft+=o.step*(active_is-1);
		}
		this.visibleRows(b,o);o=null;		
	},
	scrollTop:function(){
		this.scroll.scrollTop-=this.step;
		return false
	},
	scrollDown:function(){
		this.scroll.scrollTop+=this.step;
		return false		
	},
	scrollLeft:function(){
		this.scroll.scrollLeft-=this.step;
		return false
	},
	scrollRight:function(){
		this.scroll.scrollLeft+=this.step;
		return false		
	},
	readStyle:function(el,pr){
		if(el.style[pr]){
			return el.style[pr];
		}else if(el.currentStyle){
			return el.currentStyle[this.detectStyle(pr)];
		}else if(document.defaultView.getComputedStyle){
			var style = document.defaultView.getComputedStyle(el, null);
			return style.getPropertyValue(pr);
		}
		return null
	},
	detectStyle:function(type){
		if(!type)return false;
		type=type.split('-');
		if(type.length==1)return type[0];
		var i=0,count=type.length,tmp;
		for(i=1;i<count;i++){
			tmp=type[i].charAt(0).toUpperCase();
			type[i]=type[i].substr(1);
			type[i]=tmp+type[i];
		}
		return type.join('');
	},
	visibleRows:function(b,o){
		if(o.type=='vertical'){ if(/opera/.test(navigator.userAgent.toLowerCase())){this.visibleRows=function(b,o){
			if(b.offsetHeight<b.scrollHeight) o.top.style.visibility=o.down.style.visibility='visible';
			else o.top.style.visibility=o.down.style.visibility='hidden';
		}}else{this.visibleRows=function(b,o){
			var bTop=parseInt(this.readStyle(b,'border-top-width'))||0,bDown=parseInt(this.readStyle(b,'border-bottom-width'))||0;
			if(b.offsetHeight<(b.scrollHeight+bTop+bDown)) o.top.style.visibility=o.down.style.visibility='visible';
			else o.top.style.visibility=o.down.style.visibility='hidden';
		}}}else if(/opera/.test(navigator.userAgent.toLowerCase())){this.visibleRows=function(b,o){
			if(b.offsetWidth<b.scrollWidth) o.top.style.visibility=o.down.style.visibility='visible';
			else o.top.style.visibility=o.down.style.visibility='hidden';
		}}else{this.visibleRows=function(b,o){
			var bTop=parseInt(this.readStyle(b,'border-left-width'))||0,bDown=parseInt(this.readStyle(b,'border-right-width'))||0;
			if(b.offsetWidth<(b.scrollWidth+bTop+bDown)) o.top.style.visibility=o.down.style.visibility='visible';
			else o.top.style.visibility=o.down.style.visibility='hidden';
		}}
		this.visibleRows(b,o)
	}
}
