/*! jNavigate v0.2a jnavigate.com | jnavigate.com/license */ (function(d){var g={intTrigger:".jnavigate-int-trigger",extTrigger:".jnavigate-ext-trigger",switchContent:!0,showLoader:!0,scrollToPosition:!0,scrollSpeed:500,loadingColor:"#FFF",spinner:"/assets/ajax-loader.gif",spinnerPosition:"center",useHistory:!0,cacheDocumentTitle:!1,loaded:null,error:null},e={init:function(b){var c=this.selector,a=d.extend({},g,b);a.useHistory&&h&&history.replaceState(i(d.extend({selector:c},a)),"",location.href);return this.each(function(){var b=d(this);b.selector=c; a.jNavigateContainer=b;d(a.extTrigger).bind("click",a,f);b.delegate(a.intTrigger,"click",a,f);b.data("jnavigate-triggers",{intTrigger:a.intTrigger,extTrigger:a.extTrigger})})},overlay:function(b){var c=d.extend({},g,b);return this.each(function(){var a=d(this),b=d(document.createElement("div")),e=a.offset(),f=e.left+parseInt(a.css("borderLeftWidth")),e=e.top+parseInt(a.css("borderTopWidth"));b.css({display:"none",width:a.innerWidth(),height:a.innerHeight(),position:"absolute",top:e,left:f,backgroundImage:"url("+ c.spinner+")",backgroundPosition:c.spinnerPosition,backgroundRepeat:"no-repeat",backgroundColor:c.loadingColor,zIndex:999}).appendTo("body").fadeIn(150);a.data("jnavigate-overlay",b)})}};e.navigate=function(b){var c=this.selector,a=d.extend({},g,b);return!a.url?this:this.each(function(){var b=d(this),f=b.data("jnavloaded")||a.loaded;b.data("jnavlasttrigger",a.trigger);a.showLoader&&e.overlay.call(b,a);d.ajax({type:a.httpmethod||"GET",url:a.url,data:"jnavigate=true"+(a.params||""),dataType:"html", success:function(g){var j=b.data("jnavigate-overlay");if(a.switchContent){b.children().fadeTo(0,0);b.html(g);j&&j.fadeOut(100).remove();b.children().fadeTo(500,1);if(a.docTitle)document.title=a.docTitle;a.scrollToPosition&&e.scrollTo(a.url.replace(/^[^#]*/,""),a.scrollSpeed)}f&&(b.data("jnavloaded",f),f.call(b,g));a.useHistory&&h&&"GET"===(a.httpmethod||"GET").toUpperCase()&&k!==a.url&&history.pushState(i(d.extend(a,{selector:c})),"",a.url)},error:a.error||function(){a.$form&&a.$form.length?a.$form.submit(): location.href=a.url}})})};e.destroy=function(){return this.each(function(){var b=d(this),c=b.data("jnavigate-triggers");c&&(b.undelegate(c.intTrigger,"click",f),d(c.extTrigger).unbind("click",f),d.removeData(b,"jnavigate-triggers"))})};e.scrollTo=function(b,c){var a=d(b).offset()||{top:0};c?d("html, body").delay(150).animate({scrollTop:a.top},c):d(window).scrollTop(a.top)};var f=function(b){var c=d(this),a={url:null,httpmethod:"GET",params:"",$form:null};if("INPUT"===this.nodeName||"BUTTON"===this.nodeName){if(a.$form= c.closest("form"),a.$form.length)a.url=a.$form.attr("action")||location.href,a.httpmethod=a.$form.attr("method"),a.params+="&"+a.$form.serialize(),c.attr("name")&&(a.params+="&jnavigateTrigger="+c.attr("name"))}else a.url=c.attr("href");a.trigger=c;a.url&&(b.preventDefault(),e.navigate.call(b.data.jNavigateContainer,d.extend(b.data,a)))},i=function(b){var c={};for(key in b)b.hasOwnProperty(key)&&~"boolean,number,string".search(typeof b[key])&&(c[key]=b[key]);c.url||(c.url=window.location.href);if(b.cacheDocumentTitle)c.docTitle= document.title;return c},h=!(!history||!history.pushState),k=location.href;h&&window.addEventListener("popstate",function(b){if(b.state&&b.state.selector)k=b.state.url,e.navigate.call(d(b.state.selector),b.state)},!1);d.fn.jNavigate=function(b){if(e[b])return e[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof b)return e.init.apply(this,arguments)}})(jQuery);