/*! Respond.js v1.0.1pre: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function(e,h){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=h;if(h){return}var u=e.document,r=u.documentElement,i=[],k=[],p=[],o={},g=30,f=u.getElementsByTagName("head")[0]||r,b=f.getElementsByTagName("link"),d=[],a=function(){var B=b,w=B.length,z=0,y,x,A,v;for(;z<w;z++){y=B[z],x=y.href,A=y.media,v=y.rel&&y.rel.toLowerCase()==="stylesheet";if(!!x&&v&&!o[x]){if(y.styleSheet&&y.styleSheet.rawCssText){m(y.styleSheet.rawCssText,x,A);o[x]=true}else{if(!/^([a-zA-Z]+?:(\/\/)?)/.test(x)||x.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:x,media:A})}}}}t()},t=function(){if(d.length){var v=d.shift();n(v.href,function(w){m(w,v.href,v.media);o[v.href]=true;t()})}},m=function(G,v,x){var E=G.match(/@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi),H=E&&E.length||0,v=v.substring(0,v.lastIndexOf("/")),w=function(I){return I.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+v+"$2$3")},y=!H&&x,B=0,A,C,D,z,F;if(v.length){v+="/"}if(y){H=1}for(;B<H;B++){A=0;if(y){C=x;k.push(w(G))}else{C=E[B].match(/@media ([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;k.push(RegExp.$2&&w(RegExp.$2))}z=C.split(",");F=z.length;for(;A<F;A++){D=z[A];i.push({media:D.match(/(only\s+)?([a-zA-Z]+)(\sand)?/)&&RegExp.$2,rules:k.length-1,minw:D.match(/\(min\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1),maxw:D.match(/\(max\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1)})}}j()},l,q,j=function(E){var v="clientWidth",x=r[v],D=u.compatMode==="CSS1Compat"&&x||u.body[v]||x,z={},C=u.createDocumentFragment(),B=b[b.length-1],w=(new Date()).getTime();if(E&&l&&w-l<g){clearTimeout(q);q=setTimeout(j,g);return}else{l=w}for(var y in i){var F=i[y];if(!F.minw&&!F.maxw||(!F.minw||F.minw&&D>=F.minw)&&(!F.maxw||F.maxw&&D<=F.maxw)){if(!z[F.media]){z[F.media]=[]}z[F.media].push(k[F.rules])}}for(var y in p){if(p[y]&&p[y].parentNode===f){f.removeChild(p[y])}}for(var y in z){var G=u.createElement("style"),A=z[y].join("\n");G.type="text/css";G.media=y;if(G.styleSheet){G.styleSheet.cssText=A}else{G.appendChild(u.createTextNode(A))}C.appendChild(G);p.push(G)}f.insertBefore(C,B.nextSibling)},n=function(v,x){var w=c();if(!w){return}w.open("GET",v,true);w.onreadystatechange=function(){if(w.readyState!=4||w.status!=200&&w.status!=304){return}x(w.responseText)};if(w.readyState==4){return}w.send(null)},c=(function(){var v=false;try{v=new XMLHttpRequest()}catch(w){v=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return v}})();a();respond.update=a;function s(){j(true)}if(e.addEventListener){e.addEventListener("resize",s,false)}else{if(e.attachEvent){e.attachEvent("onresize",s)}}})(this,(function(f){if(f.matchMedia){return true}var e,i=document,c=i.documentElement,g=c.firstElementChild||c.firstChild,h=!i.body,d=i.body||i.createElement("body"),b=i.createElement("div"),a="only all";b.id="mq-test-1";b.style.cssText="position:absolute;top:-99em";d.appendChild(b);b.innerHTML='_<style media="'+a+'"> #mq-test-1 { width: 9px; }</style>';if(h){c.insertBefore(d,g)}b.removeChild(b.firstChild);e=b.offsetWidth==9;if(h){c.removeChild(d)}else{d.removeChild(b)}return e})(this));;
/*************************************************
**  jQuery Masonry version 1.3.2
**  Copyright David DeSandro, licensed MIT
**  http://desandro.com/resources/jquery-masonry
**************************************************/
(function(e){var n=e.event,o;n.special.smartresize={setup:function(){e(this).bind("resize",n.special.smartresize.handler)},teardown:function(){e(this).unbind("resize",n.special.smartresize.handler)},handler:function(j,l){var g=this,d=arguments;j.type="smartresize";o&&clearTimeout(o);o=setTimeout(function(){jQuery.event.handle.apply(g,d)},l==="execAsap"?0:100)}};e.fn.smartresize=function(j){return j?this.bind("smartresize",j):this.trigger("smartresize",["execAsap"])};e.fn.masonry=function(j,l){var g=
{getBricks:function(d,b,a){var c=a.itemSelector===undefined;b.$bricks=a.appendedContent===undefined?c?d.children():d.find(a.itemSelector):c?a.appendedContent:a.appendedContent.filter(a.itemSelector)},placeBrick:function(d,b,a,c,h){b=Math.min.apply(Math,a);for(var i=b+d.outerHeight(true),f=a.length,k=f,m=c.colCount+1-f;f--;)if(a[f]==b)k=f;d.applyStyle({left:c.colW*k+c.posLeft,top:b},e.extend(true,{},h.animationOptions));for(f=0;f<m;f++)c.colY[k+f]=i},setup:function(d,b,a){g.getBricks(d,a,b);if(a.masoned)a.previousData=
d.data("masonry");a.colW=b.columnWidth===undefined?a.masoned?a.previousData.colW:a.$bricks.outerWidth(true):b.columnWidth;a.colCount=Math.floor(d.width()/a.colW);a.colCount=Math.max(a.colCount,1)},arrange:function(d,b,a){var c;if(!a.masoned||b.appendedContent!==undefined)a.$bricks.css("position","absolute");if(a.masoned){a.posTop=a.previousData.posTop;a.posLeft=a.previousData.posLeft}else{d.css("position","relative");var h=e(document.createElement("div"));d.prepend(h);a.posTop=Math.round(h.position().top);
a.posLeft=Math.round(h.position().left);h.remove()}if(a.masoned&&b.appendedContent!==undefined){a.colY=a.previousData.colY;for(c=a.previousData.colCount;c<a.colCount;c++)a.colY[c]=a.posTop}else{a.colY=[];for(c=a.colCount;c--;)a.colY.push(a.posTop)}e.fn.applyStyle=a.masoned&&b.animate?e.fn.animate:e.fn.css;b.singleMode?a.$bricks.each(function(){var i=e(this);g.placeBrick(i,a.colCount,a.colY,a,b)}):a.$bricks.each(function(){var i=e(this),f=Math.ceil(i.outerWidth(true)/a.colW);f=Math.min(f,a.colCount);
if(f===1)g.placeBrick(i,a.colCount,a.colY,a,b);else{var k=a.colCount+1-f,m=[];for(c=0;c<k;c++){var p=a.colY.slice(c,c+f);m[c]=Math.max.apply(Math,p)}g.placeBrick(i,k,m,a,b)}});a.wallH=Math.max.apply(Math,a.colY);d.applyStyle({height:a.wallH-a.posTop},e.extend(true,[],b.animationOptions));a.masoned||setTimeout(function(){d.addClass("masoned")},1);l.call(a.$bricks);d.data("masonry",a)},resize:function(d,b,a){a.masoned=!!d.data("masonry");var c=d.data("masonry").colCount;g.setup(d,b,a);a.colCount!=c&&
g.arrange(d,b,a)}};return this.each(function(){var d=e(this),b={};b.masoned=!!d.data("masonry");var a=b.masoned?d.data("masonry").options:{},c=e.extend({},e.fn.masonry.defaults,a,j),h=a.resizeable;b.options=c.saveOptions?c:a;l=l||function(){};g.getBricks(d,b,c);if(!b.$bricks.length)return this;g.setup(d,c,b);g.arrange(d,c,b);!h&&c.resizeable&&e(window).bind("smartresize.masonry",function(){g.resize(d,c,b)});h&&!c.resizeable&&e(window).unbind("smartresize.masonry")})};e.fn.masonry.defaults={singleMode:false,
columnWidth:undefined,itemSelector:undefined,appendedContent:undefined,saveOptions:true,resizeable:true,animate:false,animationOptions:{}}})(jQuery);;
function updateZoom() {
	var self = this;
	clearTimeout(self.scrollTimer);
	if ( jQuery('#project-main-images').length > 0 ) {
		self.scrollTimer = setTimeout(function() { self.slideFollow() }, 250);
	}
}

function slideFollow() {

	var $sidebar = jQuery('#project-hidden-images'),
	$window    = jQuery(window),
	offset     = jQuery('.project-img-column').offset(),
	topPadding = 15,
	slideLimit = jQuery('#columns').height() - jQuery('#project-hidden-images').height() + 100,
	scrollTop  = $window.scrollTop() - offset.top + topPadding;
		
	if ($window.scrollTop() <= slideLimit) {
	
		if ($window.scrollTop() >= offset.top) {
			$sidebar.stop(true).animate({marginTop: scrollTop }, 400);
		} else {
		    $sidebar.stop(true).animate({marginTop: 0});
		}
	}
}

function CheckURLString(string) {
	var URL = window.location.href;
	
	if (URL.indexOf(string)!== -1) {
		return true;
	} else {
		return false;
	}
}

function initMasonry() {
	// Init Masonry Plugin
	if ( jQuery('div.view-id-work.bricks div.featured-work ul, #supporting-images ul.supporting-images').length ) {
		var speed = 500;
		var $_theBricks = jQuery('div.view-id-work.bricks div.featured-work ul, #supporting-images ul.supporting-images');
		if ( $_theBricks.length ) {
			$_theBricks.masonry({ isFitWidth: true, singleMode: true, resizeable: false, itemSelector: 'li.brick',
				animationOptions: {
					duration: speed,
					queue: false
				} 
			});
			$_theBricks.css('visibility','visible');
		}
	}
}

jQuery(document).ready(function($) {

	
	if ( $('#project-main-images').length ){
		initMasonry();
		// Project Supporting Images
		var $_supportingThumbs = $('#supporting-images ul li');
		var $_hiddenImages = $('#project-hidden-images ul li');
		var columnHeight = $('div.project-img-column').height();
		$('div.project-img-column').css('min-height', columnHeight);
		
		console.log(columnHeight);
		
		$_supportingThumbs.click(function() {
			self.updateZoom();
			// NEED TO CHECK IF USER IS SCROLLED DOWN TOO FAR SO IMAGE DOESN'T GET STUCK BELOW FOOTER		 
			var thumbIndex = $(this).index();
			$('#project-main-images').animate({ width: '0px' }, 300, function(){
				//$('#project-main-images').hide();
				$('#project-main-images').addClass('inactive');
				$('#project-hidden-images ul li:eq(' + thumbIndex + ')').show().width('642px');
				$('#project-hidden-images').removeClass('inactive').animate({width: '642px'}, 300);
				$(window).bind('scroll.slideEvent', function() {
					self.updateZoom();
				});
			});
			
			$_hiddenImages.click(function() {
				$('#project-hidden-images').animate({ width: '0px' }, 300, function() {
					$('#project-hidden-images').addClass('inactive');
					$('#project-hidden-images ul li:eq(' + thumbIndex + ')').hide();
					$('#project-main-images').removeClass('inactive').animate({width: '642px'}, 300);
					$(window).unbind('scroll.slideEvent');
				});
			});
		
		});
		
		// Social Media Button
		$('#socializer').hover(function() {
			$(this).children('a.social-btn').hide();
			$(this).children('ul').show();
		}, function() {
			$(this).children('a.social-btn').show();
			$(this).children('ul').hide();
		});
	}
	
	
	// Main Menu Set Active State
	if ( CheckURLString("work") ) {
		$('#primary-menu-bar ul li.menu-334 a').addClass("active");
	} else if ( CheckURLString("posts") ) {
		$('#primary-menu-bar ul li.menu-346 a').addClass("active");
	}
	
	
	// Clear Text Fields
	$('input.form-text, #webform-client-form-11 textarea.form-textarea').focus(function() {
	    if (!$(this).data('originalValue')) {
	        $(this).data('originalValue', $(this).val());
	    }
	    if ($(this).val() == $(this).data('originalValue')) {
	        $(this).val('');
	    }
	}).blur(function(){
	    if ($(this).val() == '') {
	        $(this).val($(this).data('originalValue'));
	    }
	});
	/*
	if ( $('div.featured-work ul li a img').length ) {
		var $_theImages = $('div.featured-work ul li a img');
		$_theImages.each(function(i) {
		    //var $_imageClone = $(this).attr('src');
		    //alert($_imageClone);
		    
		    $(this).clone().appendTo($(this).parent()).css('display','none');  
		});
		
		$_theImages.filter(':visible').pixastic("desaturate");
	}
	*/
	if ( $('div.featured-work ul li a img').length ) {
		var $_theImages = $('div.featured-work ul li a img');
		$_theImages.hover(function(){
				//$(this).animate({opacity: 1});
			}, function(){
				//$(this).animate({opacity: 0.4});
			});
	}
});

jQuery(window).load(function(){
	initMasonry();
});;

