(function(a){a.fn.lazyload=function(b){var c={threshold:0,failurelimit:1,event:"scroll",effect:"show",container:window};b&&a.extend(c,b);var d=this,e=[],f=!1;"scroll"==c.event&&a(c.container).bind("scroll",function(){var b=0;d.each(function(){if(!a.abovethetop(this,c)&&!a.leftofbegin(this,c)&&a(this).is(":visible"))if(!a.belowthefold(this,c)&&!a.rightoffold(this,c))e.indexOf(this)==-1&&!this.loaded&&e.push(this);else if(b++>c.failurelimit)return!1});e.length>0&&!f&&(f=!0,a(e[0]).trigger("appear"));
var g=a.grep(d,function(a){return!a.loaded});d=a(g)});var g=0;this.each(function(){var b=this;b.cnt=g++;"scroll"!=c.event||!a(b).attr("src")||void 0==a(b).attr("src")||c.placeholder==a(b).attr("src")||a.abovethetop(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.rightoffold(b,c)?(c.placeholder?a(b).attr("src",c.placeholder):a(b).removeAttr("src"),b.loaded=!1):b.loaded=!0;a(b).bind("appear",function(){a(b).unbind("appear");this.loaded||(f=!0,a("<img />").bind("load",function(){a(b).css("opacity",
"1").hide().attr("src",a(b).attr("original"))[c.effect](c.effectspeed);b.loaded=!0;f=!1;e.length>0&&(e.shift(),a(e[0]).delay(b.cnt*5).trigger("appear"))}).attr("src",a(b).attr("original")))})});a(c.container).trigger(c.event);return this};a.belowthefold=function(b,c){return(c.container===void 0||c.container===window?a(window).height()+a(window).scrollTop():a(c.container).offset().top+a(c.container).height())<=a(b).offset().top-c.threshold};a.rightoffold=function(b,c){return(c.container===void 0||
c.container===window?a(window).width()+a(window).scrollLeft():a(c.container).offset().left+a(c.container).width())<=a(b).offset().left-c.threshold};a.abovethetop=function(b,c){return(c.container===void 0||c.container===window?a(window).scrollTop():a(c.container).offset().top)>=a(b).offset().top+c.threshold+a(b).height()};a.leftofbegin=function(b,c){return(c.container===void 0||c.container===window?a(window).scrollLeft():a(c.container).offset().left)>=a(b).offset().left+c.threshold+a(b).width()};a.extend(a.expr[":"],
{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"})})(jQuery);$.routemachine={init:function(){$.routemachine.activeRoute=null;$.routemachine.queuedRoute=null;$.routemachine.inTransition=!1;$.routemachine.routes=[];$.routemachine.routePatterns=[]},add:function(a,b){$.routemachine.routes.push([a,b]);$.routemachine.routePatterns.push($.routemachine.regExpPath(a))},regExpPath:function(a){var b=[],a=String(a).replace(/\((\:?[\w\-,+&]+)\)/g,function(a,b){return""+b+"?"}),a=a.replace(/\:([\w\-,+&]+)(\/?)/g,function(a,d){b.push(d);return"(([\\w-,+&]+)(/|$))"}),a=a.replace(/\)\?\/\(/g,
")?(");a.match(/\*/)&&(b.push("path"),a=a.replace(/\*/g,"((.+$))?"));return[RegExp("^"+a+"$"),b]},generateURL:function(a,b){b=b||{};if(typeof b=="string"&&a.match(/\*/))a=a.replace(/\*/,b).replace(/\/\//g,"/");else{b.path&&(a=a.replace(/\*/,b.path.replace(/^\//,"")));var c=RegExp("(\\()?\\:([\\w]+)(\\))?(/|$)","g"),d;for(d in b)d!="path"&&(a=a.replace(c,function(a,c,g,i,h){return g==d?b[d]+h:(c||"")+":"+g+(i||"")+h}))}return a=a.replace(/\([^\)]+\)/g,"")},getRouteFromPath:function(a){for(var a=a.replace(" ",
"+"),b=0;b<$.routemachine.routes.length;b++)if($.routemachine.routes[b][0]==a)return $.routemachine.routes[b][1];for(b=0;b<$.routemachine.routePatterns.length;b++)if($.routemachine.routePatterns[b][0].exec(a))return $.routemachine.routes[b][1];return null},onUpdate:function(a){for(var b=$.address.path(),b=b.replace(" ","+"),c,d=0;d<$.routemachine.routes.length;d++)if($.routemachine.routes[d][0]==b)return c=$.routemachine.generateURL($.routemachine.routes[d][0]),$.routemachine.onUpdateOutcome(null,
d,c,a),!0;for(d=0;d<$.routemachine.routePatterns.length;d++)if(c=$.routemachine.routePatterns[d][0].exec(b)){for(var b={},e=0;e<$.routemachine.routePatterns[d][1].length;e++)b[$.routemachine.routePatterns[d][1][e]]=c[(e+1)*3-1];c=$.routemachine.generateURL($.routemachine.routes[d][0],b);$.routemachine.onUpdateOutcome(b,d,c,a);return!0}return!1},onUpdateOutcome:function(a,b,c,d){if($.routemachine.inTransition){if($.routemachine.activeRoute.url!=c)$.routemachine.queuedRoute={id:b,url:c,params:a,data:d}}else $.routemachine.inTransition=
!0,$.routemachine.activeRoute?($.routemachine.queuedRoute={id:b,url:c,params:a,data:d},$.routemachine.routes[$.routemachine.activeRoute.id][1].trigger("hideRoute")):($.routemachine.queuedRoute=null,$.routemachine.activeRoute={id:b,url:c,params:a,data:d},$.routemachine.routes[$.routemachine.activeRoute.id][1].trigger("updateData",[d]),firstTimeAround||$.routemachine.routes[$.routemachine.activeRoute.id][1].trigger("showRoute",a))},triggerShowFirstTime:function(){$.routemachine.routes[$.routemachine.activeRoute.id][1].trigger("showRoute",
$.routemachine.activeRoute.params)},showRouteComplete:function(){$.routemachine.inTransition=!1;if($.routemachine.queuedRoute)$.routemachine.onUpdateOutcome($.routemachine.queuedRoute.params,$.routemachine.queuedRoute.id,$.routemachine.queuedRoute.url,$.routemachine.queuedRoute.data)},hideRouteComplete:function(){$.routemachine.inTransition=!1;$.routemachine.activeRoute=null;if($.routemachine.queuedRoute)$.routemachine.onUpdateOutcome($.routemachine.queuedRoute.params,$.routemachine.queuedRoute.id,
$.routemachine.queuedRoute.url,$.routemachine.queuedRoute.data)}};(function(a){a.route=function(b,c){var d=document.createElement("div"),e={id:null,data:null,appendingData:null},f={showRoute:function(){},hideRoute:function(){},updateData:function(a,b){e.data=b},getType:function(){return"default"}};b&&a.extend(e,b);c&&a.extend(f,c);a(d).bind("showRoute",f.showRoute);a(d).bind("hideRoute",f.hideRoute);a(d).bind("updateData",f.updateData);a(d).data("config",e);a(d).data("type",f.getType());return a(d)}})(jQuery);
