

// Custom Scroll Bars III (13-July-2009)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// A lightweight 'Custom Scroll Bar' script to scroll a specified element
// or to return the slide position to a specified function.
// When a Slide is not required a dummy will be made.
// There may be as many applications on a page as required.

// Initialised by a BODY or window onloadevent call to function:
// zxcScrollBar('h','MyFunction','bar','lft','right');
// where:
// parameter 0 = the scroll bar type 'V' = vertical, 'H' = horizontal.       (string, 'V' or 'H, default 'H')
// parameter 1 = the function to pass the position of the scroll bar slider. (string)
//               or the unique ID name of the element to scroll.             (string)
// parameter 2 = (optional) the unique id name of the bar slider.            (string, a dummy will be made if not required)
// parameter 3 = (optional) the unique id name of the bar left control.      (string)
// parameter 4 = (optional) the unique id name of the bar right control.     (string)

// functional Code(3.39K) - NO NEED to Change

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.position=0;
 this.max=100;
 this.lft=document.getElementById(lid);
 if (this.lft){
  this.addevt(this.lft,'mousedown','scrollLR',-1);
  this.addevt(this.lft,'mouseup','scrollLR',false);
 }
 this.right=document.getElementById(rid);
 if (this.right){
  this.addevt(this.right,'mousedown','scrollLR',1);
  this.addevt(this.right,'mouseup','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(this.position+ud,this.max),0);
  this.position=pos;
  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];
 }
}

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;
}


// Example Functions using the Scroll Bar return.


function MyFunctionH(pos){
 var obj=document.getElementById('main_area');
 	obj.style.left=-(obj.offsetWidth-obj.parentNode.offsetWidth)*pos+'px';	 
}

function MyFunctionV(pos){
 var obj=document.getElementById('main_area');
 if (obj.offsetHeight >= obj.parentNode.offsetHeight) {
 	obj.style.top = -(obj.offsetHeight - obj.parentNode.offsetHeight) * pos + 'px';
 }
}

function Init(){
 zxcScrollBar('v','MyFunctionV','slideV','lftV','rightV');
}