/* Easing */

// 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;
	}
});


/* Slider */
/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 *	Customized by Stuart Wagner for use on thewebsqueeze.com (The Web Squeeze, LLC.)
 *
 */
(function($){

	$.fn.easySlider = function(options){
	  
		var defaults = {
			panelClass:		'panel',			
			vertical:		false,
			easeIn:			'easeInExpo',
			easeOut:		'easeOutElastic',
			easeArrow:		'easeInOutExpo',
			speedIn:		600,
			speedOut:		1000,
			speedArrow:		1000,
			auto:			true,
			pause:			8000,
			continuous:		true, 
			controls: 		true,
			controlsId: 	'controller .container',
			controlsElem:	'thumb a'
		}; 
		
		var options = $.extend(defaults, options);
				
		this.each(function(){  
			var obj = $(this);
			var s = $('.' + options.panelClass, obj).length;
			var w = $('.' + options.panelClass, obj).width();
			var h = $('.' + options.panelClass, obj).height();
			var clickable = true;
			var ts = s-1;
			var t = 0;
			$(obj).css('width',s*w);
			
			if(options.continuous){
				$(obj).prepend($('.' + options.panelClass + ":last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$(obj).append($('.' + options.panelClass + ":nth-child(2)", obj).clone());
				$(obj).css('width',(s+1)*w);
			};
			
			if(!options.vertical) $('.' + options.panelClass, obj).css('float','left');
			
			if(options.controls){
				$('#' + options.controlsId).find('.' + options.controlsElem).click(function(){
					i = $(this).attr('rel')-1;
					cycle(i,true);
					return false;
				});
			}
			
			function setCurrent(i){
				if (i == 0){
					i = 1;
				}
				else {
					i = parseInt(i)+1;
				}
				
				speed = options.speedArrow;
				ease = options.easeArrow;
				
				if (i == 1){
					$('#' + options.controlsId).animate({"background-position": "67px 0"},{queue:false,duration:speed,easing:ease});
				}
				else if (i == 2){
					$('#' + options.controlsId).animate({"background-position": "228px 0"},{queue:false,duration:speed,easing:ease});
				}
				else if (i == 3){
					$('#' + options.controlsId).animate({"background-position": "390px 0"},{queue:false,duration:speed,easing:ease});
				}
				else if (i == 4){
					$('#' + options.controlsId).animate({"background-position": "552px 0"},{queue:false,duration:speed,easing:ease});
				}
				else if (i == 5){
					$('#' + options.controlsId).animate({"background-position": "714px 0"},{queue:false,duration:speed,easing:ease});
				}
				else if (i == 6){
					$('#' + options.controlsId).animate({"background-position": "876px 0"},{queue:false,duration:speed,easing:ease});
				}
				else {
					$('#' + options.controlsId).animate({"background-position": "67px 0"},{queue:false,duration:speed,easing:ease});
				}
			};
			
			function adjust(){
				if (t>ts){t=0};		
				if (t<0){t=ts};	
				if (!options.vertical){
					$(obj).css("margin-left",(t*w*-1));
				} else {
					$(obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
			};
			
			function cycle(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};
					// var diff = Math.abs(ot-t);
					if(!options.vertical){
						p = (t*w*-1);
						p1 = (p/6)*5;
						//console.log(p1);
						/*$(obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:options.speedOut, easing:options.easeOut, complete:adjust }
						);*/
						
						$(obj).animate(
							{marginLeft:p1},
							{queue:true, duration:options.speedIn, easing:options.easeIn, complete:adjust}
						).animate(
							{marginLeft:p},
							{queue:true, duration:options.speedOut, easing:options.easeOut, complete:adjust}
						);
						
						if(options.controls){setCurrent(t)};
					} else {
						p = (t*h*-1);
						p1 = (p/6)*5;
						/*$(obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:options.speedOut, easing:options.easeOut, complete:adjust }
						);*/
						
						$(obj).animate(
							{marginLeft:p1},
							{queue:true, duration:options.speedIn, easing:options.easeIn, complete:adjust}
						).animate(
							{marginLeft:p},
							{queue:true, duration:options.speedOut, easing:options.easeOut, complete:adjust}
						);
						
						if(options.controls){setCurrent(t)};
					};
					
					if(clicked){clearTimeout(timeout);}
					if(options.auto && dir=="next"){
						autocycle();
					};
			
				};
				
			};
			
			var timeout;
			function autocycle(){
				timeout = setTimeout(function(){
					cycle("next",false);
				}, options.pause);
			};
			
			if(options.auto){
				autocycle();
				$(obj).hover(function(){
					clearTimeout(timeout);
				}, function(){
					autocycle();
				});
			};
			
			if(options.controls){setCurrent(0)};		
			
		});
	  
	};

})(jQuery);

/* Navigation Slide Effect */
(function($){

	$.fn.navSlide = function(options){
	  
		var defaults = {
			paddingOut:		15,
			paddingIn:		8,
			duration:		150,
			multiplier:		.8,
			list:			false,
			links:			true
		}; 
		
		var options = $.extend(defaults, options);
		
		var obj = $(this);		
		var timer = 0;
		
		// slide animation for list elems 
		if (options.list){
			$(" ul li", obj).each(function(i){
				// margin left = - ([width of element] + [total vertical padding of element])
				$(this).css("margin-left","-180px");
				
				timer = (timer*options.multiplier + options.duration);
				
				$(this).animate({marginLeft:"0"}, timer);
				$(this).animate({marginLeft:"15px"}, timer);
				$(this).animate({marginLeft:"0"}, timer);
			});
		}

		// hover-slide effect for links elems 	
		if (options.links){
			$(" ul li a", obj).each(function(i){
				$(this).hover(
					function(){
						$(this).stop(true,true).animate({paddingLeft:options.paddingOut}, options.duration);
					},
					function(){
						$(this).animate({paddingLeft:options.paddingIn}, options.duration);
					}
				);
			});
		}
	}
})(jQuery);

/* jQuery cookies */
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
(function($){
	jQuery.cookie = function(name, value, options){
	    if (typeof value != 'undefined'){ // name and value give, make cookie
	        options = options || {};
	        if (value === null){
	            value = '';
	            options.expires = -1;
	        }
	        var expires = '';
	        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)){
	            var date;
	            if (typeof options.expires == 'number'){
	                date = new Date();
	                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
	            } else {
	                date = options.expires;
	            }
	            expires = '; expires=' + date.toUTCString();
	        }
	        var path = options.path ? '; path=' + (options.path) : '';
	        var domain = options.domain ? '; domain=' + (options.domain) : '';
	        var secure = options.secure ? '; secure' : '';
	        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	    } else { // only name given, get cookie
	        var cookieValue = null;
	        if (document.cookie && document.cookie != '') {
	            var cookies = document.cookie.split(';');
	            for (var i = 0; i < cookies.length; i++) {
	                var cookie = jQuery.trim(cookies[i]);
	                if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;
	    }
	};
})(jQuery);
