/* Interface Elements for jQuery - FX (REI modified)
 * http://interface.eyecon.ro
 * Copyright (c) 2006 Stefan Petre
 * Dual licensed under the MIT and GPL licenses
 */
jQuery.fx.cssProps={borderBottomWidth:1,borderLeftWidth:1,borderRightWidth:1,borderTopWidth:1,bottom:1,fontSize:1,height:1,left:1,letterSpacing:1,lineHeight:1,marginBottom:1,marginLeft:1,marginRight:1,marginTop:1,maxHeight:1,maxWidth:1,minHeight:1,minWidth:1,opacity:1,outlineOffset:1,outlineWidth:1,paddingBottom:1,paddingLeft:1,paddingRight:1,paddingTop:1,right:1,textIndent:1,top:1,width:1,zIndex:1};jQuery.fx.colorCssProps={backgroundColor:1,borderBottomColor:1,borderLeftColor:1,borderRightColor:1,borderTopColor:1,color:1,outlineColor:1};jQuery.fx.cssSides=['Top','Right','Bottom','Left'];jQuery.fx.cssSidesEnd={'borderWidth':['border','Width'],'borderColor':['border','Color'],'margin':['margin',''],'padding':['padding','']};jQuery.fn.extend({animate:function(prop,speed,easing,callback){return this.queue(function(){var opt=jQuery.speed(speed,easing,callback);var e=new jQuery.fxe(this,opt,prop)})},pause:function(speed,callback){return this.queue(function(){var opt=jQuery.speed(speed,callback);var e=new jQuery.pause(this,opt)})},stop:function(step){return this.each(function(){if(this.animationHandler)jQuery.stopAnim(this,step)})},stopAll:function(step){return this.each(function(){if(this.animationHandler)jQuery.stopAnim(this,step);if(this.queue&&this.queue['fx'])this.queue.fx=[]})}});jQuery.extend({pause:function(elem,options){var z=this,values;z.step=function(){if(jQuery.isFunction(options.complete))options.complete.apply(elem)};z.timer=setInterval(function(){z.step()},options.duration);elem.animationHandler=z},easing:{linear:function(p,n,firstNum,delta,duration){return((-Math.cos(p*Math.PI)/2)+0.5)*delta+firstNum}},fxe:function(elem,options,prop){var z=this,values;var y=elem.style;var oldOverflow=jQuery.css(elem,"overflow");var oldDisplay=jQuery.css(elem,"display");var props={};z.startTime=(new Date()).getTime();options.easing=options.easing&&jQuery.easing[options.easing]?options.easing:'linear';z.getValues=function(tp,vp){if(jQuery.fx.cssProps[tp]){if(vp=='show'||vp=='hide'||vp=='toggle'){if(!elem.orig)elem.orig={};var r=parseFloat(jQuery.curCSS(elem,tp));elem.orig[tp]=r&&r>-10000?r:(parseFloat(jQuery.css(elem,tp))||0);vp=vp=='toggle'?(oldDisplay=='none'?'show':'hide'):vp;options[vp]=true;props[tp]=vp=='show'?[0,elem.orig[tp]]:[elem.orig[tp],0];if(tp!='opacity')y[tp]=props[tp][0]+(tp!='zIndex'&&tp!='fontWeight'?'px':'');else jQuery.attr(y,"opacity",props[tp][0])}else{props[tp]=[parseFloat(jQuery.curCSS(elem,tp)),parseFloat(vp)||0]}}else if(jQuery.fx.colorCssProps[tp])props[tp]=[jQuery.fx.parseColor(jQuery.curCSS(elem,tp)),jQuery.fx.parseColor(vp)];else if(/^margin$|padding$|border$|borderColor$|borderWidth$/i.test(tp)){var m=vp.replace(/\s+/g,' ').replace(/rgb\s*\(\s*/g,'rgb(').replace(/\s*,\s*/g,',').replace(/\s*\)/g,')').match(/([^\s]+)/g);switch(tp){case'margin':case'padding':case'borderWidth':case'borderColor':m[3]=m[3]||m[1]||m[0];m[2]=m[2]||m[0];m[1]=m[1]||m[0];for(var i=0;i<jQuery.fx.cssSides.length;i++){var nmp=jQuery.fx.cssSidesEnd[tp][0]+jQuery.fx.cssSides[i]+jQuery.fx.cssSidesEnd[tp][1];props[nmp]=tp=='borderColor'?[jQuery.fx.parseColor(jQuery.curCSS(elem,nmp)),jQuery.fx.parseColor(m[i])]:[parseFloat(jQuery.curCSS(elem,nmp)),parseFloat(m[i])]}break;case'border':for(var i=0;i<m.length;i++){var floatVal=parseFloat(m[i]);var sideEnd=!isNaN(floatVal)?'Width':(!/transparent|none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset/i.test(m[i])?'Color':false);if(sideEnd){for(var j=0;j<jQuery.fx.cssSides.length;j++){nmp='border'+jQuery.fx.cssSides[j]+sideEnd;props[nmp]=sideEnd=='Color'?[jQuery.fx.parseColor(jQuery.curCSS(elem,nmp)),jQuery.fx.parseColor(m[i])]:[parseFloat(jQuery.curCSS(elem,nmp)),floatVal]}}else{y['borderStyle']=m[i]}}break}}else{y[tp]=vp}return false};for(p in prop){if(p=='style'){var newStyles=jQuery.parseStyle(prop[p]);for(np in newStyles){this.getValues(np,newStyles[np])}}else if(p=='className'){if(document.styleSheets)for(var i=0;i<document.styleSheets.length;i++){var cssRules=document.styleSheets[i].cssRules||document.styleSheets[i].rules||null;if(cssRules){for(var j=0;j<cssRules.length;j++){if(cssRules[j].selectorText=='.'+prop[p]){var rule=new RegExp('\.'+prop[p]+' {');var styles=cssRules[j].style.cssText;var newStyles=jQuery.parseStyle(styles.replace(rule,'').replace(/}/g,''));for(np in newStyles){this.getValues(np,newStyles[np])}}}}}}else{this.getValues(p,prop[p])}}y.display=oldDisplay=='none'?'block':oldDisplay;y.overflow='hidden';z.step=function(){var t=(new Date()).getTime();if(t>options.duration+z.startTime){clearInterval(z.timer);z.timer=null;for(p in props){if(p=="opacity")jQuery.attr(y,"opacity",props[p][1]);else if(typeof props[p][1]=='object')y[p]='rgb('+props[p][1].r+','+props[p][1].g+','+props[p][1].b+')';else y[p]=props[p][1]+(p!='zIndex'&&p!='fontWeight'?'px':'')}if(options.hide||options.show)for(var p in elem.orig)if(p=="opacity")jQuery.attr(y,p,elem.orig[p]);else y[p]="";y.display=options.hide?'none':(oldDisplay!='none'?oldDisplay:'block');y.overflow=oldOverflow;elem.animationHandler=null;if(jQuery.isFunction(options.complete))options.complete.apply(elem)}else{var n=t-this.startTime;var pr=n/options.duration;for(p in props){if(typeof props[p][1]=='object'){y[p]='rgb('+parseInt(jQuery.easing[options.easing](pr,n,props[p][0].r,(props[p][1].r-props[p][0].r),options.duration))+','+parseInt(jQuery.easing[options.easing](pr,n,props[p][0].g,(props[p][1].g-props[p][0].g),options.duration))+','+parseInt(jQuery.easing[options.easing](pr,n,props[p][0].b,(props[p][1].b-props[p][0].b),options.duration))+')'}else{var pValue=jQuery.easing[options.easing](pr,n,props[p][0],(props[p][1]-props[p][0]),options.duration);if(p=="opacity")jQuery.attr(y,"opacity",pValue);else y[p]=pValue+(p!='zIndex'&&p!='fontWeight'?'px':'')}}}};z.timer=setInterval(function(){z.step()},13);elem.animationHandler=z},stopAnim:function(elem,step){if(step)elem.animationHandler.startTime-=100000000;else{window.clearInterval(elem.animationHandler.timer);elem.animationHandler=null;jQuery.dequeue(elem,"fx")}}});jQuery.parseStyle=function(styles){var newStyles={};if(typeof styles=='string'){styles=styles.toLowerCase().split(';');for(var i=0;i<styles.length;i++){rule=styles[i].split(':');if(rule.length==2){newStyles[jQuery.trim(rule[0].replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}))]=jQuery.trim(rule[1])}}}return newStyles};

/* Monitor Font Size Changes with jQuery @version 1.0
 * @author Dave Cardwell
 * jQuery-Em - $Revision: 24 $ ($Date: 2007-08-19 11:24:56 +0100 (Sun, 19 Aug 2007) $)
 * Copyright ©2007 Dave Cardwell <http://davecardwell.co.uk/>
 * Released under the MIT licence: http://www.opensource.org/licenses/mit-license.php
 */
jQuery(function($){var eventName='emchange';$.em=$.extend({version:'1.0',delay:200,element:$('<div />').css({left:'-100em',position:'absolute',width:'100em'}).prependTo('body')[0],action:function(){var currentWidth=$.em.element.offsetWidth/100;if(currentWidth!=$.em.current){$.em.previous=$.em.current;$.em.current=currentWidth;$.event.trigger(eventName,[$.em.current,$.em.previous])}}},$.em);$.fn[eventName]=function(fn){return fn?this.bind(eventName,fn):this.trigger(eventName)};$.em.current=$.em.element.offsetWidth/100;$.em.iid=setInterval($.em.action,$.em.delay)});

/* jQuery Dimensions
 *	Copyright (c) 2007 Paul Bakaus and Brandon Aaron - http://brandonaaron.net)
 * Dual licensed under the MIT and GPL licenses.
 * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4257 $
 * Version: 1.2
 */
(function($){$.dimensions={version:'1.2'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return this.is(':visible')?this[0]['client'+name]:num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});var val=this.is(':visible')?this[0]['offset'+name]:num(this,name.toLowerCase())+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')+num(this,'padding'+torl)+num(this,'padding'+borr);return val+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;};})(jQuery);

/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT and GPL licenses.
 * $LastChangedDate: 2007-06-20 16:25:35 -0500 (Wed, 20 Jun 2007) $
 * $Rev: 2125 $
 * Version: 2.2
 */
(function($){$.fn.extend({mousewheel:function(f){if(!f.guid)f.guid=$.event.guid++;if(!$.event._mwCache)$.event._mwCache=[];return this.each(function(){if(this._mwHandlers)return this._mwHandlers.push(f);else this._mwHandlers=[];this._mwHandlers.push(f);var s=this;this._mwHandler=function(e){e=$.event.fix(e||window.event);$.extend(e,this._mwCursorPos||{});var delta=0,returnValue=true;if(e.wheelDelta)delta=e.wheelDelta/120;if(e.detail)delta=-e.detail/3;if(window.opera)delta=-e.wheelDelta;for(var i=0;i<s._mwHandlers.length;i++)if(s._mwHandlers[i])if(s._mwHandlers[i].call(s,e,delta)===false){returnValue=false;e.preventDefault();e.stopPropagation();}return returnValue;};if($.browser.mozilla&&!this._mwFixCursorPos){this._mwFixCursorPos=function(e){this._mwCursorPos={pageX:e.pageX,pageY:e.pageY,clientX:e.clientX,clientY:e.clientY};};$(this).bind('mousemove',this._mwFixCursorPos);}if(this.addEventListener)if($.browser.mozilla)this.addEventListener('DOMMouseScroll',this._mwHandler,false);else this.addEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=this._mwHandler;$.event._mwCache.push($(this));});},unmousewheel:function(f){return this.each(function(){if(f&&this._mwHandlers){for(var i=0;i<this._mwHandlers.length;i++)if(this._mwHandlers[i]&&this._mwHandlers[i].guid==f.guid)delete this._mwHandlers[i];}else{if($.browser.mozilla&&!this._mwFixCursorPos)$(this).unbind('mousemove',this._mwFixCursorPos);if(this.addEventListener)if($.browser.mozilla)this.removeEventListener('DOMMouseScroll',this._mwHandler,false);else this.removeEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=null;this._mwHandlers=this._mwHandler=this._mwFixCursorPos=this._mwCursorPos=null;}});}});$(window).one('unload',function(){var els=$.event._mwCache||[];for(var i=0;i<els.length;i++)els[i].unmousewheel();});})(jQuery);

/* Interface Elements for jQuery
 * Easing formulas (REI modified)
 * http://interface.eyecon.ro
 * Copyright (c) 2006 Stefan Petre
 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
 */
jQuery.extend({easing:{linear:function(p,n,firstNum,delta,duration){return((-Math.cos(p*Math.PI)/2)+0.5)*delta+firstNum},easein:function(p,n,firstNum,delta,duration){return delta*(n/=duration)*n*n+firstNum},easeout:function(p,n,firstNum,delta,duration){return-delta*((n=n/duration-1)*n*n*n-1)+firstNum}}});

/* jScrollPane (REI modified) Copyright (c) 2006 Kelvin Luck (http://www.kelvinluck.com)
 * Dual licensed under the MIT and GPL licenses.
 * $Id: jScrollPane.js 4702 2008-02-09 10:19:47Z kelvin.luck $
 */
jQuery.jScrollPane = {active : []};
jQuery.fn.jScrollPane = function(settings)
{
	settings = jQuery.extend(
		{
			scrollbarWidth : 6,
			scrollbarMargin :0,
			wheelSpeed : 18,
			showArrows : false,
			arrowSize : 0,
			animateTo : false,
			dragMinHeight : 1,
			dragMaxHeight : 99999,
			animateInterval : 100,
			animateStep: 3,
			maintainPosition: false,
			scrollbarOnLeft: false
		}, settings
	);
	return this.each(
		function()
		{
			var $this = jQuery(this);
			
			if (jQuery(this).parent().is('.jScrollPaneContainer')) {
				var currentScrollPosition = settings.maintainPosition ? $this.offset({relativeTo:jQuery(this).parent()[0]}).top : 0;
				var $c = jQuery(this).parent();
				var paneWidth = $c.innerWidth();
				var paneHeight = $c.outerHeight();
				var trackHeight = paneHeight;
				if ($c.unmousewheel) {
					$c.unmousewheel();
				}
				jQuery('>.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown', $c).remove();
				$this.css({'top':0});
			} else {
				var currentScrollPosition = 0;
				this.originalPadding = $this.css('paddingTop') + ' ' + $this.css('paddingRight') + ' ' + $this.css('paddingBottom') + ' ' + $this.css('paddingLeft');
				this.originalSidePaddingTotal = (parseInt($this.css('paddingLeft')) || 0) + (parseInt($this.css('paddingRight')) || 0);
				var paneWidth = $this.innerWidth();
				var paneHeight = $this.innerHeight();
				var trackHeight = paneHeight;
				$this.wrap(
					jQuery('<div></div>').attr(
						{'className':'jScrollPaneContainer'}
					)
				);
				jQuery(document).bind(
					'emchange', 
					function(e, cur, prev){$this.jScrollPane(settings);}
				);
			}
			var p = this.originalSidePaddingTotal;
			
			var cssToApply = {'height':'auto'}
			$this.css(cssToApply);
			var contentHeight = $this.outerHeight();
			var percentInView = paneHeight / contentHeight;

			if (percentInView < .99) {
				$(this).addClass('hasScroll')
				var $container = $this.parent();
				$container.append(
					jQuery('<div></div>').attr({'className':'jScrollPaneTrack'}).css({'width':settings.scrollbarWidth+'px'}).append(
						jQuery('<div></div>').attr({'className':'jScrollPaneDrag'}).css({'width':settings.scrollbarWidth+'px'}).append(
							jQuery('<div></div>').attr({'className':'jScrollPaneDragTop'}).css({'width':settings.scrollbarWidth+'px'}),
							jQuery('<div></div>').attr({'className':'jScrollPaneDragBottom'}).css({'width':settings.scrollbarWidth+'px'})
						)
					)
				);
				
				var $track = jQuery('>.jScrollPaneTrack', $container);
				var $drag = jQuery('>.jScrollPaneTrack .jScrollPaneDrag', $container);
				var $pane = jQuery(this).css({'position':'absolute', 'overflow':'visible'});
				var currentOffset;
				var maxY;
				var mouseWheelMultiplier;
				var dragPosition = 0;
				var dragMiddle = percentInView*paneHeight/2;
				var getPos = function (event, c) {
					var p = c == 'X' ? 'Left' : 'Top';
					return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
				};
				
				var ignoreNativeDrag = function() {	return false; };
				
				var initDrag = function()
				{
					ceaseAnimation();
					currentOffset = $drag.offset(false);
					currentOffset.top -= dragPosition;
					maxY = trackHeight - $drag[0].offsetHeight;
					mouseWheelMultiplier = 2 * settings.wheelSpeed * maxY / contentHeight;
				};
				
				var onStartDrag = function(event)
				{
					initDrag();
					dragMiddle = getPos(event, 'Y') - dragPosition - currentOffset.top;
					jQuery('html').bind('mouseup', onStopDrag).bind('mousemove', updateScroll);
					if (jQuery.browser.msie) {
						jQuery('html').bind('dragstart', ignoreNativeDrag).bind('selectstart', ignoreNativeDrag);
					}
					return false;
				};
				var onStopDrag = function()
				{
					jQuery('html').unbind('mouseup', onStopDrag).unbind('mousemove', updateScroll);
					dragMiddle = percentInView*paneHeight/2;
					if (jQuery.browser.msie) {jQuery('html').unbind('dragstart', ignoreNativeDrag).unbind('selectstart', ignoreNativeDrag);}
				};
				var positionDrag = function(destY)
				{
					destY = destY < 0 ? 0 : (destY > maxY ? maxY : destY);
					dragPosition = destY;
					$drag.css({'top':destY+'px'});
					var p = destY / maxY;
					$pane.css({'top':((paneHeight-contentHeight)*p) + 'px'});
					$this.trigger('scroll');
				};
				var updateScroll = function(e){positionDrag(getPos(e, 'Y') - currentOffset.top - dragMiddle);};
				
				var dragH = Math.max(Math.min(percentInView*(paneHeight-settings.arrowSize*2), settings.dragMaxHeight), settings.dragMinHeight);
				
				$drag.css({'height':dragH+'px'}).bind('mousedown', onStartDrag);
				
				var trackScrollInterval;
				var trackScrollInc;
				var trackScrollMousePos;
				var doTrackScroll = function()
				{
					if (trackScrollInc > 8 || trackScrollInc%4==0) {
						positionDrag((dragPosition - ((dragPosition - trackScrollMousePos) / 2)));
					}
					trackScrollInc ++;
				};
				var onStopTrackClick = function()
				{
					clearInterval(trackScrollInterval);
					jQuery('html').unbind('mouseup', onStopTrackClick).unbind('mousemove', onTrackMouseMove);
				};
				var onTrackMouseMove = function(event)
				{
					trackScrollMousePos = getPos(event, 'Y') - currentOffset.top - dragMiddle;
				};
				var onTrackClick = function(event)
				{
					initDrag();
					onTrackMouseMove(event);
					trackScrollInc = 0;
					jQuery('html').bind('mouseup', onStopTrackClick).bind('mousemove', onTrackMouseMove);
					trackScrollInterval = setInterval(doTrackScroll, 100);
					doTrackScroll();
				};
				
				$track.bind('mousedown', onTrackClick);
				
				if ($container.mousewheel) {
					$container.mousewheel(
						function (event, delta) {
							initDrag();
							ceaseAnimation();
							var d = dragPosition;
							positionDrag(dragPosition - delta * mouseWheelMultiplier);
							var dragOccured = d != dragPosition;
							return !dragOccured;
						},
						false
					);					
				}
				var _animateToPosition;
				var _animateToInterval;
				function animateToPosition()
				{
					var diff = (_animateToPosition - dragPosition) / settings.animateStep;
					if (diff > 1 || diff < -1) {
						positionDrag(dragPosition + diff);
					} else {
						positionDrag(_animateToPosition);
						ceaseAnimation();
					}
				}
				var ceaseAnimation = function()
				{
					if (_animateToInterval) {
						clearInterval(_animateToInterval);
						delete _animateToPosition;
					}
				};
				var scrollTo = function(pos, preventAni)
				{
					if (typeof pos == "string") {
						$e = jQuery(pos, this);
						if (!$e.length) return;
						pos = $e.offset().top - $this.offset().top;
					}
					ceaseAnimation();
					var destDragPosition = -pos/(paneHeight-contentHeight) * maxY;
					if (!preventAni || settings.animateTo) {
						_animateToPosition = destDragPosition;
						_animateToInterval = setInterval(animateToPosition, settings.animateInterval);
					} else {
						positionDrag(destDragPosition);
					}
				};

				$this[0].scrollTo = scrollTo;
				$this[0].scrollBy = function(delta)
				{
					var currentPos = -parseInt($pane.css('top')) || 0;
					scrollTo(currentPos + delta);
				};
				
				initDrag();
				scrollTo(-currentScrollPosition, true);
				jQuery.jScrollPane.active.push($this[0]);

			} else {
				$this.css(
					{
						'height':paneHeight+'px',
						'width':paneWidth-this.originalSidePaddingTotal+'px',
						'padding':this.originalPadding
					}
				);
			}
			
		}
	)
};

