// Code to run when to page has finished loading
$(function($) {
	var headerSearchBoxText = $("#q").attr("value");
    $("#q").focus(function() {
        if ($(this).attr("value") == headerSearchBoxText) {
            $(this).attr("value", "");
        }
    });

    $("#q").blur(function() {
        if ($(this).attr("value") == "") {
            $(this).attr("value", headerSearchBoxText);
        }
    });
	
	$("#nav-button").click(function(e) {
		e.preventDefault();
		$("body > div.content").toggle();
		$(this).toggleClass("active");
    });
	
	$("#comments-button").click(function(e) {
		e.preventDefault();
		$("#comments").show();
		$(this).hide();
    });
	
	/*var startX, offsetX, el = $(".content"), diffX;
	el[0].addEventListener('touchstart', function(e) {
	  // e.preventDefault();
	  offsetX = ($(window).width()-el.outerWidth(true))/2;
	  startX = e.targetTouches[0].pageX - offsetX;
	  el.css("-webkit-transition","all 0 ease 0");
	}, false);
	el[0].addEventListener("touchmove", function(e) {
	    // e.preventDefault();
	    diffX = (e.changedTouches[0].pageX - offsetX) - startX;
		if (Math.abs(diffX) > 30) {
			el.css("-webkit-transform", "translate3d("+diffX+"px, 0, 0)");
		}		
	}, false);
	el[0].addEventListener("touchend", function(e) {
		// e.preventDefault();
		if (diffX < -50) {
			$("nav.prev-next a[rel=next]").click();
		} else if (diffX > 50) {
			$("nav.prev-next a[rel=prev]").click();
		} else {
			el.css("-webkit-transform", "translate3d(0, 0, 0)");
		}
	}, false);*/
	
	
	
	
	
	/*
	// This is the semi-working version
	var url = {"next":$("nav.prev-next a[rel=next]").attr("href"), "prev":$("nav.prev-next a[rel=prev]").attr("href")}, next = $("nav.prev-next a[rel=next]").attr("href"), prev = $("nav.prev-next a[rel=prev]").attr("href"), url, title = {}, titleArray;
	function loadPostInBg(position) {
		$('<article class="'+position+'" />').insertBefore('.content article.current').hide();
		$(".content article."+position).load($("nav.prev-next a[rel="+position+"]").attr("href") + " .content article > *", function(data) {
			titleArray = data.match(/<title>(.+?)<\/title>/i);
			title[position] = (titleArray[1]) ? titleArray[1] : "";
			if (position == "next") {
				$(".content article."+position).css("left",$(window).width()+"px");//css("-webkit-transform", "translate3d("+$(window).width()+"px, 0, 0)");
			} else if (position == "prev") {
				$(".content article."+position).css("left","-"+$(window).width()+"px");
			}
			
			url = $(".content article."+position+" nav.prev-next a[rel=prev]").attr("href");
		});
	}
	
	loadPostInBg("next");
	loadPostInBg("prev");
	$("nav.prev-next a[rel=next]").live("click", function(e) {
		if ($(".content article.prev").size() > 0) {
			e.preventDefault();
			$(".content article.previous").remove();
			$(".content article.current").toggleClass("current previous").css("left","0").css("-webkit-transform", "translate3d(-"+$(window).width()+"px, 0, 0)");
			$(".content article.next").toggleClass("current next").show().css("-webkit-transform", "translate3d(-"+$(window).width()+"px, 0, 0)");
			$("body").scrollTop($("body > .content").offset().top);
			history.pushState({url: url["next"]}, title["next"], url["next"]);
			
			loadPostInBg("next");
		}
		
	});
	$("nav.prev-next a[rel=prev]").live("click", function(e) {
		if ($(".content article.prev").size() > 0) {
			e.preventDefault();
			$(".content article.next").remove();
			$(".content article.current").toggleClass("current next").css("left","0").css("-webkit-transform", "translate3d("+$(window).width()+"px, 0, 0)");
			$(".content article.prev").toggleClass("current prev").show().css("-webkit-transform", "translate3d("+$(window).width()+"px, 0, 0)");
			$("body").scrollTop($("body > .content").offset().top);
			history.pushState({url: url["prev"]}, title["prev"], url["prev"]);
			
			loadPostInBg("prev");
		}
	});
	*/
	
	
	
	
	
	
	
	
	/*if (next) {
		$("nav.prev-next a[rel=prev]").live("click", function(e) {
			e.preventDefault();
			$(".content article.previous").remove();
			$(".content article.current").toggleClass("current previous").css("left","0").css("-webkit-transform", "translate3d(-"+$(window).width()+"px, 0, 0)");
			$(".content article.next").toggleClass("current next").show().css("-webkit-transform", "translate3d(-"+$(window).width()+"px, 0, 0)");
			// $("body").scrollTop($("body > .content").offset().top);
			history.pushState({url: next}, "new page", next);
			
			$('<article class="next" />').insertBefore('.content article.current').hide();
			$(".content article.next").load(next + " .content article > *", function(data) {
				titleArray = data.match(/<title>(.+?)<\/title>/i);
				var title = (titleArray[1]) ? titleArray[1] : "";
				$(".content article.next").css("left",$(window).width()+"px");//css("-webkit-transform", "translate3d("+$(window).width()+"px, 0, 0)");
				next = $(".content article.next nav.prev-next a[rel=prev]").attr("href");
			});
		});
	
		loadPostInBg();
	}*/
	
});

/* Lumebox $ plugin
 * Copyright Anders Zakrisson/Sogeti 2009-2011
 * http://anders.zakrisson.se, http://www.sogeti.se
 * This software is released under the GPL License.
 */
 
(function(a){
var themeURL = a('meta[name=themeURL]').attr("content") + "/";
var lumeboxOptions = {graphicsDir: themeURL+"style/"};
function i(){this.media=this.id=this.published=this.snippet=this.content=this.link=this.title=null}function k(){this.version=this.description=this.link=this.title=null;this.items=[]}a.lumebox={loader:function(b){b.feedApiKey!=void 0?a.getScript("http://www.google.com/jsapi?key"+b.feedApiKey,function(){google.load("feeds","1",{nocss:true,callback:function(){a.lumebox.init(b)}})}):a.lumebox.init(b)},settings:{showAsList:false,rss:[],proxy:"",duration:"fast",rssWidth:680,opacity:"0.7",loop:true,
scrollToTop:false,autoNext:false,parentElementId:false,useParentOffset:true,useGestures:true,graphicsDir:"style/",feedApiKey:false,platformMode:"auto",noCaptionClass:"tn"},data:{lumeboxItems:new k,lumeboxFeeds:{},popupStatus:0,group:null,timeoutId:null,parentElement:null,index:1},init:function(b){b?a.lumebox.settings=a.extend({},a.lumebox.settings,b):b={};a.lumebox.data.parentElement=this.settings.parentElementId?a("#"+this.settings.parentElementId):a("body").eq(0);a.lumebox.data.parentElement.append('<div id="lumebox-popup"><div id="lumebox-topmenu"><a href="#" id="lumebox-close" class="lumebox-controls"><img src="'+
a.lumebox.settings.graphicsDir+'icon_close.png"></a><p id="lumebox-counter"></p></div><div id="lumebox-content"></div></div><div id="lumebox-bg"></div>');if(a.lumebox.settings.platformMode=="auto"&&(navigator.platform.indexOf("iPhone")!=-1||navigator.platform.indexOf("iPod")!=-1||navigator.userAgent.indexOf("iPad")!=-1||navigator.userAgent.indexOf("Android")!=-1))a.lumebox.settings.platformMode="mobile",a.lumebox.settings.opacity=1,a("#lumebox-popup").addClass("mobile");a("#lumebox-close").click(function(){a.lumebox.close()});
a.lumebox.settings.platformMode!="mobile"&&a("#lumebox-bg").click(function(){a.lumebox.close()});a.lumebox.settings.platformMode=="mobile"?a("#lumebox-content, #lumebox-bg").quickGestures({dragRight:function(){a.lumebox.previous()},dragLeft:function(){a.lumebox.next()},mobile:true,drag:a("#lumebox-content"),threshold:50}):a("#lumebox-content").quickGestures({clickLeft:function(){a.lumebox.previous()},clickRight:function(){a.lumebox.next()}});a(document).keydown(function(c){if(a.lumebox.data.popupStatus==
1){switch(c.keyCode){case 27:a.lumebox.close();break;case 39:a.lumebox.next();break;case 78:a.lumebox.next();break;case 37:a.lumebox.previous();break;case 80:a.lumebox.previous()}switch(c.charCode){case 110:a.lumebox.next();break;case 112:a.lumebox.previous()}}});a(window).bind("resize",function(){a.lumebox.resize()});var d;a("a[rel^=lightbox]").each(function(){var c=this.rel.match(/\[([a-zA-Z0-9\-]*)\]/i);if((c=c?c[1]:null)&&a.lumebox.data.lumeboxFeeds[c])d=a.lumebox.data.lumeboxFeeds[c];else if(c)d=
new k,d.title=c,a.lumebox.data.lumeboxFeeds[c]=d;if(this.href.search(/(\.jpg|\.jpeg|\.gif|\.png)$/i)!=-1){var b,h=new i;if(!a(this).attr("class").match(a.lumebox.settings.noCaptionClass))h.content=this.title;h.link=this.href;b=c?a.lumebox.data.lumeboxFeeds[c].items.push(h)-1:a.lumebox.data.lumeboxItems.items.push(h)-1;h.id=c+"-"+b;a(this).click(function(){a.lumebox.open({index:b,group:c});return false})}else if(a.lumebox.settings.feedApiKey!=false&&this.rel.search(/lightbox\[(rss[a-zA-Z0-9\-]*)\]/i)!=
-1){var e=this;a.lumebox.parseFeed({url:a.lumebox.settings.proxy+this.href,success:function(b){a.each(b.items,function(b,d){h=a.extend({},h,d);c?a.lumebox.data.lumeboxFeeds[c].items.push(h):a.lumebox.data.lumeboxItems.items.push(h)});a(e).click(function(){a.lumebox.open({index:null,group:c});return false})}})}});a.each(a.lumebox.settings.rss,function(b,d){a.lumebox.parseFeed({url:a.lumebox.settings.proxy+d,success:function(b){a.each(b.items,function(b,c){var d=a.extend({},d,c);a.lumebox.data.lumeboxItems.items.push(d)})}})});
return this},resize:function(b){if(a.lumebox.data.popupStatus==1){var d=parseInt(a("#lumebox-popup").css("margin-top").replace("px","")),c=a.lumebox.settings.platformMode=="mobile"?0:a("#lumebox-caption").outerHeight(true),f=a(window).width()-2*d,h=a(window).height()-2*d,e=a("#lumebox-content").find("img.lumebox-img").attr("src")?a("#lumebox-content").find("img.lumebox-img").eq(0):false,g=e?e.attr("width"):f;e?(g=e.attr("width")/e.attr("height"),e[0].naturalWidth+2*d>f?(e.attr("width",f),e.attr("height",
f/g)):(e.attr("width",e[0].naturalWidth),e.attr("height",e[0].naturalWidth/g)),e.outerHeight(true)+c+2*d>=h?(d=h-c-2*d,e.attr("height",d),e.attr("width",d*g),g*=e.outerHeight(true)):g=e.attr("width")):g=a.lumebox.settings.rssWidth;g<1&&(g=f);a("#lumebox-popup").css({width:g,left:(f-g)/2-(a.lumebox.settings.useParentOffset?a("body").offset().left:0)});f=a("#lumebox-content").outerHeight(true)+a("#lumebox-footer").outerHeight(true);a("#lumebox-popup").css({height:f,top:a(window).scrollTop()+(f>h?0:
h/2-f/2)});a.lumebox.settings.scrollToTop&&a(this).scrollTop(0);a.isFunction(b)&&b()}},open:function(b){b||(b={});a.lumebox.data.group=b.group?b.group:null;var d=b.group?a.lumebox.data.lumeboxFeeds[b.group]:a.lumebox.data.lumeboxItems;a.lumebox.data.index=b.index?b.index:0;var c;c=a.lumebox.settings.showAsList?d.items:[d.items[a.lumebox.data.index]];a.lumebox.data.popupStatus==0&&(a("#lumebox-bg").css({opacity:a.lumebox.settings.opacity}),a.lumebox.settings.platformMode=="mobile"&&(a("body > *").addClass("lumebox-hidden"),
a("html, body").addClass("lumebox")),a("#lumebox-bg").fadeIn("fast",function(){a("#lumebox-popup").css("opacity",0).show();a.lumebox.data.popupStatus=1;a.lumebox.switchPost(c,0,d)}))},close:function(){if(a.lumebox.data.popupStatus==1)a.lumebox.settings.platformMode=="mobile"&&(a("body > *").removeClass("lumebox-hidden"),a("html, body").removeClass("lumebox")),a("#lumebox-bg").fadeOut(a.lumebox.settings.duration),a("#lumebox-popup").fadeOut(a.lumebox.settings.duration),a.lumebox.data.popupStatus=0;
clearInterval(a.lumebox.data.timeoutId)},next:function(){var b=a.lumebox.data.group?a.lumebox.data.lumeboxFeeds[a.lumebox.data.group]:a.lumebox.data.lumeboxItems;a.lumebox.data.index=a.lumebox.data.index<b.items.length-1?a.lumebox.data.index+1:0;a.lumebox.switchPost([b.items[a.lumebox.data.index]],"next",b)},previous:function(){var b=a.lumebox.data.group?a.lumebox.data.lumeboxFeeds[a.lumebox.data.group]:a.lumebox.data.lumeboxItems;a.lumebox.data.index=a.lumebox.data.index>0?a.lumebox.data.index-1:
b.items.length-1;a.lumebox.switchPost([b.items[a.lumebox.data.index]],"previous",b)},switchPost:function(b,d,c,f){a.lumebox.data.popupStatus==1&&(a.lumebox.settings.platformMode=="mobile"?a("#lumebox-content"):a("#lumebox-popup")).animate({opacity:0},a.lumebox.settings.duration,function(){a.lumebox.settings.platformMode=="mobile"&&a(this).css("-webkit-transform","translate3d(0,0,0)");a("#lumebox-content").css("opacity",0).lboxFillContent(b,function(){a("#lumebox-popup").css("opacity",1);a("#lumebox-counter").html(a.lumebox.data.index+
1+"/"+c.items.length);a.lumebox.resize(function(){a("#lumebox-popup").children(":not(.lumebox-controls)").animate({opacity:1},a.lumebox.settings.duration);a.isFunction(f)&&f()})})})},parseFeed:function(b){b.url.search(/^http/i)!=-1&&(new google.feeds.Feed(b.url)).load(function(d){var c=new k;c.title=d.feed.title;c.link=d.feed.link;c.description=d.feed.description;c.version=d.feed.type;a(d.feed.entries).each(function(a,b){var d=new i;d.title=b.title;d.link=b.link;d.published=b.publishedDate;d.id=b.link;
d.content=b.content;d.snippet=b.contentSnippet;c.items.push(d)});a.isFunction(b.success)&&b.success(c)})},loadImage:function(b,d){a("#lboxItem-"+b.id).length<1&&a("<img />").attr("src",b.link).load(d);a("#lumebox-bg").find(".lumebox-preLoaded").length>50&&a("#lumebox-bg").find(".lumebox-preLoaded").eq(0).remove();var c=a.lumebox.data.group?a.lumebox.data.lumeboxFeeds[a.lumebox.data.group]:a.lumebox.data.lumeboxItems;a.each([c.items[a.lumebox.data.index<c.items.length-1?a.lumebox.data.index+1:0],c.items[a.lumebox.data.index<
c.items.length-2?a.lumebox.data.index+2:0]],function(b,d){a("#lboxItem-"+d.id).length<1&&a("<img />").attr("src",d.link).load(function(){a(this).attr({"class":"lumebox-preLoaded",id:"lboxItem-"+d.id,width:this.width,height:this.height}).appendTo("#lumebox-bg")})})}};a.fn.lboxFillContent=function(b,d){return this.each(function(){var c=this;b.length==1&&b[0].link.search(/(\.jpg|\.jpeg|\.gif|\.png)$/i)!=-1?(i=b[0],a("#lboxItem-"+i.id).length>0?(a.lumebox.loadImage(i),a(c).html(a("#lboxItem-"+i.id).clone().attr("class",
"lumebox-img")),a(c).find("img.lumebox-img").wrap('<div class="post"><div class="post-body"></div></div>'),i.content&&a(c).find("div.post-body").append('<div id="lumebox-caption">'+i.content+"</div>"),a.isFunction(d)&&d()):(a.lumebox.data.parentElement.append('<div id="lumebox-loading"><img src="'+a.lumebox.settings.graphicsDir+'ajax-loader.gif" /> Loading</div>'),a.lumebox.loadImage(i,function(){a("#lumebox-loading").remove();a(this).attr({"class":"lumebox-img",width:this.width,height:this.height});
a(c).html(this).find("img.lumebox-img").wrap('<div class="post"><div class="post-body"></div></div>');i.content&&a(c).find("div.post-body").append('<div id="lumebox-caption">'+i.content+"</div>");a.isFunction(d)&&d()}))):(html="",a.each(b,function(a,b){var d="",c="";b.title&&(d='<div class="post-title"><h2><a href="'+b.link+'">'+b.title+"</a></h2></div>");c=b.content;html+='<div class="post hentry">'+d+'<div class="post-body>">'+c+"</div></div>"}),a(c).html(html),a.isFunction(d)&&d())})};a.fn.quickGestures=
function(b){settings=a.extend({dragLeft:null,dragRight:null,clickLeft:null,clickRight:null,tap:null,hold:null,holdTime:1200,threshold:50,mobile:false,drag:true},b);this.each(function(){var b=0,c=0,f=null,h=null;if(settings.mobile){var e,g,i,j=0;this.addEventListener("touchstart",function(l){l.preventDefault();g=(a(window).width()-a(this).outerWidth(true))/2;i=(a(window).height()-a(this).outerHeight(true))/2;e=b=l.targetTouches[0].pageX-g;lastPagY=c=l.targetTouches[0].pageY-i;h=new Date;a.isFunction(settings.hold)&&
(f=setTimeout("settings.hold()",settings.holdTime))},false);a(this).bind("touchmove",function(a){a.preventDefault();e=(a.originalEvent.touches[0].pageX||a.originalEvent.changedTouches[0].pageX)-g;j=e-g-b;settings.drag&&settings.drag.css("-webkit-transform","translate3d("+j+"px, 0, 0)")},false);a(this).bind("touchend",function(c){c.preventDefault();f!=null&&clearTimeout(f);c=new Date;j<=-settings.threshold?a.isFunction(settings.dragLeft)&&settings.dragLeft():j>=settings.threshold?a.isFunction(settings.dragRight)&&
settings.dragRight():c.getTime()-h.getTime()<settings.holdTime?b<a(this).width()/2&&a.isFunction(settings.clickLeft)?settings.clickLeft():b>=a(this).width()/2&&a.isFunction(settings.clickRight)?settings.clickRight():a.isFunction(settings.tap)&&settings.tap():a.isFunction(settings.hold)?settings.hold():settings.drag.css("-webkit-transform","translate3d(0, 0, 0)")},false)}else a(this).mousedown(function(e){e.preventDefault();var g=(a(window).width()-a(this).outerWidth(true))/2,i=(a(window).height()-
a(this).outerHeight(true))/2;b=e.pageX-g;c=e.pageY-i;h=new Date;a.isFunction(settings.hold)&&(f=setTimeout("settings.hold()",settings.holdTime));a(this).mouseup(function(){f!=null&&clearTimeout(f);var c=e.pageX-g-b;(new Date).getTime()-h.getTime()<settings.holdTime&&c<settings.threshold&&(b<a(this).width()/2&&a.isFunction(settings.clickLeft)?settings.clickLeft():b>=a(this).width()/2&&a.isFunction(settings.clickRight)?settings.clickRight():a.isFunction(settings.tap)&&settings.tap());a(this).unbind("mouseup")});
a(this).mousemove(function(c){a(this).mouseup(function(){a(this).unbind("mousemove")});c=c.pageX-g-b;c<=-settings.threshold?(a(this).unbind("mousemove"),a.isFunction(settings.dragLeft)&&settings.dragLeft()):c>=settings.threshold&&(a(this).unbind("mousemove"),a.isFunction(settings.dragRight)&&settings.dragRight())})})});return this};a.lumebox.loader(typeof lumeboxOptions!="undefined"?lumeboxOptions:{})})(jQuery);
