/*

Copyright (c) 2009 Dimas Begunoff, http://www.farinspace.com

Licensed under the MIT license
http://en.wikipedia.org/wiki/MIT_License

*/

function imgpreload(a,b){if(b instanceof Function){b={all:b}}if(typeof a=="string"){a=[a]}var c=[];var t=a.length;var i=0;for(i;i<t;i++){var d=new Image();d.onload=function(){c.push(this);if(b.each instanceof Function){b.each.call(this)}if(c.length>=t&&b.all instanceof Function){b.all.call(c)}};d.src=a[i]}}if(typeof jQuery!="undefined"){(function($){$.imgpreload=imgpreload;$.fn.imgpreload=function(b){b=$.extend({},$.fn.imgpreload.defaults,(b instanceof Function)?{all:b}:b);this.each(function(){var a=this;imgpreload($(this).attr('src'),function(){if(b.each instanceof Function){b.each.call(a)}})});var c=[];this.each(function(){c.push($(this).attr('src'))});var d=this;imgpreload(c,function(){if(b.all instanceof Function){b.all.call(d)}});return this};$.fn.imgpreload.defaults={each:null,all:null}})(jQuery)};
/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */;
/*!
jquery scroll - a custom stylable scrollbar
Version 0.4
https://github.com/thomd/jquery-scroll
Copyright (c) 2011 Thomas Duerr (me-at-thomd-dot-net)
Licensed under the MIT license (https://raw.github.com/thomd/jquery-scroll/master/MIT-LICENSE)
*/(function($,document){var methods={init:function(fn,opts){var options=$.extend({},$.fn.scrollbar.defaults,opts);return this.each(function(){var container=$(this),props={arrows:options.arrows};options.containerHeight!="auto"&&container.height(options.containerHeight),props.containerHeight=container.height(),props.contentHeight=$.fn.scrollbar.contentHeight(container);if(props.contentHeight<=props.containerHeight)return!0;this.scrollbar=new $.fn.scrollbar.Scrollbar(container,props,options),this.scrollbar.buildHtml().setHandle().appendEvents(),typeof fn=="function"&&fn(container.find(".scrollbar-pane"),this.scrollbar)})},repaint:function(){return this.each(function(){this.scrollbar.repaint()})},scrollto:function(to){return this.each(function(){this.scrollbar.scrollto(to)})}};$.fn.scrollbar=function(method){if(methods[method])return methods[method].apply(this,Array.prototype.slice.call(arguments,1));if(typeof method=="function"||method===undefined)return methods.init.apply(this,arguments);if(typeof method=="object")return methods.init.apply(this,[null,method]);$.error("method '"+method+"' does not exist for $.fn.scrollbar")},$.fn.scrollbar.defaults={containerHeight:"auto",arrows:!0,handleHeight:"auto",handleMinHeight:30,scrollTimeout:50,scrollStep:20,scrollTimeoutArrows:40,scrollStepArrows:3},$.fn.scrollbar.Scrollbar=function(container,props,options){this.container=container,this.props=props,this.opts=options,this.mouse={},this.props.arrows=this.container.hasClass("no-arrows")?!1:this.props.arrows},$.fn.scrollbar.Scrollbar.prototype={buildHtml:function(){this.container.wrapInner('<div class="scrollbar-pane"/>'),this.container.append('<div class="scrollbar-handle-container"><div class="scrollbar-handle"/></div>'),this.props.arrows&&this.container.append('<div class="scrollbar-handle-up"/>').append('<div class="scrollbar-handle-down"/>');var height=this.container.height();return this.pane=this.container.find(".scrollbar-pane"),this.handle=this.container.find(".scrollbar-handle"),this.handleContainer=this.container.find(".scrollbar-handle-container"),this.handleArrows=this.container.find(".scrollbar-handle-up, .scrollbar-handle-down"),this.handleArrowUp=this.container.find(".scrollbar-handle-up"),this.handleArrowDown=this.container.find(".scrollbar-handle-down"),this.pane.defaultCss({top:0,left:0}),this.handleContainer.defaultCss({right:0}),this.handle.defaultCss({top:0,right:0}),this.handleArrows.defaultCss({right:0}),this.handleArrowUp.defaultCss({top:0}),this.handleArrowDown.defaultCss({bottom:0}),this.container.css({position:this.container.css("position")==="absolute"?"absolute":"relative",overflow:"hidden",height:height}),this.pane.css({position:"absolute",overflow:"visible",height:"auto"}),this.handleContainer.css({position:"absolute",top:this.handleArrowUp.outerHeight(!0),height:this.props.containerHeight-this.handleArrowUp.outerHeight(!0)-this.handleArrowDown.outerHeight(!0)+"px"}),this.handle.css({position:"absolute",cursor:"pointer"}),this.handleArrows.css({position:"absolute",cursor:"pointer"}),this.pane.top=0,this},setHandle:function(){return this.props.handleContainerHeight=this.handleContainer.height(),this.props.contentHeight=this.pane.height(),this.props.handleHeight=this.opts.handleHeight=="auto"?Math.max(Math.ceil(this.props.containerHeight*this.props.handleContainerHeight/this.props.contentHeight),this.opts.handleMinHeight):this.opts.handleHeight,this.handle.height(this.props.handleHeight),this.handle.height(2*this.handle.height()-this.handle.outerHeight(!0)),this.props.handlePosition={min:0,max:this.props.handleContainerHeight-this.props.handleHeight},this.props.handleContentRatio=(this.props.contentHeight-this.props.containerHeight)/(this.props.handleContainerHeight-this.props.handleHeight),this.handle.top==undefined?this.handle.top=0:this.handle.top=-1*this.pane.top/this.props.handleContentRatio,this},appendEvents:function(){return this.handle.bind("mousedown.handle",$.proxy(this,"startOfHandleMove")),this.handleContainer.bind("mousedown.handle",$.proxy(this,"onHandleContainerMousedown")),this.handleContainer.bind("mouseenter.container mouseleave.container",$.proxy(this,"onHandleContainerHover")),this.handleArrows.bind("mousedown.arrows",$.proxy(this,"onArrowsMousedown")),this.container.bind("mousewheel.container",$.proxy(this,"onMouseWheel")),this.container.bind("mouseenter.container mouseleave.container",$.proxy(this,"onContentHover")),this.handle.bind("click.scrollbar",this.preventClickBubbling),this.handleContainer.bind("click.scrollbar",this.preventClickBubbling),this.handleArrows.bind("click.scrollbar",this.preventClickBubbling),this},mousePosition:function(ev){return ev.pageY||ev.clientY+(document.documentElement.scrollTop||document.body.scrollTop)||0},repaint:function(){this.setHandle(),this.setHandlePosition()},scrollto:function(to){var distance=0;typeof to=="number"?distance=(to<0?0:to)/this.props.handleContentRatio:typeof to=="string"?(to=="bottom"&&(distance=this.props.handlePosition.max),to=="middle"&&(distance=Math.ceil(this.props.handlePosition.max/2))):typeof to=="object"&&!$.isPlainObject(to)&&(distance=Math.ceil(to.position().top/this.props.handleContentRatio)),this.handle.top=distance,this.setHandlePosition(),this.setContentPosition()},startOfHandleMove:function(ev){ev.preventDefault(),ev.stopPropagation(),this.mouse.start=this.mousePosition(ev),this.handle.start=this.handle.top,$(document).bind("mousemove.handle",$.proxy(this,"onHandleMove")).bind("mouseup.handle",$.proxy(this,"endOfHandleMove")),this.handle.addClass("move"),this.handleContainer.addClass("move")},onHandleMove:function(ev){ev.preventDefault();var distance=this.mousePosition(ev)-this.mouse.start;this.handle.top=this.handle.start+distance,this.setHandlePosition(),this.setContentPosition()},endOfHandleMove:function(ev){$(document).unbind(".handle"),this.handle.removeClass("move"),this.handleContainer.removeClass("move")},setHandlePosition:function(){this.handle.top=this.handle.top>this.props.handlePosition.max?this.props.handlePosition.max:this.handle.top,this.handle.top=this.handle.top<this.props.handlePosition.min?this.props.handlePosition.min:this.handle.top,this.handle[0].style.top=this.handle.top+"px"},setContentPosition:function(){this.pane.top=-1*this.props.handleContentRatio*this.handle.top,this.pane[0].style.top=this.pane.top+"px"},onMouseWheel:function(ev,delta){this.handle.top-=delta,this.setHandlePosition(),this.setContentPosition(),this.handle.top>this.props.handlePosition.min&&this.handle.top<this.props.handlePosition.max&&ev.preventDefault()},onHandleContainerMousedown:function(ev){ev.preventDefault();if(!$(ev.target).hasClass("scrollbar-handle-container"))return!1;this.handle.direction=this.handle.offset().top<this.mousePosition(ev)?1:-1,this.handle.step=this.opts.scrollStep;var that=this;$(document).bind("mouseup.handlecontainer",function(){clearInterval(timer),that.handle.unbind("mouseenter.handlecontainer"),$(document).unbind("mouseup.handlecontainer")}),this.handle.bind("mouseenter.handlecontainer",function(){clearInterval(timer)});var timer=setInterval($.proxy(this.moveHandle,this),this.opts.scrollTimeout)},onArrowsMousedown:function(ev){ev.preventDefault(),this.handle.direction=$(ev.target).hasClass("scrollbar-handle-up")?-1:1,this.handle.step=this.opts.scrollStepArrows,$(ev.target).addClass("move");var timer=setInterval($.proxy(this.moveHandle,this),this.opts.scrollTimeoutArrows);$(document).one("mouseup.arrows",function(){clearInterval(timer),$(ev.target).removeClass("move")})},moveHandle:function(){this.handle.top=this.handle.direction===1?Math.min(this.handle.top+this.handle.step,this.props.handlePosition.max):Math.max(this.handle.top-this.handle.step,this.props.handlePosition.min),this.handle[0].style.top=this.handle.top+"px",this.setContentPosition()},onContentHover:function(ev){ev.type==="mouseenter"?(this.container.addClass("hover"),this.handleContainer.addClass("hover")):(this.container.removeClass("hover"),this.handleContainer.removeClass("hover"))},onHandleContainerHover:function(ev){ev.type==="mouseenter"?this.handleArrows.addClass("hover"):this.handleArrows.removeClass("hover")},preventClickBubbling:function(ev){ev.stopPropagation()}},$.fn.scrollbar.contentHeight=function(container){var wrapper=container.wrapInner("<div/>").find(":first"),height=wrapper.css({overflow:"hidden"}).height();/**/if(height==0) height=parseInt($('div.scrollable').height())+50;/**/return wrapper.replaceWith(wrapper.contents()),height},$.fn.defaultCss=function(styles){var notdef={right:"auto",left:"auto",top:"auto",bottom:"auto",position:"static"};return this.each(function(){var elem=$(this);for(var style in styles)elem.css(style)===notdef[style]&&elem.css(style,styles[style])})},$.event.special.mousewheel={setup:function(){this.addEventListener?(this.addEventListener("mousewheel",$.fn.scrollbar.mouseWheelHandler,!1),this.addEventListener("DOMMouseScroll",$.fn.scrollbar.mouseWheelHandler,!1)):this.onmousewheel=$.fn.scrollbar.mouseWheelHandler},teardown:function(){this.removeEventListener?(this.removeEventListener("mousewheel",$.fn.scrollbar.mouseWheelHandler,!1),this.removeEventListener("DOMMouseScroll",$.fn.scrollbar.mouseWheelHandler,!1)):this.onmousewheel=null}},$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel")},unmousewheel:function(fn){return this.unbind("mousewheel",fn)}}),$.fn.scrollbar.mouseWheelHandler=function(event){var orgEvent=event||window.event,args=[].slice.call(arguments,1),delta=0,returnValue=!0,deltaX=0,deltaY=0;return event=$.event.fix(orgEvent),event.type="mousewheel",event.wheelDelta&&(delta=event.wheelDelta/120),event.detail&&(delta=-event.detail/3),orgEvent.axis!==undefined&&orgEvent.axis===orgEvent.HORIZONTAL_AXIS&&(deltaY=0,deltaX=-1*delta),orgEvent.wheelDeltaY!==undefined&&(deltaY=orgEvent.wheelDeltaY/120),orgEvent.wheelDeltaX!==undefined&&(deltaX=-1*orgEvent.wheelDeltaX/120),args.unshift(event,delta,deltaX,deltaY),$.event.handle.apply(this,args)}})(jQuery,document);
/**
 * jQuery Plugin to obtain touch gestures from iPhone, iPod Touch and iPad, should also work with Android mobile phones (not tested yet!)
 * Common usage: wipe images (left and right to show the previous or next image)
 * 
 * @author Andreas Waltl, netCU Internetagentur (http://www.netcu.de)
 * @version 1.1.1 (9th December 2010) - fix bug (older IE's had problems)
 * @version 1.1 (1st September 2010) - support wipe up and wipe down
 * @version 1.0 (15th July 2010)
 */
(function($){$.fn.touchwipe=function(settings){var config={min_move_x:20,min_move_y:20,wipeLeft:function(){},wipeRight:function(){},wipeUp:function(){},wipeDown:function(){},preventDefaultEvents:true};if(settings)$.extend(config,settings);this.each(function(){var startX;var startY;var isMoving=false;function cancelTouch(){this.removeEventListener('touchmove',onTouchMove);startX=null;isMoving=false}function onTouchMove(e){if(config.preventDefaultEvents){e.preventDefault()}if(isMoving){var x=e.touches[0].pageX;var y=e.touches[0].pageY;var dx=startX-x;var dy=startY-y;if(Math.abs(dx)>=config.min_move_x){cancelTouch();if(dx>0){config.wipeLeft()}else{config.wipeRight()}}else if(Math.abs(dy)>=config.min_move_y){cancelTouch();if(dy>0){config.wipeDown()}else{config.wipeUp()}}}}function onTouchStart(e){if(e.touches.length==1){startX=e.touches[0].pageX;startY=e.touches[0].pageY;isMoving=true;this.addEventListener('touchmove',onTouchMove,false)}}if('ontouchstart'in document.documentElement){this.addEventListener('touchstart',onTouchStart,false)}});return this}})(jQuery);;
// version 1.4.0
// http://welcome.totheinter.net/columnizer-jquery-plugin/
// created by: Adam Wulf adam.wulf@gmail.com

(function($){

 $.fn.columnize = function(options) {


	var defaults = {
		// default width of columnx
		width: 400,
		// optional # of columns instead of width
		columns : false,
		// true to build columns once regardless of window resize
		// false to rebuild when content box changes bounds
		buildOnce : false,
		// an object with options if the text should overflow
		// it's container if it can't fit within a specified height
		overflow : false,
		// this function is called after content is columnized
		doneFunc : function(){},
		// if the content should be columnized into a 
		// container node other than it's own node
		target : false,
		// re-columnizing when images reload might make things
		// run slow. so flip this to true if it's causing delays
		ignoreImageLoading : true,
		// should columns float left or right
		float : "left",
		// ensure the last column is never the tallest column
		lastNeverTallest : false
	};
	var options = $.extend(defaults, options);

    return this.each(function() {
	    var $inBox = options.target ? $(options.target) : $(this);
		var maxHeight = $(this).height();
		var $cache = $('<div></div>'); // this is where we'll put the real content
		var lastWidth = 0;
		var columnizing = false;
		$cache.append($(this).children().clone(true));
	    
	    // images loading after dom load
	    // can screw up the column heights,
	    // so recolumnize after images load
	    if(!options.ignoreImageLoading && !options.target){
	    	if(!$inBox.data("imageLoaded")){
		    	$inBox.data("imageLoaded", true);
		    	if($(this).find("img").length > 0){
		    		// only bother if there are
		    		// actually images...
			    	var func = function($inBox,$cache){ return function(){
				    	if(!$inBox.data("firstImageLoaded")){
				    		$inBox.data("firstImageLoaded", "true");
					    	$inBox.empty().append($cache.children().clone(true));
					    	$inBox.columnize(options);
				    	}
			    	}}($(this), $cache);
				    $(this).find("img").one("load", func);
				    $(this).find("img").one("abort", func);
				    return;
		    	}
	    	}
	    }
	    
		$inBox.empty();
		
		columnizeIt();
		
		if(!options.buildOnce){
			$(window).resize(function() {
				if(!options.buildOnce && $.browser.msie){
					if($inBox.data("timeout")){
						clearTimeout($inBox.data("timeout"));
					}
					$inBox.data("timeout", setTimeout(columnizeIt, 200));
				}else if(!options.buildOnce){
					columnizeIt();
				}else{
					// don't rebuild
				}
			});
		}
		
		/**
		 * return a node that has a height
		 * less than or equal to height
		 *
		 * @param putInHere, a dom element
		 * @$pullOutHere, a jQuery element
		 */
		function columnize($putInHere, $pullOutHere, $parentColumn, height){
			while($parentColumn.height() < height &&
				  $pullOutHere[0].childNodes.length){
				$putInHere.append($pullOutHere[0].childNodes[0]);
			}
			if($putInHere[0].childNodes.length == 0) return;
			
			// now we're too tall, undo the last one
			var kids = $putInHere[0].childNodes;
			var lastKid = kids[kids.length-1];
			$putInHere[0].removeChild(lastKid);
			var $item = $(lastKid);
			
			
			if($item[0].nodeType == 3){
				// it's a text node, split it up
				var oText = $item[0].nodeValue;
				var counter2 = options.width / 18;
				if(options.accuracy)
				counter2 = options.accuracy;
				var columnText;
				var latestTextNode = null;
				while($parentColumn.height() < height && oText.length){
					if (oText.indexOf(' ', counter2) != '-1') {
						columnText = oText.substring(0, oText.indexOf(' ', counter2));
					} else {
						columnText = oText;
					}
					latestTextNode = document.createTextNode(columnText);
					$putInHere.append(latestTextNode);
					
					if(oText.length > counter2){
						oText = oText.substring(oText.indexOf(' ', counter2));
					}else{
						oText = "";
					}
				}
				if($parentColumn.height() >= height && latestTextNode != null){
					// too tall :(
					$putInHere[0].removeChild(latestTextNode);
					oText = latestTextNode.nodeValue + oText;
				}
				if(oText.length){
					$item[0].nodeValue = oText;
				}else{
					return false; // we ate the whole text node, move on to the next node
				}
			}
			
			if($pullOutHere.children().length){
				$pullOutHere.prepend($item);
			}else{
				$pullOutHere.append($item);
			}
			
			return $item[0].nodeType == 3;
		}
		
		function split($putInHere, $pullOutHere, $parentColumn, height){
			if($pullOutHere.children().length){
				$cloneMe = $pullOutHere.children(":first");
				$clone = $cloneMe.clone(true);
				if($clone.attr("nodeType") == 1 && !$clone.hasClass("dontend")){ 
					$putInHere.append($clone);
					if($clone.is("img") && $parentColumn.height() < height + 20){
						$cloneMe.remove();
					}else if(!$cloneMe.hasClass("dontsplit") && $parentColumn.height() < height + 20){
						$cloneMe.remove();
					}else if($clone.is("img") || $cloneMe.hasClass("dontsplit")){
						$clone.remove();
					}else{
						$clone.empty();
						if(!columnize($clone, $cloneMe, $parentColumn, height)){
							if($cloneMe.children().length){
								split($clone, $cloneMe, $parentColumn, height);
							}
						}
						if($clone.get(0).childNodes.length == 0){
							// it was split, but nothing is in it :(
							$clone.remove();
						}
					}
				}
			}
		}
		
		
		function singleColumnizeIt() {
			if ($inBox.data("columnized") && $inBox.children().length == 1) {
				return;
			}
			$inBox.data("columnized", true);
			$inBox.data("columnizing", true);
			
			$inBox.empty();
			$inBox.append($("<div class='first last column' style='width:98%; padding: 3px; float: " + options.float + ";'></div>")); //"
			$col = $inBox.children().eq($inBox.children().length-1);
			$destroyable = $cache.clone(true);
			if(options.overflow){
				targetHeight = options.overflow.height;
				columnize($col, $destroyable, $col, targetHeight);
				// make sure that the last item in the column isn't a "dontend"
				if(!$destroyable.children().find(":first-child").hasClass("dontend")){
					split($col, $destroyable, $col, targetHeight);
				}
				
				while(checkDontEndColumn($col.children(":last").length && $col.children(":last").get(0))){
					var $lastKid = $col.children(":last");
					$lastKid.remove();
					$destroyable.prepend($lastKid);
				}

				var html = "";
				var div = document.createElement('DIV');
				while($destroyable[0].childNodes.length > 0){
					var kid = $destroyable[0].childNodes[0];
					for(var i=0;i<kid.attributes.length;i++){
						if(kid.attributes[i].nodeName.indexOf("jQuery") == 0){
							kid.removeAttribute(kid.attributes[i].nodeName);
						}
					}
					div.innerHTML = "";
					div.appendChild($destroyable[0].childNodes[0]);
					html += div.innerHTML;
				}
				var overflow = $(options.overflow.id)[0];
				overflow.innerHTML = html;

			}else{
				$col.append($destroyable);
			}
			$inBox.data("columnizing", false);
			
			if(options.overflow){
				options.overflow.doneFunc();
			}
			
		}
		
		function checkDontEndColumn(dom){
			if(dom.nodeType != 1) return false;
			if($(dom).hasClass("dontend")) return true;
			if(dom.childNodes.length == 0) return false;
			return checkDontEndColumn(dom.childNodes[dom.childNodes.length-1]);
		}
		
		function columnizeIt() {
			if(lastWidth == $inBox.width()) return;
			lastWidth = $inBox.width();
			
			var numCols = Math.round($inBox.width() / options.width);
			if(options.columns) numCols = options.columns;
//			if ($inBox.data("columnized") && numCols == $inBox.children().length) {
//				return;
//			}
			if(numCols <= 1){
				return singleColumnizeIt();
			}
			if($inBox.data("columnizing")) return;
			$inBox.data("columnized", true);
			$inBox.data("columnizing", true);
			
			$inBox.empty();
			$inBox.append($("<div style='width:" + (Math.round(100 / numCols) - 2)+ "%; padding: 3px; float: " + options.float + ";'></div>")); //"
			$col = $inBox.children(":last");
			$col.append($cache.clone());
			maxHeight = $col.height();
			$inBox.empty();
			
			var targetHeight = maxHeight / numCols;
			var firstTime = true;
			var maxLoops = 3;
			var scrollHorizontally = false;
			if(options.overflow){
				maxLoops = 1;
				targetHeight = options.overflow.height;
			}else if(options.height && options.width){
				maxLoops = 1;
				targetHeight = options.height;
				scrollHorizontally = true;
			}
			
			for(var loopCount=0;loopCount<maxLoops;loopCount++){
				$inBox.empty();
				var $destroyable;
				try{
					$destroyable = $cache.clone(true);
				}catch(e){
					// jquery in ie6 can't clone with true
					$destroyable = $cache.clone();
				}
				$destroyable.css("visibility", "hidden");
				// create the columns
				for (var i = 0; i < numCols; i++) {
					/* create column */
					var className = (i == 0) ? "first column" : "column";
					var className = (i == numCols - 1) ? ("last " + className) : className;
					$inBox.append($("<div class='" + className + "' style='width:" + (Math.round(100 / numCols) - 2)+ "%; float: " + options.float + ";'></div>")); //"
				}
				
				// fill all but the last column (unless overflowing)
				var i = 0;
				while(i < numCols - (options.overflow ? 0 : 1) || scrollHorizontally && $destroyable.children().length){
					if($inBox.children().length <= i){
						// we ran out of columns, make another
						$inBox.append($("<div class='" + className + "' style='width:" + (Math.round(100 / numCols) - 2)+ "%; float: " + options.float + ";'></div>")); //"
					}
					var $col = $inBox.children().eq(i);
					columnize($col, $destroyable, $col, targetHeight);
					// make sure that the last item in the column isn't a "dontend"
					if(!$destroyable.children().find(":first-child").hasClass("dontend")){
						split($col, $destroyable, $col, targetHeight);
					}else{
//						alert("not splitting a dontend");
					}
					
					while(checkDontEndColumn($col.children(":last").length && $col.children(":last").get(0))){
						var $lastKid = $col.children(":last");
						$lastKid.remove();
						$destroyable.prepend($lastKid);
					}
					i++;
				}
				if(options.overflow && !scrollHorizontally){
					var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
					var IE7 = (document.all) && (navigator.appVersion.indexOf("MSIE 7.") != -1);
					if(IE6 || IE7){
						var html = "";
						var div = document.createElement('DIV');
						while($destroyable[0].childNodes.length > 0){
							var kid = $destroyable[0].childNodes[0];
							for(var i=0;i<kid.attributes.length;i++){
								if(kid.attributes[i].nodeName.indexOf("jQuery") == 0){
									kid.removeAttribute(kid.attributes[i].nodeName);
								}
							}
							div.innerHTML = "";
							div.appendChild($destroyable[0].childNodes[0]);
							html += div.innerHTML;
						}
						var overflow = $(options.overflow.id)[0];
						overflow.innerHTML = html;
					}else{
						$(options.overflow.id).empty().append($destroyable.children().clone(true));
					}
				}else if(!scrollHorizontally){
					// the last column in the series
					$col = $inBox.children().eq($inBox.children().length-1);
					while($destroyable.children().length) $col.append($destroyable.children(":first"));
					var afterH = $col.height();
					var diff = afterH - targetHeight;
					var totalH = 0;
					var min = 10000000;
					var max = 0;
					var lastIsMax = false;
					$inBox.children().each(function($inBox){ return function($item){
						var h = $inBox.children().eq($item).height();
						lastIsMax = false;
						totalH += h;
						if(h > max) {
							max = h;
							lastIsMax = true;
						}
						if(h < min) min = h;
					}}($inBox));

					var avgH = totalH / numCols;
					if(options.lastNeverTallest && lastIsMax){
						// the last column is the tallest
						// so allow columns to be taller
						// and retry
						targetHeight = targetHeight + 30;
						if(loopCount == maxLoops-1) maxLoops++;
					}else if(max - min > 30){
						// too much variation, try again
						targetHeight = avgH + 30;
					}else if(Math.abs(avgH-targetHeight) > 20){
						// too much variation, try again
						targetHeight = avgH;
					}else {
						// solid, we're done
						loopCount = maxLoops;
					}
				}else{
					// it's scrolling horizontally, fix the width/classes of the columns
					$inBox.children().each(function(i){
						$col = $inBox.children().eq(i);
						$col.width(options.width + "px");
						if(i==0){
							$col.addClass("first");
						}else if(i==$inBox.children().length-1){
							$col.addClass("last");
						}else{
							$col.removeClass("first");
							$col.removeClass("last");
						}
					});
					$inBox.width($inBox.children().length * options.width + "px");
				}
				$inBox.append($("<br style='clear:both;'>"));
			}
			$inBox.find('.column').find(':first.removeiffirst').remove();
			$inBox.find('.column').find(':last.removeiflast').remove();
			$inBox.data("columnizing", false);

			if(options.overflow){
				options.overflow.doneFunc();
			}
			options.doneFunc();
		}
    });
 };
})(jQuery);
;
(function($){ 
 	$.fn.fcSlideshow = function(options){
		var options = $.extend({
					images: 		null,
					preloadImages: 	true,
					wrapper: 		$('#wrapper'),
      				interval: 		6000,
      				duration: 		1000
    			}, options);
		
		if(!options.wrapper.length || !options.images) return;
		
		var closedWidth = 100,
			openWidthMin = 875,
			openWidthMax = 2500,
			openShivWidth = 5;
		
		var windowWidth, windowHeight,
			totalWidthMin, totalWidthMax, activeSlideWidth,
			firstSlide, lastSlide,
			sliderCreated = false,
			sliderInterval = null,
			sliderPaused = false,
			sliderControlLocked = false,
			updateNavPosition = function(){};
	
		
		return $(this).each(function(){
			var slider = $(this);
		
		
			var cteateSlider = function(){
					
					var slideHtml = '';
					
					//slides
					for(i = 0; i < options.images.length; i++){
						slideHtml += '<div class="slide"><img src="' + options.images[i] + '" /><div class="shiv"></div></div>';
					}
					
					//dim
					if(slider.hasClass('paused') && !slider.hasClass('no-dim')){
						slideHtml += '<div class="dim"></div>';
					}
					
					options.wrapper.addClass('loading');
					slider.css({opacity: 0}).append(slideHtml);
					
					$('div.shiv:gt(1)', slider).css({ width: openShivWidth + 'px'});
					
					options.wrapper.removeClass('loading');
				}
			
			
			var createNavigation = function(){
					options.wrapper.append('<ul id="nav"><li><a href="#" title="Previous" class="prev" id="prevSlide" onclick="return false"></a></li><li><a href="#" title="Play/Pause" class="pause" id="playPause" onclick="return false"></a></li><li><a href="#" title="Next" class="next" id="nextSlide" onclick="return false"></a></li></ul>');
					
					//update position
					updateNavPosition = function(){
						var nav = $('#nav');
						nav.css({left: (closedWidth + activeSlideWidth - nav.width()) + 'px'});
					}
					
					updateNavPosition();
					$('#nav').show();
					
					//
					var pauseSlideshow = function(){
						//clearInterval(sliderInterval);
						sliderPaused = true;
						$('#playPause').removeClass('pause').addClass('play');
					}
					
					//play|pause btn
					$('#playPause').bind('click', function(){
						if($(this).hasClass('pause')){
							pauseSlideshow();
						} else { //if hasClass('play')
							if(sliderControlLocked) return;
							
							sliderPaused = false;
							nextSlide();
							//initSlider();
							
							$(this).removeClass('play').addClass('pause');
						}
						return false;
					});
					
					//next btn
					$('#nextSlide').bind('click', function(){
						if(sliderControlLocked) return;
						
						sliderPaused = false;
						
						nextSlide();
						pauseSlideshow();
					});
					
					//prev btn
					$('#prevSlide').bind('click', function(){
						if(sliderControlLocked) return;
						
						sliderPaused = false;
						prevSlide();
						
						pauseSlideshow();
					});
					
					//keyboard control
					$(document).bind('keydown', function(e){
						var code = (e.keyCode ? e.keyCode : e.which);
						if(code == 37){
							$('#prevSlide').trigger('click');
							return false;
						} else if(code == 39){
							$('#nextSlide').trigger('click');
							return false;
						} else if(code == 32){//space 
							$('#playPause').trigger('click');
							return false;
						}
					});
				}
			
			
			var nextSlide = function(){
					if(sliderPaused) return;
					
					sliderControlLocked = true;
					
					firstSlide = $('div.slide:eq(0)', slider);
					lastSlide = firstSlide.clone();
					
					lastSlide.css({ width: 0});
					slider.append(lastSlide);
					
					firstSlide.addClass('remove').animate({ width: 0}, options.duration, function(){
						$(this).remove();
						sliderControlLocked = false;
					});
					
					$('div.slide:eq(1)', slider).animate({ width: closedWidth + 'px'}, options.duration);
					$('div.slide:eq(2)', slider).animate({ width: activeSlideWidth + 'px'}, options.duration).find('div.shiv').css({width: 0});
					
					if(options.images.length > 2)
						lastSlide.animate({ width: closedWidth + 'px'}, options.duration).find('div.shiv').css({width: openShivWidth + 'px'});
				}
				
			var prevSlide = function(){
					if(sliderPaused) return;
					
					sliderControlLocked = true;
					
					var lastSlide = $('div.slide:last', slider);
					var firstSlide = lastSlide.clone();
					
					firstSlide.css({ width: 0});
					slider.prepend(firstSlide);
					
					firstSlide.animate({ width: closedWidth + 'px'}, options.duration).find('div.shiv').css({width: 0});
					
					$('div.slide:eq(1)', slider).animate({ width: activeSlideWidth + 'px'}, options.duration);
					
					if(options.images.length > 2)
						$('div.slide:eq(2)', slider).animate({ width: closedWidth + 'px'}, options.duration).find('div.shiv').width({width: openShivWidth + 'px'});
					
					lastSlide.addClass('remove').animate({ width: 0}, options.duration, function(){
						$(this).remove();
						sliderControlLocked = false;
					});
				}
				
			
			var updateSlideSize = function(){
					$('div.slide', slider).stop();
					$('div.remove', slider).remove();
					
					windowWidth = options.wrapper.width();
					windowHeight = options.wrapper.height();
					
					//calculate active slide width
					totalWidthMin = openWidthMin;
					totalWidthMax = windowWidth - closedWidth * (options.images.length - 1);
					activeSlideWidth = totalWidthMax;
					
					if(totalWidthMax > openWidthMax){
						activeSlideWidth = openWidthMax; 
					} else if(totalWidthMax <= openWidthMin){
						activeSlideWidth = openWidthMin;
					}
					
					//resize slider
					slider.css({height: windowHeight + 'px'});
					
					//resize slides
					$('div.slide', slider).css({ height: windowHeight + 'px'});
					
					var currSlide = $('div.slide:eq(1)', slider);
					if(!currSlide.length){/*if we have 1 slide*/
						currSlide = $('div.slide:first', slider);
					}
					if(currSlide.width() != activeSlideWidth){
						$('div.slide:eq(0), div.slide:gt(1)', slider).css({ width: closedWidth + 'px' });
						currSlide.css({ width: activeSlideWidth + 'px'});
					}
					
					//resize slide images
					$('div.slide img', slider).each(function(){
						var img = $(this);
						img.css({height: windowHeight + 'px', width: 'auto'});
						if(img.width() < activeSlideWidth){
							img.css({height: 'auto', width: activeSlideWidth + 'px'});
						}
					});
				}
		
				
			var initSlider = function(){
					if(sliderCreated) return;
					sliderCreated = true;
					
					cteateSlider();
					updateSlideSize();
					
					if(slider.hasClass('controls')){
						createNavigation();
					}
					
					slider.animate({opacity: 1}, options.duration);
					
					if(!slider.hasClass('paused')){
						sliderInterval = setInterval(nextSlide, options.interval);
					}
					
					$(window).bind('blur', function(){
						sliderPaused = true;
					}).bind('focus', function(){
						sliderPaused = false;
					}).bind('resize', function(){
						updateSlideSize();
						updateNavPosition();
					});
				}
				
				
			//start show!
			if(options.preloadImages && typeof($.imgpreload) == 'function'){
				options.wrapper.addClass('loading');
				
				var planB = setTimeout(function(){
					initSlider();
				}, 1000 * options.images.length * 1.5);
				
				//preload images
				$.imgpreload(options.images, function(){
					clearTimeout(planB);
					setTimeout(function(){
						initSlider();
					}, 2000);
				});
			} else {
				initSlider();
			}
				
    	});
		
	}; 
})(jQuery);
;
/*fix for jQuery '-10000' bug*/
jQuery.fx.prototype.cur = function(){ // we are overwriting this function to remove limiting of the size of the
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}

jQuery(document).ready(function($){
	
	var wrapper = $('#wrapper'),
		windowWidth = wrapper.width(),
		windowHeight = wrapper.height(); 
	
	var isIE8 = $.browser.msie && parseInt($.browser.version) == 8;
	
	//slideshow
	if(Drupal.settings.fc_slideshow != undefined){
		if(Drupal.settings.fc_slideshow['images'].length){
			if(Drupal.settings.fc_slideshow['controls']){
				$('#slider').addClass('controls');
			}
				
			$('#slider').fcSlideshow({
				images: 		Drupal.settings.fc_slideshow['images'],
				preloadImages: 	Drupal.settings.fc_slideshow['preload'] ? true : false,
				interval: 		Drupal.settings.fc_slideshow['interval'],
				duration: 		Drupal.settings.fc_slideshow['duration']
			});
		}
	}	


	//centering content container	
	var updateElementsPosition = function(){
			var contentDiv = $('#content'),
				contentHeight = $('#content div.centered').height(),
				contentWidth = $('#content div.centered').width(),
				contentPosLeft = (windowWidth - contentWidth) / 2,
				contentPosTop = (windowHeight - contentHeight) / 2;
			
			//centering content div (vert.)
			contentDiv.css({top: (windowHeight/2 - contentHeight/2 - 15) + 'px'});
			
			//centering page-title and filter links
			$('#content h3.page-title').css({paddingLeft: contentPosLeft + 10 + 'px'});
			
			//for small screens
			if(!wrapper.hasClass('autosize')){
				if(windowHeight < 850){
					$('#header').css({top: (contentPosTop/2 - 26) + 'px'});
					$('#footer').css({bottom: (contentPosTop/2 - 27) + 'px'});
					
					if(isIE8 && !wrapper.hasClass('autosize')){
						$('#footer').css({top: (windowHeight - contentPosTop/2) + 'px'}); 
					}
				} else {
					$('#header').css({top: '70px'});
					$('#footer').css({bottom: '40px'});
					
					if(isIE8 && !wrapper.hasClass('autosize')){
						$('#footer').css({top: (windowHeight - 69) + 'px'}); 
					}
				}
				
				if(windowWidth < 1020){
					$('a.nav-btn').addClass('inset');
				} else {
					$('a.nav-btn').removeClass('inset'); 
				}
			}
			
		}	
		
	
	//bg image
	var updateBgSize = function(){}
	if(Drupal.settings.fc_bg_img != undefined){
		wrapper.append('<div id="bg"><img src="' + Drupal.settings.fc_bg_img + '" /></div>');
		
		updateBgSize = function(){
			var bg = $('#bg');
			var bgImg = $('#bg img');
			
			if(!bgImg.length){
				return;
			}
			
			bg.css({height: windowHeight + 'px'});
			bgImg.css({width: windowWidth + 'px', height: 'auto'});
			
			if(windowHeight > bgImg.height() && bgImg.height()){
				bgImg.css({width: 'auto', height: windowHeight + 'px'});
			}
		}
	}
		
			
	//onresize
	$(window).bind('resize', function(){
		windowWidth = wrapper.width();
		windowHeight = wrapper.height();
			
		updateBgSize();
		updateElementsPosition();
	}).trigger('resize');
		
	// thumbs sliders
	var addPrevNextButtons = function(){
			if($('#btn-next, #btn-prev').length) return;
			
			var html = '<a href="#" title="" id="btn-prev" class="nav-btn disabled" onclick="return false"></a><a href="#" title="" id="btn-next" class="nav-btn" onclick="return false"></a>';
			$('#panels').append(html);
			
			if(windowWidth < 1020){
				$('a.nav-btn').addClass('inset');
			}
		}
		
	var initKeyboardControl = function(){
			$(document).unbind('keydown').bind('keydown', function(e){
				var code = (e.keyCode ? e.keyCode : e.which);
				
				if(code == 37){
					$('#btn-prev').trigger('click');
				} else if(code == 39){
					$('#btn-next').trigger('click');
				}
			});
		}
		
	var initThumbsSlider = function(panel, itemsCount, itemWidth, limitFix){
		var currItem = 1,
			maxScrollItems = 1,
			panelAnimated = false;
			
		panel.css({width: (itemsCount*itemWidth + 100) + 'px'});
		
		//add controls
		addPrevNextButtons();
		initKeyboardControl();
				
		//next btn
		$('#btn-next').unbind('click').bind('click', function(){
			if($(this).hasClass('disabled') || panelAnimated) return false;
			
			panelAnimated = true;
			
			panel.animate({left: '-=' + (itemWidth * maxScrollItems) + 'px'}, 300,function(){
				panelAnimated = false;
			});
			currItem += maxScrollItems;
			
			$('#btn-prev').removeClass('disabled');
			if(currItem == itemsCount-limitFix){
				$('#btn-next').addClass('disabled');
			}
		});
		if(currItem >= itemsCount-limitFix){
			$('#btn-next').addClass('disabled');
		}
		
		//prev btn
		$('#btn-prev').unbind('click').bind('click', function(){
			if($(this).hasClass('disabled') || panelAnimated) return false;
			
			panelAnimated = true;
			panel.animate({left: '+=' + (itemWidth * maxScrollItems) + 'px'}, 300, function(){
				panelAnimated = false;
			});
			currItem -= maxScrollItems;
			
			$('#btn-next').removeClass('disabled');
			if(currItem == 1){
				$('#btn-prev').addClass('disabled');
			}
			
		}).addClass('disabled');
	}
	
	// leadership slider
	if($('#panels').hasClass('leadership')){
		var panel = $('div.panel');
		var itemsCount = $('a.associate', panel).length;
		
		if(itemsCount > 4){
			var itemWidth = $('a.associate:first', panel).width() + 5;
			initThumbsSlider(panel, itemsCount, itemWidth, 2 /*3*/);
		}
	}
	
	//
	// projects slider
	if($('#panels').hasClass('projects')){
		var panel = $('div.panel');
		var itemsCount = $('div.project', panel).length;
		
		if(itemsCount > 3){
			var itemWidth = $('div.project:first', panel).width() + 8;
			initThumbsSlider(panel, itemsCount, itemWidth, 2);
		}
		
		//
		var switchProjectsCategory = function(cat){
				var catPanel = $('div.panel-' + cat);
				if(catPanel.is(':visible')) return;
				
				$('div.panel:visible').hide();
				catPanel.fadeIn(500);
				
				$('ul.filter li').removeClass('active').find('a[rel=' + cat + ']').parents('li').addClass('active');
				
				var catLength = catPanel.find('div.project').length;
				if(catLength <= 3){
					$('#btn-next, #btn-prev').hide();
				} else {
					$('#btn-next, #btn-prev').show();
					$('#btn-next').removeClass('disabled');
					catPanel.css({left: 0});
					initThumbsSlider(catPanel, catLength, itemWidth, 2);
				}
			}
		
		//categories
		var projects = $('div.panel a.project-thumb');
		$('ul.filter li a[rel]').each(function(){
			var rel = $(this).attr('rel');
			if(rel == 'all'){
				$('div.panel:first').addClass('panel-all');
			} else {
				$('div.projects #container').append('<div class="panel panel-' + rel + '" style="display:none"></div>');
				
				var catProjects = projects.filter('.cat-' + rel).clone();
				if(catProjects.length){
					for(i = 0; i < catProjects.length; i += 2){
						$('div.panel-' + rel).append('<div class="project"></div>');
						$('div.panel-' + rel + ' div.project:last').append(catProjects[i]);
						if(i+1 <= catProjects.length){
							$('div.panel-' + rel + ' div.project:last').append(catProjects[i+1]);
						}
					}
				}
				
			}
			
			$(this).bind('click', function(){
				switchProjectsCategory($(this).attr('rel'));
			});
			
		});
		
		var catHash = getHash();
		if(catHash != '' && $('div.panel-' + catHash).length){
			switchProjectsCategory(catHash);
		}
		
		//project info
		$('#container .project a').bind('mouseover', function(){
			$('div.info', this).stop().animate({bottom: 0}, 300);
		}).bind('mouseleave', function(){
			$('div.info', this).stop().animate({bottom: '-250px'}, 600);
		}).bind('click', function(){
			$('div.info', this).stop().css({bottom: '-250px'});
			return true;
		});
	}
	
	//clients columns
	if($.browser.msie){
		$('div.clients .inner').columnize({
			columns: 2,
			width : 280,
			height : 490,
			lastNeverTallest: true
		});
	}
	
	
	//
	// press articles slider
	if($('#panels').hasClass('articles')){
		var panel = $('div.panel');
		var itemsCount = $('div.press-col', panel).length;
		
		if(itemsCount > 2){
			var itemWidth = $('div.press-col:first', panel).width() + 5;
			initThumbsSlider(panel, itemsCount, itemWidth, 1);
		}
		
		//
		var switchArticlesCategory = function(cat){
				var catPanel = $('div.panel-' + cat);
				if(catPanel.is(':visible')) return;
				
				$('div.panel:visible').hide();
				catPanel.fadeIn(500);
				
				$('ul.filter li').removeClass('active').find('a[rel=' + cat + ']').parents('li').addClass('active');
				
				var catLength = catPanel.find('div.press-col').length;
				if(catLength <= 2){
					$('#btn-next, #btn-prev').hide();
				} else {
					$('#btn-next, #btn-prev').show();
					$('#btn-next').removeClass('disabled');
					catPanel.css({left: 0});
					initThumbsSlider(catPanel, catLength, itemWidth, 1);
				}
			}
		
		//categories
		var articles = $('div.panel div.press');
		$('ul.filter li a[rel]').each(function(){
			var rel = $(this).attr('rel');
			if(rel == 'all'){
				$('div.panel:first').addClass('panel-all');
			} else {
				$('div.articles #container').append('<div class="panel panel-' + rel + '" style="display:none"></div>');
				
				var catArticles = articles.filter('.cat-' + rel).clone();
				if(catArticles.length){
					for(i = 0; i < catArticles.length; i += 2){
						$('div.panel-' + rel).append('<div class="press-col"></div>');
						$('div.panel-' + rel + ' div.press-col:last').append(catArticles[i]);
						if(i+1 <= catArticles.length){
							$('div.panel-' + rel + ' div.press-col:last').append(catArticles[i+1]);
						}
					}
				}
				
			}
			
			$(this).bind('click', function(){
				switchArticlesCategory($(this).attr('rel'));
			});
			
		});
		
		var catHash = getHash();
		if(catHash != '' && $('div.panel-' + catHash).length){
			switchArticlesCategory(catHash);
		}
		
	}
	
	// article scroller
	if($('#panels').hasClass('article')){
		var panel = $('div.panel');
		
		if($.browser.msie){
			// add custom scrollbar
			$('div.columnize', panel).addClass('scrollable');
			
		} else {
			var contentHeight = $('div.columnize', panel).css({height:'auto'}).height();
			itemsCount = Math.ceil(contentHeight / 500);
			var itemWidth = 476;
			
			$('div.article').addClass('article-full');
			$('div.columnize', panel).addClass('columnize-it');
			
			if(itemsCount > 2){
				initThumbsSlider(panel, itemsCount, itemWidth, 1);
			}
		}
	}
	
	
	//WORK: project info
	$('#info-trigger').toggle(
		function(){
			$('div.project-info').fadeOut(500);
			$(this).animate({left: 0}, 400, function(){
				$(this).removeClass('opened').animate({top: '497px'}, 300);
			});
		},
		function(){
			$(this).animate({top: '10px'}, 300, function(){
				$('div.project-info').fadeIn(500);
				$(this).addClass('opened').animate({left: '340px'}, 400);
			});
		}
	);

	
	//show logo
	setTimeout(function(){
		$('div.logo a').animate({ left: '5px'}, 1000);
	}, 100);
		

	//custom scrollbars
	$('#content div.scrollable').scrollbar({arrows: false});
	$('#content div.scrollbar-handle-container').touchwipe({
		 wipeUp: function() { 
			$('div.scrollable').scrollbar('scrollto', 'bottom');
		},
		 wipeDown: function() { 
			$('div.scrollable').scrollbar('scrollto', 'top');
		},
		 min_move_y: 20,
		 preventDefaultEvents: true
	});
	
	
	//set active menu item
	if(Drupal.settings.fc_active_menu_item != undefined){
		$('#header ul:first li a:contains("' + Drupal.settings.fc_active_menu_item + '")').addClass('active');
	}
    

	//back btn
	$('#back:not(.no-history)').bind('click', function(){
		history.go(-1);
		return false;
	});
	
	//show footer
	$('#footer').show();
	
    
    //admin fix (hide header and footer)
    var location = window.location.href;
    if(location.indexOf('/admin') != -1 || location.indexOf('#overlay') != -1){
        $('#header, #footer').hide();
    }
	
	
	//antispam mail
	$('div.address a:contains("{at}")').each(function(){
		$(this).attr('href', $(this).attr('href').replace('{at}', '@')).text($(this).text().replace('{at}', '@'));
	});
	
});


//remove no-js class
document.getElementsByTagName('html')[0].className = '';

function getHash() {
  	var hash = window.location.hash;
  	return hash.substring(1); // remove #
};

