/*
 * 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 Plugin Scroller.
 * @author NOSE
 * @version 1.0.0	initial version			
 */
jQuery.fn.scroller = function(op) {	
	// defaults
	var defaults =  {	
			scrollSpeed: 300,
			scrollEasing: "easeOutSine"
	};
	jQuery.extend(defaults, op);

	// scroll
	jQuery(this).bind("click",scrollIt);


	/**
	* Scrolls to an element.
	*/
	function scrollIt() {
	  var target = jQuery(this).attr('href');
      var targetOffset = jQuery(target).offset().top;
      jQuery('html,body').animate({scrollTop: targetOffset}, defaults.scrollSpeed, defaults.scrollEasing);
	  return false;
	}



    // return
    return this;
};


(function($){	
	$.keyNav = function(){
		$.keyNav.watchKeys();
		$(':input').focus(function(){ $(window).unbind('keydown',$.keyNav.keyPress);});
		$(':input').blur(function(){ $(window).keydown($.keyNav.keyPress);});
	}

	$.keyNav.watchKeys =function(){
		$(window).keydown($.keyNav.keyPress);
	}

	$.keyNav.unwatchKeys =function(){
		$(window).unbind('keydown',$.keyNav.keyPress);
	}
		
	$.keyNav.keys = {"?": 0,"backspace": 8,"tab": 9,"enter": 13,"shift": 16,"ctrl": 17,"alt": 18,"pause_break": 19,
		"caps_lock": 20,"escape": 27,"page_up": 33,"page_down": 34,"end": 35,"home": 36,"left_arrow": 37,
		"up_arrow": 38,"right_arrow": 39,"down_arrow": 40,"insert": 45,"delete": 46,"0": 48,"1": 49,"2": 50,
		"3": 51,"4": 52,"5": 53,"6": 54,"7": 55,"8": 56,"9": 57,"a": 65,"b": 66,"c": 67,"d": 68,"e": 69,"f": 70,
		"g": 71,"h": 72,"i": 73,"j": 74,"k": 75,"l": 76,"m": 77,"n": 78,"o": 79,"p": 80,"q": 81,"r": 82,"s": 83,
		"t": 84,"u": 85,"v": 86,"w": 87,"x": 88,"y": 89,"z": 90,"left_window_key": 91,"right_window_key": 92,
		"select_key": 93,"numpad_0": 96,"numpad_1": 97,"numpad_2": 98,"numpad_3": 99,"numpad 4": 100,"numpad_5": 101,
		"numpad_6": 102,"numpad_7": 103,"numpad_8": 104,"numpad_9": 105,"multiply": 106,"add": 107,"subtract": 109,
		"decimal point": 110,"divide": 111,"f1": 112,"f2": 113,"f3": 114,"f4": 115,"f5": 116,"f6": 117,"f7": 118,
		"f8": 119,"f9": 120,"f10": 121,"f11": 122,"f12": 123,"num_lock": 144,"scroll_lock": 145,"semi_colon": 186,
		";": 186,"=": 187,"equal_sign": 187,"comma": 188,",": 188,"dash": 189,".": 190,"period": 190,"forward_slash": 191,
		"/": 191,"grave_accent": 192,"open_bracket": 219,"back_slash": 220,"\\": 220,"close_braket": 221,"single_quote":222}
		
	$.keyNav.watchedCodes = {};	
	$.keyNav.tieredCodes = {};	
	//setups the initial key watching
	
	$.keyNav.keyPress = function(e){
		if($.keyNav.watchedCodes[e.keyCode] != null){
			var funs = $.keyNav.watchedCodes[e.keyCode];
			$.each(funs,function(){	this.func.call(this.scope)});
		}
		return true;
	}
	
	//use the actual key for evaluation i.e. "J" or "K" all will be downcased for non-normal keys see the table above
	//if an integer is used, it will use that for the keycode, so if you want to watch 1 you must pass "1"
	//a strings will be converted to lowercase and all spaces will be convertedto underscores
	$.fn.whenPressed = function(key,fn){
		$.keyNav.assignAction($.keyNav.parseKey(key),fn,this);
	}
	
	$.whenPressed = function(key,fn){
		$.keyNav.assignAction($.keyNav.parseKey(key),fn,document);
	}
	
	$.keyNav.parseKey = function(key){
		if(parseInt(key) >= 0){ key = parseInt(key);}
		else{ key = $.keyNav.keys[key.toLowerCase().replace(/\s/g,'_')];}
		if(key == null){ return false;}
		else{ return key;}
	}
	
	$.keyNav.isLetterKey = function(key){
		return key >= 65 && key <= 90
	}
	
	$.keyNav.isNumberKey = function(key){
		return (key >= 48 && key <= 57) || (key >= 96 && key <= 105)
	}
	
	$.keyNav.assignAction = function(key,fn, obj){
		if($.keyNav.watchedCodes[key] == null){
			$.keyNav.watchedCodes[key] = [{func:fn, scope:obj}];
		}else{
			$.keyNav.watchedCodes[key] = $.keyNav.watchedCodes[key].push({func:fn, scope:obj})
		}
	}
	
	//will look for the href of the referrer object 
	$.fn.navigateTo = function(){
		if(this.attr('href')){
			window.location = this.attr('href');
		}
	}
	
	$.fn.or = function(str){
		if(this.length > 0){
			console.log($(this))
			return $(this);
		}else{
			return this.prevObject.find(str);
		}
	}
	
	$.fn.scrollTo = function(){
		var offset = this.offset().top;
		var totalH = $('html,body')[0].scrollTop + window.innerHeight;
		if((offset + this.outerHeight()) > totalH){
			window.scrollBy(0, ((offset + this.outerHeight()) - totalH));
		}else if(offset < $('html,body')[0].scrollTop){
			$('html,body')[0].scrollTop = offset;
		}
	}
})(jQuery);


/**
 * SEmail serves to secure email adresses against spam.
 * @author NOSE
 * @author SpamSpan (www.spamspan.com)
 * 
 * @example <script type="text/javascript" src="semail.js"></script>
 * @before
 	<span class="semail"><span class="username">test1.email</span>[at]<span class="domain">domain1.com</span></span>
 * 
 * 
 * @option sEmailClass The class name of the surrounding span.
 * @option sEmailUsernameClass The class name of the username span.
 * @option sEmailDomainClass The class name of the domain span.
 * 
 * @version 1.1.0 event listener
 * @version 1.0.0 initial version
 */
var SEmail = {	
	
	/**
	 * SEmail Parameters.
	 */
	sEmailClass: "email",
	sEmailUsernameClass: "username",
	sEmailDomainClass: "domain",
	
	/**
	 * Initializes the tracker.
	 */
	initialize: function() {
		// elements
		var elements = SEmail.getElementsByClassName(SEmail.sEmailClass,"span",document);
		
		// init
		for (var i = 0; i < elements.length; i++) {
			// vars
			var e = elements[i];
			var username = SEmail.getSpanValue(SEmail.sEmailUsernameClass,e);
			var domain = SEmail.getSpanValue(SEmail.sEmailDomainClass,e);
			var at = String.fromCharCode(32*2);
			
			// anchor
			var email = SEmail.cleanSpan(username) + at + SEmail.cleanSpan(domain);
			var mto = String.fromCharCode(109,97,105,108,116,111,58);			
			
			var anchorTagText = document.createTextNode(email);
			var anchorTag = document.createElement('a');
			anchorTag.className = SEmail.sEmailClass;
			anchorTag.setAttribute('href', mto + email);
			anchorTag.appendChild(anchorTagText);
			
			// replace the span with anchor
			e.parentNode.replaceChild(anchorTag, e);			
		}
	},
	
	
	/*
	 * Gets elements of a class.
	 */
	getElementsByClassName: function(searchClass,tag,scope) {
		// init
		var elements = new Array();
		if (tag == null) {
			tag = '*';
		}
		if (scope == null) {
			scope = document;
		}
		// search
		var tags = scope.getElementsByTagName(tag);
		var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
		for (var i = 0; i < tags.length; i++) {
			if ( pattern.test(tags[i].className) ) {
				elements.push(tags[i]);
			}
		}
		return elements;
	},
	/*
	 * Gets the span's value.
	 */
	getSpanValue: function(searchClass, scope) {
		var span = SEmail.getElementsByClassName(searchClass, 'span',scope);
		if (span[0]) {
			return span[0].innerHTML;
		}
		else return false;
	},
	/*
	 * Cleans a span.
	 */
	cleanSpan: function(val) {
		// replace comments <!-- bla --> text <!-- bla -->
		var cleaned = val.replace(/\<!\s*--(.*?)(--\s*\>)/g, '');
		
		// replace white space
		var cleaned = cleaned.replace(/\s+/g, '');
		return cleaned;
	},
	
	/*
	 * Adds an event listener.
	 * @el The element.
	 * @type The event type.
	 * @fn The function to invoke.
	 */
	 addListener: function() {
	 	// firefox, etc.
	 	if ( window.addEventListener ) {
        	return function(el, type, fn) {
        		el.addEventListener(type, fn, false);
        	};
    	} 
    	// ie
    	else if ( window.attachEvent ) {
        	return function(el, type, fn) {
            	var f = function() {
                	fn.call(el, window.event);
            	};
            	el.attachEvent('on'+type, f);
        	};
    	}
    	// other 
    	else {
        	return function(el, type, fn) {
            	element['on'+type] = fn;
        	}
    	}
	 }()

}

/**
 * Initialize on window load.
 */
SEmail.addListener(window, 'load', function(){SEmail.initialize()});
