﻿ /*
 * jQuery CenterBgImage
 * @author highmore
 *
 * Version: 1.0
 */
;(function($) {

	// centers the background image
	$.CenterBgImage = function ($img) {
		var dim	= getImageDim($img);
		//set the returned values and show the image
		$img.css({
			width	: dim.width		+ "px",
			height	: dim.height	+ "px",
			left	: dim.left		+ "px",
			top		: dim.top		+ "px"
		});
	}

	//get dimentions of the image,
	//in order to make it full size and centered
	function getImageDim($i) {
		var pad	= 0;
		var $img = new Image();
		$img.src = $i.attr("src");

		var w_w	= $(window).width()-pad,
			w_h	= $(window).height()-pad,
			r_w	= w_h/w_w,

			i_w	= $img.width,
			i_h	= $img.height,
			r_i	= i_h/i_w;

		var new_w, new_h, new_left, new_top;

		if (r_w>r_i) {
			new_h	= w_h>i_h ? i_h : w_h;
			new_w	= w_h>i_h ? i_w : w_h/r_i;
		} else {
			new_h	= w_w>i_w ? i_h : w_w*r_i;
			new_w	= w_w>i_w ? i_w : w_w;
		}

		return {
			width	: new_w,
			height	: new_h,
			left	: (w_w-new_w)/2+pad/2,
			top		: (w_h-new_h)/2+pad/2
		}
	}

})(jQuery);

/*
 * jQuery imagesLoaded plugin v1.0.3
 * http://github.com/desandro/imagesloaded
 *
 * MIT License. by Paul Irish et al.
 */

(function($, undefined) {

	// $('#my-container').imagesLoaded(myFunction)
	// or
	// $('img').imagesLoaded(myFunction)

	// execute a callback when all images have loaded.
	// needed because .load() doesn't work on cached images

	// callback function gets image collection as argument
	//  `this` is the container

	$.fn.imagesLoaded = function(callback) {
		var $this	= this,
			$images	= $this.find("img").add($this.filter("img")),
			len		= $images.length,
			blank	= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";

		function triggerCallback() {
			callback.call($this, $images);
		}

		function imgLoaded() {
			if (--len <= 0 && this.src !== blank) {
				setTimeout( triggerCallback );
				$images.unbind("load error", imgLoaded);
			}
		}

		if (!len) {
			triggerCallback();
		}

		$images.bind("load error", imgLoaded).each(function() {
			// cached images don't fire load sometimes, so we reset src.
			if (this.complete || this.complete === undefined){
				var src = this.src;
				// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
				// data uri bypasses webkit log warning (thx doug jones)
				this.src = blank;
				this.src = src;
			}
		});

		return $this;
	};

})(jQuery);

/*
 *
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 *
 */
(function(e){function g(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1]),parseInt(a[2]),parseInt(a[3])];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],16),parseInt(a[2], 16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];return i[e.trim(c).toLowerCase()]}e.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){e.fx.step[a]=function(b){if(b.state==0){var d;d=b.elem;var h=a,f;do{f=e.curCSS(d,h);if(f!=""&&f!="transparent"||e.nodeName(d,"body"))break;h="backgroundColor"}while(d=d.parentNode); d=g(f);b.start=d;b.end=g(b.end)}b.elem.style[a]="rgb("+[Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0]),255),0),Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1]),255),0),Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2]),255),0)].join(",")+")"}});var i={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0, 100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128, 128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(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.
 *
*/

// 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;
	}
});

/**
 * @name		Shuffle Letters
 * @author		Martin Angelov
 * @version 	1.0
 * @url			http://tutorialzine.com/2011/09/shuffle-letters-effect-jquery/
 * @license		MIT License
 */

(function($){
	
	$.fn.shuffleLetters = function(prop){

		var options = $.extend({
			"step"		: 8,			// How many times should the letters be changed
			"fps"		: 25,			// Frames Per Second
			"text"		: "", 			// Use this text instead of the contents
			"callback"	: function(){}	// Run once the animation is complete
		}, prop)

		return this.each(function() {
			var el	= $(this),
				str	= "";

			// Preventing parallel animations using a flag;
			if (el.data("animated")) {
				return true;
			}

			el.data("animated", true);
			
			if (options.text) {
				str = options.text.split('');
			}
			else {
				str = el.text().split('');
			}

			// The types array holds the type for each character;
			// Letters holds the positions of non-space characters;
			var types	= [],
				letters	= [];

			// Looping through all the chars of the string
			for (var i=0; i<str.length; i++) {
				var ch = str[i];

				if (ch==" ") {
					types[i] = "space";
					continue;
				}
				else if (/[a-z]/.test(ch)) {
					types[i] = "lowerLetter";
				}
				else if (/[A-Z]/.test(ch)) {
					types[i] = "upperLetter";
				}
				else {
					types[i] = "symbol";
				}
				letters.push(i);
			}
			el.html("");			

			// Self executing named function expression:
			(function shuffle(start) {
				// This code is run options.fps times per second
				// and updates the contents of the page element

				var i,
					len = letters.length,
					strCopy = str.slice(0);	// Fresh copy of the string

				if (start>len) {
					// The animation is complete. Updating the
					// flag and triggering the callback;

					el.data("animated", false);
					options.callback(el);
					return;
				}
				
				// All the work gets done here
				for (i=Math.max(start, 0); i<len; i++) {
					// The start argument and options.step limit
					// the characters we will be working on at once

					if (i<start+options.step) {
						// Generate a random character at thsi position
						strCopy[letters[i]] = randomChar(types[letters[i]]);
					}
					else {
						strCopy[letters[i]] = "";
					}
				}

				el.text(strCopy.join(""));
				setTimeout(function() {shuffle(start+1);}, 1000/options.fps);

			})(-options.step);

		});
	};
	
	function randomChar(type){
		var pool = "";
		
		if (type == "lowerLetter"){
			pool = "abcdefghijklmnopqrstuvwxyz0123456789";
		}
		else if (type == "upperLetter"){
			pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		}
		else if (type == "symbol"){
			pool = ",.?/\\(^)![]{}*&^%$#'\"";
		}
		
		var arr = pool.split('');
		return arr[Math.floor(Math.random()*arr.length)];
	}
	
})(jQuery);

/*
 * jQuery Mouse Wheel
 * 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.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.4
 * Requires: 1.2.2+
 */

;(function($) {

	var types = ["DOMMouseScroll", "mousewheel"];

	$.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;
			}
		}
	};

	$.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 orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
		event = $.event.fix(orgEvent);
		event.type = "mousewheel";

		// Old school scrollwheel delta
		if (event.wheelDelta) {delta = event.wheelDelta/120;}
		if (event.detail) {delta = -event.detail/3;}

		// New school multidimensional scroll (touchpads) deltas
		deltaY = delta;

		// Gecko
		if (orgEvent.axis!==undefined && orgEvent.axis===orgEvent.HORIZONTAL_AXIS) {
			deltaY = 0;
			deltaX = -1*delta;
		}

		// Webkit
		if (orgEvent.wheelDeltaY!==undefined) {deltaY = orgEvent.wheelDeltaY/120;}
		if (orgEvent.wheelDeltaX!==undefined) {deltaX = -1*orgEvent.wheelDeltaX/120;}

		// Add event and delta to the front of the arguments
		args.unshift(event, delta, deltaX, deltaY);

		return $.event.handle.apply(this, args);
	}

})(jQuery);


 /*
 * jQuery mWheelIntent
 * @author trixta
 *
 * Version: 1.2
 */
(function($){

	var mwheelI = {
			pos: [-260, -260]
		},
		minDif 	= 3,
		doc 	= document,
		root 	= doc.documentElement,
		body 	= doc.body,
		longDelay, shortDelay;

	function unsetPos() {
		if (this===mwheelI.elem) {
			mwheelI.pos = [-260, -260];
			mwheelI.elem = false;
			minDif = 3;
		}
	}

	$.event.special.mwheelIntent = {
		setup	: function(){
			var jElm = $(this).bind('mousewheel', $.event.special.mwheelIntent.handler);
			if (this!==doc && this!==root && this!==body){
				jElm.bind('mouseleave', unsetPos);
			}
			jElm = null;
	        return true;
	    },
		teardown: function() {
	        $(this)
				.unbind('mousewheel', $.event.special.mwheelIntent.handler)
				.unbind('mouseleave', unsetPos)
			;
	        return true;
	    },
	    handler	: function(e, d) {
			var pos = [e.clientX, e.clientY];
			if (this===mwheelI.elem || Math.abs(mwheelI.pos[0] - pos[0]) > minDif || Math.abs(mwheelI.pos[1] - pos[1]) > minDif) {
	            mwheelI.elem = this;
				mwheelI.pos = pos;
				minDif = 250;

				clearTimeout(shortDelay);
				shortDelay = setTimeout(function() {
					minDif = 10;
				}, 200);
				clearTimeout(longDelay);
				longDelay = setTimeout(function() {
					minDif = 3;
				}, 1500);
				e = $.extend({}, e, {type: 'mwheelIntent'});
	            return $.event.handle.apply(this, arguments);
			}
	    }
	}

	$.fn.extend({
		mwheelIntent: function(fn) {
			return fn ? this.bind("mwheelIntent", fn) : this.trigger("mwheelIntent");
		},
		
		unmwheelIntent: function(fn) {
			return this.unbind("mwheelIntent", fn);
		}
	});

	$(function(){
		body = doc.body;
		//assume that document is always scrollable, doesn't hurt if not
		$(doc).bind('mwheelIntent.mwheelIntentDefault', $.noop);
	});

})(jQuery);
