(function(n){n.fn.pjax=function(t,i){i?i.container=t:i=n.isPlainObject(t)?t:{container:t};if(i.container&&typeof i.container!="string"){throw"pjax container must be a string selector!";return!1}return this.live("click",function(t){if(t.which>1||t.metaKey)return!0;var r={url:this.href,container:n(this).attr("data-pjax"),clickedElement:n(this),fragment:null};n.pjax(n.extend({},r,i)),t.preventDefault()})},n.pjax=function(t){var r=n(t.container),f=t.success||n.noop,e,u,i;delete t.success;if(typeof t.container!="string")throw"pjax container must be a string selector!";return e={async:!1},u={timeout:5e3,push:!0,replace:!1,data:{_pjax:!0},type:"GET",dataType:"html",beforeSend:function(n){r.trigger("start.pjax"),n.setRequestHeader("X-PJAX","true")},error:function(){window.location=t.url},complete:function(){r.trigger("end.pjax")},success:function(i){var s,c,h,u,o,e;if(t.fragment){s=n(i).find(t.fragment);if(s.length)i=s.children();else return window.location=t.url}else if(!n.trim(i)||/<html/i.test(i))return window.location=t.url;r.html(i),c=document.title,h=n.trim(r.find("title").remove().text()),h&&(document.title=h),u={pjax:t.container,fragment:t.fragment,timeout:t.timeout},o=n.param(t.data),o!="_pjax=true"&&(u.url=t.url+(/\?/.test(t.url)?"&":"?")+o),t.replace?window.history.replaceState(u,document.title,t.url):t.push&&(n.pjax.active||(window.history.replaceState(n.extend({},u,{url:null}),c),n.pjax.active=!0),window.history.pushState(u,document.title,t.url)),(t.replace||t.push)&&window._gaq&&_gaq.push(["_trackPageview"]),e=window.location.hash.toString(),e!==""&&(window.location.href=e),f.apply(this,arguments)}},t=n.extend(!0,{},u,t),n.isFunction(t.url)&&(t.url=t.url()),i=n.pjax.xhr,i&&i.readyState<4&&(i.onreadystatechange=n.noop,i.abort()),n.pjax.xhr=n.ajax(t),n(document).trigger("pjax",n.pjax.xhr,t),n.pjax.xhr};var t="state"in window.history,i=location.href;n(window).bind("popstate",function(r){var e=!t&&location.href==i,u,f;t=!0;if(e)return;u=r.state,u&&u.pjax&&(f=u.pjax,n("body").unbind("start.pjax").unbind("end.pjax"),n(f+"").length?n.pjax({url:u.url||location.href,fragment:u.fragment,container:f,push:!1,timeout:u.timeout}):window.location=location.href)}),n.inArray("state",n.event.props)<0&&n.event.props.push("state"),n.support.pjax=window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/(iPod|iPhone|iPad|WebApps\/.+CFNetwork)/),n.support.pjax||(n.pjax=function(t){window.location=n.isFunction(t.url)?t.url():t.url},n.fn.pjax=function(){return this})})(jQuery);
