/* 
* ----------------------------------------------------------- 
*
* Hello JS viewer!
*
* Though I would normally remove all the comments and minify a 
* production script, I've left this one commented out so you can
* see what I'm up to. Hope it's helpful!
*
*
* ------------------------------------------------------------
*/



/* jQuery Plugins -------------------------------------------- */

/*
 * Lazy Load - jQuery plugin for lazy loading images
 * Copyright (c) 2007-2011 Mika Tuupola
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * Project home: http://www.appelsiini.net/projects/lazyload
 * Version:  1.7.0-dev
 */
 
(function($){$.fn.lazyload=function(options){var settings={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:window,skip_invisible:true};if(options){if(undefined!==options.failurelimit){options.failure_limit=options.failurelimit;delete options.failurelimit;}
$.extend(settings,options);}
var elements=this;if(0==settings.event.indexOf("scroll")){$(settings.container).bind(settings.event,function(event){var counter=0;elements.each(function(){if(settings.skip_invisible&&!$(this).is(":visible"))return;if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$(this).trigger("appear");}else{if(++counter>settings.failure_limit){return false;}}});var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);});}
this.each(function(){var self=this;self.loaded=false;$(self).one("appear",function(){if(!this.loaded){$("<img />").bind("load",function(){$(self).hide().attr("src",$(self).data("original"))
[settings.effect](settings.effectspeed);self.loaded=true;}).attr("src",$(self).data("original"));};});if(0!=settings.event.indexOf("scroll")){$(self).bind(settings.event,function(event){if(!self.loaded){$(self).trigger("appear");}});}});$(window).bind("resize",function(event){$(settings.container).trigger(settings.event);});$(settings.container).trigger(settings.event);return this;};$.belowthefold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).height()+$(window).scrollTop();}else{var fold=$(settings.container).offset().top+$(settings.container).height();}
return fold<=$(element).offset().top-settings.threshold;};$.rightoffold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).width()+$(window).scrollLeft();}else{var fold=$(settings.container).offset().left+$(settings.container).width();}
return fold<=$(element).offset().left-settings.threshold;};$.abovethetop=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollTop();}else{var fold=$(settings.container).offset().top;}
return fold>=$(element).offset().top+settings.threshold+$(element).height();};$.leftofbegin=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollLeft();}else{var fold=$(settings.container).offset().left;}
return fold>=$(element).offset().left+settings.threshold+$(element).width();};$.extend($.expr[':'],{"below-the-fold":function(a){return $.belowthefold(a,{threshold:0,container:window})},"above-the-fold":function(a){return!$.belowthefold(a,{threshold:0,container:window})},"right-of-fold":function(a){return $.rightoffold(a,{threshold:0,container:window})},"left-of-fold":function(a){return!$.rightoffold(a,{threshold:0,container:window})}});})(jQuery);


/*
* $ lightbox_me
* By: Buck Wilson
* Version : 2.3
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/

(function(a){a.fn.lightbox_me=function(b){return this.each(function(){var e=a.extend({},a.fn.lightbox_me.defaults,b),l=a(),k=a(this),m=a('<iframe id="foo" style="z-index: '+(e.zIndex+1)+';border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0; filter: mask();"/>'),g=(a.browser.msie&&a.browser.version<7);if(e.showOverlay){var f=a(".js_lb_overlay:visible");if(f.length>0){l=a('<div class="lb_overlay_clear js_lb_overlay"/>')}else{l=a('<div class="'+e.classPrefix+'_overlay js_lb_overlay"/>')}}if(g){var d=/^https/i.test(window.location.href||"")?"javascript:false":"about:blank";m.attr("src",d);a("body").append(m)}a("body").append(k.hide()).append(l);if(e.showOverlay){h();l.css({position:"absolute",width:"100%",top:0,left:0,right:0,bottom:0,zIndex:(e.zIndex+2),display:"none"});if(!l.hasClass("lb_overlay_clear")){l.css(e.overlayCSS)}}if(e.showOverlay){l.fadeIn(e.overlaySpeed,function(){c();k[e.appearEffect](e.lightboxSpeed,function(){h();c();e.onLoad()})})}else{c();k[e.appearEffect](e.lightboxSpeed,function(){e.onLoad()})}if(e.parentLightbox){e.parentLightbox.fadeOut(200)}a(window).resize(h).resize(c).scroll(c).keyup(j);if(e.closeClick){l.click(function(n){i();n.preventDefault})}k.delegate(e.closeSelector,"click",function(n){i();n.preventDefault()});k.bind("close",i);k.bind("reposition",c);function i(){var n=k[0].style;if(e.destroyOnClose){k.add(l).remove()}else{k.add(l).hide()}if(e.parentLightbox){e.parentLightbox.fadeIn(200)}m.remove();k.undelegate(e.closeSelector,"click");a(window).unbind("reposition",h);a(window).unbind("reposition",c);a(window).unbind("scroll",c);a(document).unbind("keyup",j);if(g){n.removeExpression("top")}e.onClose()}function j(n){if((n.keyCode==27||(n.DOM_VK_ESCAPE==27&&n.which==0))&&e.closeEsc){i()}}function h(){if(a(window).height()<a(document).height()){l.css({height:a(document).height()+"px"});m.css({height:a(document).height()+"px"})}else{l.css({height:"100%"});if(g){a("html,body").css("height","100%");m.css("height","100%")}}}function c(){var o=k[0].style;k.css({left:"50%",marginLeft:(k.outerWidth()/2)*-1,zIndex:(e.zIndex+3)});if((k.height()+80>=a(window).height())&&(k.css("position")!="absolute"||g)){var n=a(document).scrollTop()+40;k.css({position:"absolute",top:n+"px",marginTop:0});if(g){o.removeExpression("top")}}else{if(k.height()+80<a(window).height()){if(g){o.position="absolute";if(e.centered){o.setExpression("top",'(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');o.marginTop=0}else{var p=(e.modalCSS&&e.modalCSS.top)?parseInt(e.modalCSS.top):0;o.setExpression("top","((blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "+p+') + "px"')}}else{if(e.centered){k.css({position:"fixed",top:"50%",marginTop:(k.outerHeight()/2)*-1})}else{k.css({position:"fixed"}).css(e.modalCSS)}}}}}})};a.fn.lightbox_me.defaults={appearEffect:"fadeIn",appearEase:"",overlaySpeed:250,lightboxSpeed:300,closeSelector:".close",closeClick:true,closeEsc:true,destroyOnClose:false,showOverlay:true,parentLightbox:false,onLoad:function(){},onClose:function(){},classPrefix:"lb",zIndex:999,centered:false,modalCSS:{top:"40px"},overlayCSS:{opacity:1}}})(jQuery);


/*
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 5/25/2009
* @author Ariel Flesler
* @version 1.4.2
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/
 
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/* 
* Email Obfuscation Script
* by John Plummer
* http://http://www.johnplummer.com/js-html-and-css/email-obfuscation.html
*/ 

(function($){$.fn.deobfuscate=function(){$(this).each(function(i,el){var email,subject;email=el.innerHTML;email=email.replace(/ at /gi,"@").replace(/ dot /gi,".");subject=el.getAttribute('data-subject');subject=subject?("?subject="+subject):""
email='<a href="mailto:'+email+subject+'">'+email+'</a>';el.innerHTML=email;});return this;};})(jQuery);


/* My Scripts -------------------------------------------- */

$(document).ready(function(){
	// Remove the default 'no-js' class and add 'js' class to allow for JS-enabled-only styles
	$('html').removeClass('no-js').addClass('js');
	// Initialize lazy image loading plugin and begin loading image once image is scrolled within 800px of viewport
	$("img.lazy").show().lazyload({
		threshold : 800
	});
	// Detect if the user is on an iOS device
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))){
		// add class 'iOS' to enable iOS specific styles (e.g. making the nav items larger and more tappable)
		$('html').addClass('iOS');
	} else {
		// If the user is NOT on an iOS device, add any behaviors that are not iOS-friendly (such as this tooltip script)
		$('a.tip, figure.tip, #lb').hover(function(){
			var title = $(this).attr('title');
			$(this).data('tipText', title).removeAttr('title');
			$('<p class="tooltip"></p>')
				.text(title)
				.appendTo('body')
				.fadeIn('slow');
			}, function() {
				$(this).attr('title', $(this).data('tipText'));
				$('.tooltip').remove();
			}).mousemove(function(e) {
				var mousex = e.pageX + 20;
				var mousey = e.pageY + 10;
				$('.tooltip')
				.css({ top: mousey, left: mousex })
		}); 
	}
	// When a project thumbnail is clicked/tapped, check to see if the newly-expanded project description is visible. If not, scroll the viewport so that the user can see the description.
	// This prevents situations where the user clicks/taps on a project thumbnail, but since the now-visible project description is offscreen, the user doesn't see the result of their action.
	$("figure.vis").click(function(e){
		e.preventDefault();
		// Get the distance of the clicked element from the top of the document
		var absDist = $(this).offset().top;
		// Get the current position of the scrollbar
		var scrollDist = $(window).scrollTop();
		// Values less than 0 mean the user has NOT scrolled past the clicked element, and the project description is hidden.
		// Values greater than 0 mean the user HAS scrolled past the clicked element, and the project description is visible.
		var winDist = absDist - scrollDist;
		// if the clicked element is already active, do nothing
		if ($(this).not('.active').length){
			// If the project description is not visible, scroll it into view
			if ( winDist > 0) {		
				$.scrollTo(this, 500, {axis:'y', offset:{top:150, left:0} });
			}  
		}
		$(this)
			.toggleClass('active')
			.parent()
			.find('.pr-desc')
			.toggleClass('active')
			.slideToggle();
	});	
	// When a link with class "lb" is clicked, run the lightbox script
	$('a.lb').click(function(event){
		var lbContent = $(this).attr('href');
		$("#lb")
			.empty()
			.append("<img class='close' title='Click to close.' src='" + lbContent + "' />")
			.lightbox_me();
			event.preventDefault();
	});
	// Email addresses are obfuscated (but human-readable) in the markup to fight spammers harvesting bots, this script deobfuscates the address and wraps it in a "mailto:" link.
	$('.email-address').deobfuscate();
});
		
