
(function(a)
{
a.jScrollPane={active:[]};
a.fn.jScrollPane=function(b)
{
b=a.extend({},a.fn.jScrollPane.defaults,b);
var c=function()
{
return false
};
return this.each(function()
{
var d=a(this),
bb=this,
P=0,
t,
e,
m,
J=b.topCapHeight;
if(a(this).parent().is(".jScrollPaneContainer"))
{
P=b.maintainPosition?d.position().top:0;
var N=a(this).parent();
t=N.innerWidth();
e=N.outerHeight();
a(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScollCap",N).remove();
d.css({top:0})
}
else
{
d.data("originalStyleTag",d.attr("style"));
d.css("overflow","hidden");
this.originalPadding=d.css("paddingTop")+" "+d.css("paddingRight")+" "+d.css("paddingBottom")+" "+d.css("paddingLeft");
this.originalSidePaddingTotal=(parseInt(d.css("paddingLeft"))||0)+(parseInt(d.css("paddingRight"))||0);
t=d.innerWidth();
e=d.innerHeight();
var f=a("<div></div>").attr({className:"jScrollPaneContainer"}).css({height:e+"px",width:t+"px"});
b.enableKeyboardNavigation&&
f.attr("tabindex",b.tabIndex);
d.wrap(f);
a(document).bind("emchange",function()
{
d.jScrollPane(b)
})
}
m=e;
if(b.reinitialiseOnImageLoad)
{
var q=a.data(bb,"jScrollPaneImagesToLoad")||a("img",d),
X=[];
q.length&&
q.each(function(e,c)
{
a(this).bind("load readystatechange",function()
{
if(a.inArray(e,X)==-1)
{
X.push(c);
q=a.grep(q,function(a)
{
return a!=c
});
a.data(bb,"jScrollPaneImagesToLoad",q);
var f=a.extend(b,{reinitialiseOnImageLoad:false});
d.jScrollPane(f)
}
}).each(function()
{
if(this.complete||this.complete===undefined)
this.src=this.src
})
})
}
var mb=this.originalSidePaddingTotal,
ib=t-b.scrollbarWidth-b.scrollbarMargin-mb,
K={height:"auto",width:ib+"px"};
if(b.scrollbarOnLeft)
K.paddingLeft=b.scrollbarMargin+b.scrollbarWidth+"px";
else
K.paddingRight=b.scrollbarMargin+"px";
d.css(K);
var r=d.outerHeight(),
A=e/r;
if(A<.99)
{
var f=d.parent();
f.append(a("<div></div>").addClass("jScrollCap jScrollCapTop").css({height:b.topCapHeight}),a("<div></div>").attr({className:"jScrollPaneTrack"}).css({width:b.scrollbarWidth+"px"}).append(a("<div></div>").attr({className:"jScrollPaneDrag"}).css({width:b.scrollbarWidth+"px"}).append(a("<div></div>").attr({className:"jScrollPaneDragTop"}).css({width:b.scrollbarWidth+"px"}),a("<div></div>").attr({className:"jScrollPaneDragBottom"}).css({width:b.scrollbarWidth+"px"}))),a("<div></div>").addClass("jScrollCap jScrollCapBottom").css({height:b.bottomCapHeight}));
var cb=a(">.jScrollPaneTrack",f),
E=a(">.jScrollPaneTrack .jScrollPaneDrag",f),
o,
j=[],
l,
k=function()
{
(l>4||l%4==0)&&
h(g+o*F);
l++
};
b.enableKeyboardNavigation&&
f.bind("keydown.jscrollpane",function(a)
{
switch(a.keyCode)
{
case 38:
o=-1;
l=0;
k();
j[j.length]=setInterval(k,100);
return false;
case 40:
o=1;
l=0;
k();
j[j.length]=setInterval(k,100);
return false;
case 33:
case 34:
return false
}
}).bind("keyup.jscrollpane",function(b)
{
if(b.keyCode==38||b.keyCode==40)
{
for(var a=0;a<j.length;a++)
clearInterval(j[a]);
return false
}
});
if(b.showArrows)
{
var v,
Q,
V=function()
{
a("html").unbind("mouseup",V);
v.removeClass("jScrollActiveArrowButton");
clearInterval(Q)
},
T=function()
{
a("html").bind("mouseup",V);
v.addClass("jScrollActiveArrowButton");
l=0;
k();
Q=setInterval(k,100)
};
f.append(a("<a></a>").attr({href:"javascript:;",className:"jScrollArrowUp",tabindex:-1}).css({width:b.scrollbarWidth+"px",top:b.topCapHeight+"px"}).html("Scroll up").bind("mousedown",function()
{
v=a(this);
o=-1;
T();
this.blur();
return false
}).bind("click",c),a("<a></a>").attr({href:"javascript:;",className:"jScrollArrowDown",tabindex:-1}).css({width:b.scrollbarWidth+"px",bottom:b.bottomCapHeight+"px"}).html("Scroll down").bind("mousedown",function()
{
v=a(this);
o=1;
T();
this.blur();
return false
}).bind("click",c));
var L=a(">.jScrollArrowUp",f),
Z=a(">.jScrollArrowDown",f)
}
if(b.arrowSize)
{
m=e-b.arrowSize-b.arrowSize;
J+=b.arrowSize
}
else
if(L)
{
var I=L.height();
b.arrowSize=I;
m=e-I-Z.height();
J+=I
}
m-=b.topCapHeight+b.bottomCapHeight;
cb.css({height:m+"px",top:J+"px"});
var M=a(this).css({position:"absolute",overflow:"visible"}),
s,
i,
F,
g=0,
B=A*e/2,
D=function(b,a)
{
var c=a=="X"?"Left":"Top";
return b["page"+a]||b["client"+a]+(document.documentElement["scroll"+c]||document.body["scroll"+c])||0
},
x=function()
{
return false
},
C=function()
{
y();
s=E.offset(false);
s.top-=g;
i=m-E[0].offsetHeight;
F=2*b.wheelSpeed*i/r
},
kb=function(b)
{
C();
B=D(b,"Y")-g-s.top;
a("html").bind("mouseup",ab).bind("mousemove",Y);
a.browser.msie&&
a("html").bind("dragstart",x).bind("selectstart",x);
return false
},
ab=function()
{
a("html").unbind("mouseup",ab).unbind("mousemove",Y);
B=A*e/2;
a.browser.msie&&
a("html").unbind("dragstart",x).unbind("selectstart",x)
},
h=function(a)
{
f.scrollTop(0);
a=a<0?0:a>i?i:a;
g=a;
E.css({top:a+"px"});
var c=a/i;
d.data("jScrollPanePosition",(e-r)*-c);
M.css({top:(e-r)*c+"px"});
d.trigger("scroll");
if(b.showArrows)
{
L[a==0?"addClass":"removeClass"]("disabled");
Z[a==i?"addClass":"removeClass"]("disabled")
}
},
Y=function(a)
{
h(D(a,"Y")-s.top-B)
},
lb=Math.max(Math.min(A*(e-b.arrowSize*2),b.dragMaxHeight),b.dragMinHeight);
E.css({height:lb+"px"}).bind("mousedown",kb);
var R,
z,
S,
W=function()
{
(z>8||z%4==0)&&
h(g-(g-S)/2);
z++
},
U=function()
{
clearInterval(R);
a("html").unbind("mouseup",U).unbind("mousemove",H)
},
H=function(a)
{
S=D(a,"Y")-s.top-B
},
jb=function(b)
{
C();
H(b);
z=0;
a("html").bind("mouseup",U).bind("mousemove",H);
R=setInterval(W,100);
W();
return false
};
cb.bind("mousedown",jb);
f.bind("mousewheel",function(a,b)
{
b=b||(a.wheelDelta?a.wheelDelta/120:a.detail?-a.detail/3:0);
C();
y();
var d=g;
h(g-b*F);
var c=d!=g;
return !c
});
var w,
G;
function hb()
{
var a=(w-g)/b.animateStep;
if(a>1||a<-1)
h(g+a);
else
{
h(w);
y()
}
}
var y=function()
{
if(G)
{
clearInterval(G);
delete w
}
},
n=function(c,k)
{
if(typeof c=="string")
{
$e=a(c,d);
if(!$e.length)
return;
c=$e.offset().top-d.offset().top
}
y();
var g=r-e;
c=c>g?g:c;
d.data("jScrollPaneMaxScroll",g);
var j=c/g*i;
if(k||!b.animateTo)
h(j);
else
{
f.scrollTop(0);
w=j;
G=setInterval(hb,b.animateInterval)
}
};
d[0].scrollTo=n;
d[0].scrollBy=function(b)
{
var a=-parseInt(M.css("top"))||0;
n(a+b)
};
C();
n(-P,true);
a("*",this).bind("focus",function()
{
var f=a(this),
c=0;
while(f[0]!=d[0])
{
c+=f.position().top;
f=f.offsetParent()
}
var g=-parseInt(M.css("top"))||0,
i=g+e,
j=c>g&&c<i;
if(!j)
{
var h=c-b.scrollbarMargin;
if(c>g)
h+=a(this).height()+15+b.scrollbarMargin-e;
n(h)
}
});
location.hash&&location.hash.length>1&&
setTimeout(function()
{
n(location.hash)
},a.browser.safari?100:0);
a(document).bind("click",function(d)
{
$target=a(d.target);
if($target.is("a"))
{
var c=$target.attr("href");
c&&c.substr(0,1)=="#"&&c.length>1&&
setTimeout(function()
{
n(c,!b.animateToInternalLinks)
},a.browser.safari?100:0)
}
});
function eb()
{
a(document).bind("mousemove.jScrollPaneDragging",db);
a(document).bind("mouseup.jScrollPaneDragging",gb)
}
var u,
p;
function fb()
{
direction=u<0?-1:1;
d[0].scrollBy(u/2)
}
function O()
{
if(p)
{
clearInterval(p);
p=undefined
}
}
function db(f)
{
var b=d.parent().offset().top,
c=b+e,
a=D(f,"Y");
u=a<b?a-b:a>c?a-c:0;
if(u==0)
O();
else
if(!p)
p=setInterval(fb,100)
}
function gb()
{
a(document).unbind("mousemove.jScrollPaneDragging").unbind("mouseup.jScrollPaneDragging");
O()
}
f.bind("mousedown.jScrollPane",eb);
a.jScrollPane.active.push(d[0])
}
else
{
d.css({height:e+"px",width:t-this.originalSidePaddingTotal+"px",padding:this.originalPadding});
d[0].scrollTo=d[0].scrollBy=function()
{
};
d.parent().unbind("mousewheel").unbind("mousedown.jScrollPane").unbind("keydown.jscrollpane").unbind("keyup.jscrollpane")
}
})
};
a.fn.jScrollPaneRemove=function()
{
a(this).each(function()
{
$this=a(this);
var b=$this.parent();
if(b.is(".jScrollPaneContainer"))
{
$this.css({top:"",height:"",width:"",padding:"",overflow:"",position:""});
$this.attr("style",$this.data("originalStyleTag"));
b.after($this).remove()
}
})
};
a.fn.jScrollPane.defaults={scrollbarWidth:10,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false,tabIndex:0,enableKeyboardNavigation:true,animateToInternalLinks:false,topCapHeight:0,bottomCapHeight:0};
a(window).bind("unload",function()
{
for(var c=a.jScrollPane.active,
b=0;b<c.length;b++)
c[b].scrollTo=c[b].scrollBy=null
})
})(jQuery)
