jQuery(function(){
	initPlugins();
});

function initPlugins(){
	jQuery('select').customSelect();
	jQuery('input:radio').customRadio();
	jQuery('input:checkbox').customCheckbox();
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addParentFocus: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
	initValidation();
}
function initValidation(){
	var _form = $('.select-form');
	_form.submit(function(){
		_form.removeClass('false');
		function check(){
			var _f = true;
			_form.find('select option').each(function(){
				if ($(this).attr('selected')) {
					if ($(this).text() == 'Choose Your Location'){
						_f = false;
						_form.addClass('false')
						return false;
					}
				}
			})
			return _f;
		}
		return check();
		
	})
}
// custom forms plugin
(function(jQuery){
	// custom checkboxes module
	jQuery.fn.customCheckbox = function(_options){
		var _options = jQuery.extend({
			checkboxStructure: '<div></div>',
			checkboxDisabled: 'disabled',
			checkboxDefault: 'checkboxArea',
			checkboxChecked: 'checkboxAreaChecked'
		}, _options);
		return this.each(function(){
			var checkbox = jQuery(this);
			if(!checkbox.hasClass('outtaHere') && checkbox.is(':checkbox')){
				var replaced = jQuery(_options.checkboxStructure);
				this._replaced = replaced;
				if (checkbox.is(':disabled')) replaced.addClass(_options.checkboxDisabled);
				else if (checkbox.is(':checked')) replaced.addClass(_options.checkboxChecked);
				else replaced.addClass(_options.checkboxDefault);

				replaced.click(function(){
					if(checkbox.is(':checked')) checkbox.removeAttr('checked');
					else checkbox.attr('checked', 'checked');
					changeCheckbox(checkbox);
				});
				checkbox.click(function(){
					changeCheckbox(checkbox);
				});
				replaced.insertBefore(checkbox);
				checkbox.addClass('outtaHere');
			}
		});
		function changeCheckbox(_this){
			_this.change();
			if(_this.is(':checked')) _this.get(0)._replaced.removeClass().addClass(_options.checkboxChecked);
			else _this.get(0)._replaced.removeClass().addClass(_options.checkboxDefault);
		}
	}

	// custom radios module
	jQuery.fn.customRadio = function(_options){
		var _options = jQuery.extend({
			radioStructure: '<div></div>',
			radioDisabled: 'disabled',
			radioDefault: 'radioArea',
			radioChecked: 'radioAreaChecked'
		}, _options);
		return this.each(function(){
			var radio = jQuery(this);
			if(!radio.hasClass('outtaHere') && radio.is(':radio')){
				var replaced = jQuery(_options.radioStructure);
				this._replaced = replaced;
				if(radio.is(':disabled')) replaced.addClass(_options.radioDisabled);
				else if(radio.is(':checked')) replaced.addClass(_options.radioChecked);
				else replaced.addClass(_options.radioDefault);
				replaced.click(function(){
					if($(this).hasClass(_options.radioDefault)){
						radio.attr('checked', 'checked');
						changeRadio(radio.get(0));
					}
				});
				radio.click(function(){
					changeRadio(this);
				});
				replaced.insertBefore(radio);
				radio.addClass('outtaHere');
			}
		});
		function changeRadio(_this){
			$(_this).change();
			$('input:radio[name='+$(_this).attr("name")+']').not(_this).each(function(){
				if(this._replaced && !$(this).is(':disabled')) this._replaced.removeClass().addClass(_options.radioDefault);
			});
			_this._replaced.removeClass().addClass(_options.radioChecked);
		}
	}

	var rpcSel;
	// custom selects module
	jQuery.fn.customSelect = function(_options) {
		var _options = jQuery.extend({
			selectStructure: '<div class="selectArea"><span class="left"></span><span class="center"></span><a href="#" class="selectButton"></a><div class="disabled"></div></div>',
			hideOnMouseOut: false,
			copyClass: true,
			selectText: '.center',
			selectBtn: '.selectButton',
			selectDisabled: '.disabled',
			optStructure: '<div class="selectOptions optionsDivVisible"><div class="select-top"></div><div class="select-center"><div class="scrollable"><ul></ul></div></div><div class="select-bottom"></div></div>',
			optList: 'ul'
		}, _options);
		return this.each(function() {
			var select = jQuery(this);
			if(!select.hasClass('outtaHere')) {
				if(select.is(':visible')) {
					var hideOnMouseOut = _options.hideOnMouseOut;
					var copyClass = _options.copyClass;
					var replaced = jQuery(_options.selectStructure);
					rpcSel = replaced;
					var selectText = replaced.find(_options.selectText);
					var selectBtn = replaced.find(_options.selectBtn);
					var selectDisabled = replaced.find(_options.selectDisabled).hide();
					var optHolder = jQuery(_options.optStructure);
					var optList = optHolder.find(_options.optList);
					if(copyClass) optHolder.addClass('drop-'+select.attr('class'));

					if(select.attr('disabled')) selectDisabled.show();
					select.find('option').each(function(){
						var selOpt = $(this);
						var _opt = jQuery('<li class="'+selOpt.attr('class')+'"><a href="#">' + selOpt.html() + '</a></li>');
						if(selOpt.attr('selected')) {
							selectText.html(selOpt.html());
							_opt.addClass('selected');
						}
						_opt.children('a').click(function() {
							if(!$(this).parent('li').hasClass('country')){
								optList.find('li').removeClass('selected');
								select.find('option').removeAttr('selected');
								$(this).parent().addClass('selected');
								selOpt.attr('selected', 'selected');
								replaced.removeClass('active');
								selectText.html(selOpt.html());
								select.change();
								optHolder.hide();
							}
							return false;
						});
						optList.append(_opt);
					});
					replaced.width(select.outerWidth());
					replaced.insertBefore(select);
					optHolder.css({
						width: select.outerWidth(),
						display: 'none',
						position: 'absolute'
					});
					jQuery(document.body).append(optHolder);

					var optTimer;
					replaced.hover(function() {
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					optHolder.hover(function(){
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					selectBtn.click(function() {
						if(optHolder.is(':visible')) {
							optHolder.hide();
							replaced.removeClass('active');
						}
						else{
							replaced.addClass('active');
							if(_activeDrop) _activeDrop.hide();
							optHolder.children('ul').css({height:'auto', overflow:'hidden'});
							optHolder.css({
								top: replaced.offset().top + replaced.outerHeight(),
								left: replaced.offset().left,
								display: 'block'
							});
							//if(optHolder.children('ul').height() > 200) optHolder.children('ul').css({height:200, overflow:'auto'});
							//
							
							if (optHolder.find('div.scrollable').height() > 278) {
								optHolder.find('div.scrollable').css({height:278, overflow:'auto'});
								optHolder.find('div.scrollable').customScroll(); //VSA_initScrollbars();
							} 
							_activeDrop = optHolder;
						}
						return false;
					});
					select.addClass('outtaHere');
				}
			}
		});
	}

	// event handler on DOM ready
	var _activeDrop;
	jQuery(function(){
		jQuery('body').click(hideOptionsClick)
		jQuery(window).resize(hideOptions)
	});
	function hideOptions() {
		if(_activeDrop && _activeDrop.length) {
			_activeDrop.hide();
			_activeDrop = null;
			rpcSel.removeClass('active');
		}
	}
	function hideOptionsClick(e) {
		var temp = e.target;
		if($(temp).parents('.selectOptions').length == 0){
			rpcSel.removeClass('active');
			if(_activeDrop && _activeDrop.length) {
				var f = false;
				$(e.target).parents().each(function(){
					if(this == _activeDrop) f=true;
				});
				if(!f) {
					_activeDrop.hide();
					_activeDrop = null;
				}
			}
		}
	}
})(jQuery);

function clearFormFields(o){
	if(o.clearInputs == null){o.clearInputs = true;} // true/false
	if(o.clearTextareas == null){o.clearTextareas = true;} // true/false
	if(o.passwordFieldText == null){o.passwordFieldText = false;} // true/false
	if(o.addClassFocus == null){o.addClassFocus = false;} // focus class
	if(o.addParentFocus == null){o.addParentFocus = false;} // true/false or parent selector
	if(!o.filter){o.filter = "default";}
	if(o.clearInputs || o.clearTextareas){
		var inputs = jQuery(eval("o.clearInputs ? 'input' : ''") + eval("o.clearTextareas ? ', textarea' : ''"));
		inputs.each(function(){
			var _this = jQuery(this);
			var _type = _this.attr('type') || 'textarea';
			var _class = _this.attr('class');
			var _valHtml = _this.val();
			if(o.passwordFieldText && _type == 'password'){
				var fakeInput = jQuery('<input>');
				fakeInput.attr('type', 'text');
				fakeInput.attr('value', _valHtml);
				fakeInput.attr('class', _class);
				fakeInput.fake = true;
				fakeInput.focus(function(){
					_this.trigger('focus');
				});
				_this.parent().prepend(fakeInput);
				_this.fake = fakeInput;
				inputsSwap(_this, null);
			}
			if((_type == 'textarea' || _type == 'text' || _type == 'password') || _class == o.filterClass){
				_this.focus(function(){
					if(_valHtml == _this.val()){_this.val('');}
					if(_this.fake){
						inputsSwap(_this.fake, _this);
					}
					if(o.addClassFocus){
						_this.addClass(o.addClassFocus);
						if(_this.fake){_this.fake.addClass(o.addClassFocus);}
						if(o.addParentFocus == true){
							_this.parent().addClass('parent-'+o.addClassFocus);
						}else if(!o.addParentFocus == false){
							_this.parents(o.addParentFocus).addClass('parent-'+o.addClassFocus);
						}
					}
				});
				_this.blur(function(){
					if(_this.val() == ''){
						_this.val(_valHtml);
						if(_this.fake){inputsSwap(_this, _this.fake);}
					}
					if(o.addClassFocus){
						_this.removeClass(o.addClassFocus);
						if(_this.fake){_this.fake.removeClass(o.addClassFocus);}
						if(o.addParentFocus == true){
							_this.parent().removeClass('parent-'+o.addClassFocus);
						}else if(!o.addParentFocus == false){
							_this.parents(o.addParentFocus).removeClass('parent-'+o.addClassFocus);
						}
					}
				});
			}
		});
	}
	function inputsSwap(el, el2){
		if(el) el.hide();
		if(el2) el2.show();
	}
}

var types = ['DOMMouseScroll', 'mousewheel'];
jQuery.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener )
			for ( var i=types.length; i; )
				this.addEventListener( types[--i], handler, false );
		else
			this.onmousewheel = handler;
	},
	teardown: function() {
		if ( this.removeEventListener )
			for ( var i=types.length; i; )
				this.removeEventListener( types[--i], handler, false );
		else
			this.onmousewheel = null;
	}
};
jQuery.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});
function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	event = jQuery.event.fix(event || window.event);
	event.type = "mousewheel";
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	// Add events and delta to the front of the arguments
	args.unshift(event, delta);
	return jQuery.event.handle.apply(this, args);
}

/*--- function custom scroll ---*/
jQuery.fn.customScroll = function(_options) {
var _options = jQuery.extend({
	lineWidth: 24
}, _options);
return this.each(function(){
	var _box = jQuery(this);
	if(_box.is(':visible')){
		if(_box.children('.scroll-content').length == 0){
			var line_w = _options.lineWidth;
			/*--- init part ---*/
			var scrollBar = jQuery('<div class="vscroll-bar"> \
			<div class="vscroll-up"></div> \
				<div class="vscroll-line"> \
					<div class="vscroll-slider"><div class="vscroll-slider-top"></div><div class="vscroll-slider-bottom"></div></div> \
				</div> \
			<div class="vscroll-down"></div></div>');
			_box.wrapInner('<div class="scroll-content"></div>').append(scrollBar);
			var scrollContent = _box.children('.scroll-content');
			var scrollSlider = scrollBar.find('.vscroll-slider');
			var scrollSliderH = scrollSlider.parent();
			var scrollUp = scrollBar.find('.vscroll-up');
			var scrollDown = scrollBar.find('.vscroll-down');
			/*--- different variables ---*/
			var box_h = _box.height();
			var box_w = _box.width();
			var slider_h = 0;
			var slider_f = 0;
			var cont_h = scrollContent.height();
			var _f = false;
			var _f1 = false;
			var _f2 = true;
			var _t1, _t2, _s1, _s2;
			/*--- set styles ---*/
			_box.css({
				position: 'relative',
				overflow: 'hidden',
				width: box_w,
				height: box_h
			});
			scrollContent.css({
				position: 'absolute',
				top: 0,
				left: 0,
				zIndex: 1,
				width: box_w - line_w,
				height: 'auto'
			});
			scrollBar.css({
				position: 'absolute',
				top: 0,
				left: box_w - line_w,
				zIndex:2,
				width: line_w,
				height: box_h,
				overflow: 'hidden'
			});
			scrollUp.css({
				width: line_w,
				height: 0,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			scrollDown.css({
				width: line_w,
				height: 0,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			slider_h = scrollBar.height();
			if(scrollUp.is(':visible')) slider_h -= scrollUp.height();
			if(scrollDown.is(':visible')) slider_h -= scrollDown.height();
			scrollSliderH.css({
				position: 'relative',
				width: line_w,
				height: slider_h,
				overflow: 'hidden'
			});
			slider_h = 0;
			scrollSlider.css({
				position: 'absolute',
				top: 0,
				left: 0,
				width: line_w,
				height: slider_h,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			box_h = _box.height();
			cont_h = scrollContent.height();
			if(box_h < cont_h){
				_f = true;
				slider_h = Math.round(box_h/cont_h*scrollSliderH.height());
				if(slider_h < 5) slider_h = 5;
				scrollSlider.height(slider_h).find('> .center').height(slider_h-8);
				slider_h = scrollSlider.height();
				slider_f = (cont_h - box_h)/(scrollSliderH.height() - scrollSlider.height());
				_s1 = (scrollSliderH.height() - scrollSlider.height())/20;
				_s2 = (scrollSliderH.height() - scrollSlider.height())/3;
			}
			else{
				_f = false;
				scrollBar.hide();
				scrollContent.css({width: _box.width(), top: 0, left:0});
			}
			var _top = 0;
			/*--- element's events ---*/
			scrollUp.mousedown(function(){
				_top -= _s1;
				scrollCont();
				_t1 = setTimeout(function(){
					_t2 = setInterval(function(){
						_top -= 4/slider_f;
						scrollCont();
					}, 20);
				}, 500);
			}).mouseup(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			}).mouseleave(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			});
			scrollDown.mousedown(function(){
				_top += _s1;
				scrollCont();
				_t1 = setTimeout(function(){
					_t2 = setInterval(function(){
						_top += 4/slider_f;
						scrollCont();
					}, 20);
				}, 500);
			}).mouseup(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			}).mouseleave(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			});
			scrollSliderH.click(function(e){
				if(_f2){
					if(scrollSlider.offset().top + slider_h < e.pageY){
						_top += _s2;
					}
					else if(scrollSlider.offset().top > e.pageY){
						_top -= _s2;
					}
					scrollCont();
				}
				else{
					_f2 = true;
				}
			});
			var t_y = 0;
			scrollSlider.mousedown(function(e){
				_box.css({'-moz-user-select':'none', '-khtml-user-select': 'none', 'user-select':'none'});
				t_y = e.pageY - jQuery(this).position().top;
				_f1 = true;
			}).mouseup(function(){
				_f1 = false;
				_box.css({'-moz-user-select':'', '-khtml-user-select': '', 'user-select':''});
			});
			jQuery('body').mousemove(function(e){
				if(_f1){
					 _f2 = false;
					 _top = e.pageY - t_y;
					 scrollCont();
				}
			}).mouseup(function(){
				_f1 = false;
				_box.css({'-moz-user-select':'', '-khtml-user-select': '', 'user-select':''});
			});
			document.body.onselectstart = function(){if(_f1) return false;}
			_box.bind('mousewheel', function(event, delta){
				if(_f){
					_top -=delta*_s1;
					scrollCont();
					if((_top > 0) && (_top+slider_h < scrollSliderH.height())) return false;
				}
			});
			function scrollCont(){
				if(_top < 0) _top = 0;
				else if(_top+slider_h > scrollSliderH.height()) _top = scrollSliderH.height() - slider_h;
				scrollSlider.css('top', _top);
				scrollContent.css('top', -_top*slider_f);
			}
			this.scrollResize = function(){
				box_h = _box.height();
				cont_h = scrollContent.height();
				if(box_h < cont_h){
					_f = true;
					scrollBar.show();
					scrollContent.width(box_w - line_w);
					slider_h = Math.round(box_h/cont_h*scrollSliderH.height());
					if(slider_h < 5) slider_h = 5;
					scrollSlider.height(slider_h);
					slider_h = scrollSlider.height();
					slider_f = (cont_h - box_h)/(scrollSliderH.height() - scrollSlider.height());
					if(cont_h + scrollContent.position().top < box_h) scrollContent.css('top', -(cont_h - box_h));
					_top = - scrollContent.position().top/slider_f;
					scrollSlider.css('top', _top);
					_s1 = (scrollSliderH.height() - scrollSlider.height())/20;
					_s2 = (scrollSliderH.height() - scrollSlider.height())/3;
				}
				else{
					_f = false;
					scrollBar.hide();
					scrollContent.css({width: _box.width(), top: 0, left:0});
				}
			}
			/*
			setInterval(function(){
				if(_box.is(':visible') && cont_h != scrollContent.height()) _box.get(0).scrollResize();
			}, 200);
			*/
		}
		else{
			this.scrollResize();
		}
	}
});
}

/* Copyright (c) 2009 Brandon Aaron (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.
 *
 * Version: 3.0.2
 *
 * Requires: 1.2.2+
 */
;(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);

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