
function zxcScrollBar(mde,fun,sid,lid,rid){
 var oop=new zxcScroll(mde,fun,sid,lid,rid);
 return oop;
}

function zxcScroll(mde,fun,sid,lid,rid){
 this.mde=mde.charAt(0).toUpperCase()=='V'?'top':'left'
 this.min=0;
 this.slide=document.getElementById(sid);
 if (this.slide){
  this.max=zxcLT(this.slide.parentNode,this.mde=='top'?'height':'width')-zxcLT(this.slide,this.mde=='top'?'height':'width');
  this.addevt(this.slide,'mousedown','down');
  this.addevt(document,'mousemove','move');
  this.addevt(document,'mouseup','up');
 }
 else {
  var p=zxcES('DIV',{position:'absolute',left:'0px',top:'0px',width:'1000px',height:'1000px'});
  this.slide=zxcES('DIV',{position:'absolute',left:'0px',top:'0px',width:'10px',height:'10px'},p);
  this.max=990;
 }
 this.slide.oop=this;
 this.lft=document.getElementById(lid);
 if (this.lft){
  this.addevt(this.lft,'mouseover','scrollLR',-1);
  this.addevt(this.lft,'mouseout','scrollLR',false);
 }
 this.right=document.getElementById(rid);
 if (this.right){
  this.addevt(this.right,'mouseover','scrollLR',1);
  this.addevt(this.right,'mouseout','scrollLR',false);
 }
 this.to=null;
 this.obj=document.getElementById(fun);
 this.fun=fun;
}

zxcScroll.prototype.scrollLR=function(e,ud){
 clearTimeout(this.to);
 if (ud){
  var pos=Math.max(Math.min(zxcLT(this.slide,this.mde)+ud,this.max),0);
  this.slide.style[this.mde]=pos+'px';
  if (this.obj){ this.Scroll(pos/this.max); }
  else if (window[this.fun]) window[this.fun](pos/this.max);
  this.to=setTimeout(function(oop){return function(){oop.scrollLR(e,ud);}}(this),10);
 }
}

zxcScroll.prototype.Scroll=function(pos){
 var wh=this.mde=='top'?'height':'width';
 this.obj.style[this.mde]=-(zxcLT(this.obj,wh)-zxcLT(this.obj.parentNode,wh))*pos+'px';
}

zxcScroll.prototype.addevt=function(o,t,f,p){
 var oop=this;
 if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
 else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
 else {
  var prev=o['on'+t];
  if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
  else o['on'+t]=o[f];
 }
}

zxcScroll.prototype.down=function(ev){
 document.onselectstart=function(event){ window.event.returnValue=false; }
 this.lastXY=this.mde=='left'?ev.clientX:ev.clientY;
 this.pos=zxcLT(this.slide,this.mde);
 this.drag=true;
 if (!window.event) ev.preventDefault();
 return false;
}

zxcScroll.prototype.move=function(ev){
 if (this.drag){
  var mse=this.mde=='left'?ev.clientX:ev.clientY;
  this.pos=Math.min(Math.max(this.min,this.pos+mse-this.lastXY),this.max);
  this.slide.style[this.mde]=this.pos+'px';
  this.lastXY=mse;
  if (this.obj){ this.Scroll(zxcLT(this.slide,this.mde)/this.max); }
  else if (window[this.fun]) window[this.fun](zxcLT(this.slide,this.mde)/this.max);
 }
 if (!window.event) ev.preventDefault();
 return false;
}

zxcScroll.prototype.up=function(ev){
 if (this.drag){
  this.drag=false;
  document.onselectstart=null;
 }
}

function zxcLT(obj,p){
 if (obj.currentStyle) return parseInt(obj.currentStyle[p]);
 return parseInt(document.defaultView.getComputedStyle(obj,null).getPropertyValue(p));
}

function zxcES(ele,style,par,txt){
 if (typeof(ele)=='string') ele=document.createElement(ele);
 for (key in style) ele.style[key]=style[key];
 if (par) par.appendChild(ele);
 if (txt) ele.appendChild(document.createTextNode(txt));
 return ele;
}




