/* Copyright (c) 2009 Kelvin Luck (kelvin AT kelvinluck DOT com || http://www.kelvinluck.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * See http://kelvinluck.com/assets/jquery/jScrollPane/
 * $Id: jScrollPane.js 90 2010-01-25 03:52:10Z kelvin.luck $
 */

/**
 * Replace the vertical scroll bars on any matched elements with a fancy
 * styleable (via CSS) version. With JS disabled the elements will
 * gracefully degrade to the browsers own implementation of overflow:auto.
 * If the mousewheel plugin has been included on the page then the scrollable areas will also
 * respond to the mouse wheel.
 *
 * @example jQuery(".scroll-pane").jScrollPane();
 *
 * @name jScrollPane
 * @type jQuery
 * @param Object	settings	hash with options, described below.
 *								scrollbarWidth	-	The width of the generated scrollbar in pixels
 *								scrollbarMargin	-	The amount of space to leave on the side of the scrollbar in pixels
 *								wheelSpeed		-	The speed the pane will scroll in response to the mouse wheel in pixels
 *								showArrows		-	Whether to display arrows for the user to scroll with
 *								arrowSize		-	The height of the arrow buttons if showArrows=true
 *								animateTo		-	Whether to animate when calling scrollTo and scrollBy
 *								dragMinHeight	-	The minimum height to allow the drag bar to be
 *								dragMaxHeight	-	The maximum height to allow the drag bar to be
 *								animateInterval	-	The interval in milliseconds to update an animating scrollPane (default 100)
 *								animateStep		-	The amount to divide the remaining scroll distance by when animating (default 3)
 *								maintainPosition-	Whether you want the contents of the scroll pane to maintain it's position when you re-initialise it - so it doesn't scroll as you add more content (default true)
 *								tabIndex		-	The tabindex for this jScrollPane to control when it is tabbed to when navigating via keyboard (default 0)
 *								enableKeyboardNavigation - Whether to allow keyboard scrolling of this jScrollPane when it is focused (default true)
 *								animateToInternalLinks - Whether the move to an internal link (e.g. when it's focused by tabbing or by a hash change in the URL) should be animated or instant (default false)
 *								scrollbarOnLeft	-	Display the scrollbar on the left side?  (needs stylesheet changes, see examples.html)
 *								reinitialiseOnImageLoad - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded (default false)
 *								topCapHeight	-	The height of the "cap" area between the top of the jScrollPane and the top of the track/ buttons
 *								bottomCapHeight	-	The height of the "cap" area between the bottom of the jScrollPane and the bottom of the track/ buttons
 *								observeHash		-	Whether jScrollPane should attempt to automagically scroll to the correct place when an anchor inside the scrollpane is linked to (default true)
 * @return jQuery
 * @cat Plugins/jScrollPane
 * @author Kelvin Luck (kelvin AT kelvinluck DOT com || http://www.kelvinluck.com)
 */

;(function(b){b.jScrollPane={active:[]};b.fn.jScrollPane=function(c){c=b.extend({},b.fn.jScrollPane.defaults,c);var m=function(){return false};return this.each(function(){var d=b(this),Q=this,R=0,l,f,p,K=c.topCapHeight,g;if(b(this).parent().is(".jScrollPaneContainer")){g=b(this).parent();R=c.maintainPosition?d.position().top:0;var i=b(this).parent();l=i.innerWidth();f=i.outerHeight();b(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap",i).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);l=d.innerWidth();f=d.innerHeight();g=b("<div></div>").attr({className:"jScrollPaneContainer"}).css({height:f+"px",width:l+"px"});c.enableKeyboardNavigation&&g.attr("tabindex",c.tabIndex);d.wrap(g);g=d.parent();b(document).bind("emchange", function(){d.jScrollPane(c)})}p=f;if(c.reinitialiseOnImageLoad){var u=b.data(Q,"jScrollPaneImagesToLoad")||b("img",d),S=[];u.length&&u.each(function(a,e){b(this).bind("load readystatechange",function(){if(b.inArray(a,S)==-1){S.push(e);u=b.grep(u,function(k){return k!=e});b.data(Q,"jScrollPaneImagesToLoad",u);var h=b.extend(c,{reinitialiseOnImageLoad:false});d.jScrollPane(h)}}).each(function(){if(this.complete||this.complete===undefined)this.src=this.src})})}i={height:"auto",width:l-c.scrollbarWidth- c.scrollbarMargin-this.originalSidePaddingTotal+"px"};if(c.scrollbarOnLeft)i.paddingLeft=c.scrollbarMargin+c.scrollbarWidth+"px";else i.paddingRight=c.scrollbarMargin+"px";d.css(i);var v=d.outerHeight(),z=f/v;i=z<0.99;g[i?"addClass":"removeClass"]("jScrollPaneScrollable");if(i){g.append(b("<div></div>").addClass("jScrollCap jScrollCapTop").css({height:c.topCapHeight}),b("<div></div>").attr({className:"jScrollPaneTrack"}).css({width:c.scrollbarWidth+"px"}).append(b("<div></div>").attr({className:"jScrollPaneDrag"}).css({width:c.scrollbarWidth+ "px"}).append(b("<div></div>").attr({className:"jScrollPaneDragTop"}).css({width:c.scrollbarWidth+"px"}),b("<div></div>").attr({className:"jScrollPaneDragBottom"}).css({width:c.scrollbarWidth+"px"}))),b("<div></div>").addClass("jScrollCap jScrollCapBottom").css({height:c.bottomCapHeight}));l=b(">.jScrollPaneTrack",g);var A=b(">.jScrollPaneTrack .jScrollPaneDrag",g),w,q=[],r,s=function(){if(r>4||r%4==0)n(j+w*L);r++};c.enableKeyboardNavigation&&g.bind("keydown.jscrollpane",function(a){switch(a.keyCode){case 38:w= -1;r=0;s();q[q.length]=setInterval(s,100);return false;case 40:w=1;r=0;s();q[q.length]=setInterval(s,100);return false;case 33:case 34:return false;default:}}).bind("keyup.jscrollpane",function(a){if(a.keyCode==38||a.keyCode==40){for(a=0;a<q.length;a++)clearInterval(q[a]);return false}});if(c.showArrows){var B,T,U=function(){b("html").unbind("mouseup",U);B.removeClass("jScrollActiveArrowButton");clearInterval(T)},V=function(){b("html").bind("mouseup",U);B.addClass("jScrollActiveArrowButton");r=0; s();T=setInterval(s,100)};g.append(b("<a></a>").attr({href:"javascript:;",className:"jScrollArrowUp",tabindex:-1}).css({width:c.scrollbarWidth+"px",top:c.topCapHeight+"px"}).html("Scroll up").bind("mousedown",function(){B=b(this);w=-1;V();this.blur();return false}).bind("click",m),b("<a></a>").attr({href:"javascript:;",className:"jScrollArrowDown",tabindex:-1}).css({width:c.scrollbarWidth+"px",bottom:c.bottomCapHeight+"px"}).html("Scroll down").bind("mousedown",function(){B=b(this);w=1;V();this.blur(); return false}).bind("click",m));var M=b(">.jScrollArrowUp",g),W=b(">.jScrollArrowDown",g)}if(c.arrowSize){p=f-c.arrowSize-c.arrowSize;K+=c.arrowSize}else if(M){i=M.height();c.arrowSize=i;p=f-i-W.height();K+=i}p-=c.topCapHeight+c.bottomCapHeight;l.css({height:p+"px",top:K+"px"});var N=b(this).css({position:"absolute",overflow:"visible"}),x,o,L,j=0,C=z*f/2,D=function(a,e){var h=e=="X"?"Left":"Top";return a["page"+e]||a["client"+e]+(document.documentElement["scroll"+h]||document.body["scroll"+h])||0}, E=function(){return false},G=function(){F();x=A.offset(false);x.top-=j;o=p-A[0].offsetHeight;L=2*c.wheelSpeed*o/v},X=function(){b("html").unbind("mouseup",X).unbind("mousemove",Y);C=z*f/2;b.browser.msie&&b("html").unbind("dragstart",E).unbind("selectstart",E)},n=function(a){g.scrollTop(0);j=a=a<0?0:a>o?o:a;A.css({top:a+"px"});var e=a/o;d.data("jScrollPanePosition",(f-v)*-e);N.css({top:(f-v)*e+"px"});d.trigger("scroll");if(c.showArrows){M[a==0?"addClass":"removeClass"]("disabled");W[a==o?"addClass": "removeClass"]("disabled")}},Y=function(a){n(D(a,"Y")-x.top-C)};A.css({height:Math.max(Math.min(z*(f-c.arrowSize*2),c.dragMaxHeight),c.dragMinHeight)+"px"}).bind("mousedown",function(a){G();C=D(a,"Y")-j-x.top;b("html").bind("mouseup",X).bind("mousemove",Y);b.browser.msie&&b("html").bind("dragstart",E).bind("selectstart",E);return false});var Z,H,$,aa=function(){if(H>8||H%4==0)n(j-(j-$)/2);H++},ba=function(){clearInterval(Z);b("html").unbind("mouseup",ba).unbind("mousemove",O)},O=function(a){$=D(a, "Y")-x.top-C};l.bind("mousedown",function(a){G();O(a);H=0;b("html").bind("mouseup",ba).bind("mousemove",O);Z=setInterval(aa,100);aa();return false});g.bind("mousewheel",function(a,e){e=e||(a.wheelDelta?a.wheelDelta/120:a.detail?-a.detail/3:0);G();F();var h=j;n(j-e*L);return h==j});var I,P,da=function(){var a=(I-j)/c.animateStep;if(a>1||a<-1)n(j+a);else{n(I);F()}},F=function(){if(P){clearInterval(P);delete I}},t=function(a,e){if(typeof a=="string"){try{$e=b(a,d)}catch(h){return}if(!$e.length)return; a=$e.offset().top-d.offset().top}F();var k=v-f;a=a>k?k:a;d.data("jScrollPaneMaxScroll",k);k=a/k*o;if(e||!c.animateTo)n(k);else{g.scrollTop(0);I=k;P=setInterval(da,c.animateInterval)}};d[0].scrollTo=t;d[0].scrollBy=function(a){var e=-parseInt(N.css("top"))||0;t(e+a)};G();t(-R,true);b("*",this).bind("focus",function(){for(var a=b(this),e=0;a[0]!=d[0];){e+=a.position().top;a=a.offsetParent()}a=-parseInt(N.css("top"))||0;var h=a+f;if(!(e>a&&e<h)){h=e-c.scrollbarMargin;if(e>a)h+=b(this).height()+15+c.scrollbarMargin- f;t(h)}});if(c.observeHash){if(location.hash&&location.hash.length>1)setTimeout(function(){t(location.hash)},b.browser.safari?100:0);b(document).bind("click",function(a){$target=b(a.target);if($target.is("a")){var e=$target.attr("href");if(e&&e.substr(0,1)=="#"&&e.length>1)setTimeout(function(){t(e,!c.animateToInternalLinks)},b.browser.safari?100:0)}})}var J,y,ea=function(){direction=J<0?-1:1;d[0].scrollBy(J/2)},ca=function(){if(y){clearInterval(y);y=undefined}},fa=function(a){var e=d.parent().offset().top, h=e+f;a=D(a,"Y");J=a<e?a-e:a>h?a-h:0;if(J==0)ca();else y||(y=setInterval(ea,100))},ga=function(){b(document).unbind("mousemove.jScrollPaneDragging").unbind("mouseup.jScrollPaneDragging");ca()};g.bind("mousedown.jScrollPane",function(){b(document).bind("mousemove.jScrollPaneDragging",fa);b(document).bind("mouseup.jScrollPaneDragging",ga)});b.jScrollPane.active.push(d[0])}else{d.css({height:f+"px",width:l-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")}})};b.fn.jScrollPaneRemove=function(){b(this).each(function(){$this=b(this);var c=$this.parent();if(c.is(".jScrollPaneContainer")){$this.css({top:"",height:"",width:"",padding:"",overflow:"",position:""});$this.attr("style",$this.data("originalStyleTag"));c.after($this).remove()}})};b.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,observeHash:true};b(window).bind("unload",function(){for(var c=b.jScrollPane.active,m=0;m<c.length;m++)c[m].scrollTo=c[m].scrollBy=null})})(jQuery);

/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

;(function(b){b.event.special.mousewheel={setup:function(){var a=b.event.special.mousewheel.handler;b.browser.mozilla&&b(this).bind("mousemove.mousewheel",function(c){b.data(this,"mwcursorposdata",{pageX:c.pageX,pageY:c.pageY,clientX:c.clientX,clientY:c.clientY})});if(this.addEventListener)this.addEventListener(b.browser.mozilla?"DOMMouseScroll":"mousewheel",a,false);else this.onmousewheel=a},teardown:function(){var a=b.event.special.mousewheel.handler;b(this).unbind("mousemove.mousewheel");if(this.removeEventListener)this.removeEventListener(b.browser.mozilla? "DOMMouseScroll":"mousewheel",a,false);else this.onmousewheel=function(){};b.removeData(this,"mwcursorposdata")},handler:function(a){var c=Array.prototype.slice.call(arguments,1);a=b.event.fix(a||window.event);b.extend(a,b.data(this,"mwcursorposdata")||{});var d=0;if(a.wheelDelta)d=a.wheelDelta/120;if(a.detail)d=-a.detail/3;a.data=a.data||{};a.type="mousewheel";c.unshift(d);c.unshift(a);return b.event.handle.apply(this,c)}};b.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")}, unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function(a){a.fn.superfish=function(d){var b=a.fn.superfish,h=b.c,n=a(['<span class="',h.arrowClass,'"> &#187;</span>'].join("")),i=function(){var c=a(this),e=j(c);clearTimeout(e.sfTimer);c.showSuperfishUl().siblings().hideSuperfishUl()},k=function(){var c=a(this),e=j(c),g=b.op;clearTimeout(e.sfTimer);e.sfTimer=setTimeout(function(){g.retainPath=a.inArray(c[0],g.$path)>-1;c.hideSuperfishUl();g.$path.length&&c.parents(["li.",g.hoverClass].join("")).length<1&&i.call(g.$path)},g.delay)},j=function(c){c= c.parents(["ul.",h.menuClass,":first"].join(""))[0];b.op=b.o[c.serial];return c},o=function(c){c.addClass(h.anchorClass).append(n.clone())};return this.each(function(){var c=this.serial=b.o.length,e=a.extend({},b.defaults,d);e.$path=a("li."+e.pathClass,this).slice(0,e.pathLevels).each(function(){a(this).addClass([e.hoverClass,h.bcClass].join(" ")).filter("li:has(ul)").removeClass(e.pathClass)});b.o[c]=b.op=e;a("li:has(ul)",this)[a.fn.hoverIntent&&!e.disableHI?"hoverIntent":"hover"](i,k).each(function(){e.autoArrows&& o(a(">a:first-child",this))}).not("."+h.bcClass).hideSuperfishUl();var g=a("a",this);g.each(function(l){var m=g.eq(l).parents("li");g.eq(l).focus(function(){i.call(m)}).blur(function(){k.call(m)})});e.onInit.call(this)}).each(function(){var c=[h.menuClass];b.op.dropShadows&&!(a.browser.msie&&a.browser.version<7)&&c.push(h.shadowClass);a(this).addClass(c.join(" "))})};var f=a.fn.superfish;f.o=[];f.op={};f.IE7fix=function(){var d=f.op;a.browser.msie&&a.browser.version>6&&d.dropShadows&&d.animation.opacity!= undefined&&this.toggleClass(f.c.shadowClass+"-off")};f.c={bcClass:"sf-breadcrumb",menuClass:"sf-js-enabled",anchorClass:"sf-with-ul",arrowClass:"sf-sub-indicator",shadowClass:"sf-shadow"};f.defaults={hoverClass:"sfHover",pathClass:"overideThisToUse",pathLevels:1,delay:0,animation:{opacity:"show"},speed:"normal",autoArrows:false,dropShadows:false,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};a.fn.extend({hideSuperfishUl:function(){var d=f.op, b=d.retainPath===true?d.$path:"";d.retainPath=false;b=a(["li.",d.hoverClass].join(""),this).add(this).not(b).removeClass(d.hoverClass).find(">ul").hide().css("visibility","hidden");d.onHide.call(b);return this},showSuperfishUl:function(){var d=f.op,b=this.addClass(d.hoverClass).find(">ul:hidden").css("visibility","visible");f.IE7fix.call(b);d.onBeforeShow.call(b);b.animate(d.animation,d.speed,function(){f.IE7fix.call(b);d.onShow.call(b)});return this}})})(jQuery);

/* -------------------------------------------------- *
 * ToggleVal 2.1
 * Updated: 1/16/09
 * -------------------------------------------------- *
 * Author: Aaron Kuzemchak
 * URL: http://aaronkuzemchak.com/
 * Copyright: 2008-2009 Aaron Kuzemchak
 * License: MIT License
** -------------------------------------------------- */

;(function($){$.fn.toggleVal=function(theOptions){if(!theOptions||typeof(theOptions)=="object"){theOptions=$.extend({focusClass:"tv-focused",changedClass:"tv-changed",populateFrom:"default",text:null,removeLabels:false},theOptions);}
else if(typeof(theOptions)=="string"&&theOptions.toLowerCase()=="destroy"){var destroy=true;}
return this.each(function(){if(destroy){$(this).unbind("focus.toggleval").unbind("blur.toggleval").removeData("defText");return false;}
var defText="";switch(theOptions.populateFrom){case"title":defText=$(this).attr("title");$(this).val(defText);break;case"label":defText=$("label[for='"+$(this).attr("id")+"']").text();$(this).val(defText);break;case"custom":defText=theOptions.text;$(this).val(defText);break;default:defText=$(this).val();}
$(this).addClass("toggleval").data("defText",defText);if(theOptions.removeLabels==true){$("label[for='"+$(this).attr("id")+"']").remove();}
$(this).bind("focus.toggleval",function(){if($(this).val()==$(this).data("defText")){$(this).val("");}
$(this).addClass(theOptions.focusClass).removeClass(theOptions.changedClass);}).bind("blur.toggleval",function(){if($(this).val()==""){$(this).val($(this).data("defText"));}
$(this).removeClass(theOptions.focusClass);if($(this).val()!=$(this).data("defText")){$(this).addClass(theOptions.changedClass);}
else{$(this).removeClass(theOptions.changedClass);}});});};})(jQuery);
