/*
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
*/
if(typeof window.console!=="object"||typeof window.console.emulated==="undefined"){if(typeof window.console!=="object"||typeof window.console.log!=="function"){window.console={};window.console.log=window.console.debug=window.console.warn=window.console.trace=function(){};window.console.error=function(){alert("An error has occured. Please use another browser to obtain more detailed information.")}}else{if(typeof window.console.debug==="undefined")window.console.debug=function(){for(var b=["console.debug:"],
a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,b)};if(typeof window.console.warn==="undefined")window.console.warn=function(){for(var b=["console.warn:"],a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,b)};if(typeof window.console.error==="undefined")window.console.error=function(){for(var b=["console.error"],a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,b)};if(typeof window.console.trace===
"undefined")window.console.trace=function(){window.console.error.apply(window.console,["console.trace does not exist"])}}window.console.emulated=true}String.prototype.trim=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")};String.prototype.strip=String.prototype.strip||function(b,a){b=String(b);var c=this;if(b.length){a||0||(b=b.replace(/([\[\]\(\)\^\$\.\?\|\/\\])/g,"\\$1"));c=c.replace(eval("/^"+b+"+|"+b+"+$/g"),"")}return String(c)};
String.prototype.stripLeft=String.prototype.stripLeft||function(b,a){b=String(b);var c=this;if(b.length){a||0||(b=b.replace(/([\[\]\(\)\^\$\.\?\|\/\\])/g,"\\$1"));c=c.replace(eval("/^"+b+"+/g"),"")}return String(c)};String.prototype.stripRight=String.prototype.stripRight||function(b,a){b=String(b);var c=this;if(b.length){a||0||(b=b.replace(/([\[\]\(\)\^\$\.\?\|\/\\])/g,"\\$1"));c=c.replace(eval("/"+b+"+$/g"),"")}return String(c)};
String.prototype.toInt=String.prototype.toInt||function(){return parseInt(this,10)};String.prototype.wrap=String.prototype.wrap||function(b,a){return b+this+a};String.prototype.wrapSelection=String.prototype.wrapSelection||function(b,a,c,d){if(typeof c==="undefined"||c===null)c=this.length;if(typeof d==="undefined"||d===null)d=this.length;return this.substring(0,c)+b+this.substring(c,d)+a+this.substring(d)};
String.prototype.toSlug=String.prototype.toSlug||function(){return this.toLowerCase().replace(/[\s_]/g,"-").replace(/[^-a-z0-9]/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")};
String.prototype.queryStringToJSON=String.prototype.queryStringToJSON||function(){var b=String(this);b=b.substring(b.indexOf("?")+1);b=b.replace(/\+/g,"%20");if(b.substring(0,1)==="{"&&b.substring(b.length-1)==="}")return eval(decodeURIComponent(b));b=b.split(/\&(amp\;)?/);for(var a={},c=0,d=b.length;c<d;++c){var e=b[c]||null;if(e!==null){e=e.split("=");if(e!==null){var f=e[0]||null;if(f!==null)if(typeof e[1]!=="undefined"){e=e[1];f=decodeURIComponent(f);e=decodeURIComponent(e);try{e=eval(e)}catch(g){}var h=
f.split(".");if(h.length===1)a[f]=e;else{var j="",i="";$.each(h,function(n,k){j+='["'+k.replace(/"/g,'\\"')+'"]';jsonCLOSUREGLOBAL=a;i="if ( typeof jsonCLOSUREGLOBAL"+j+' === "undefined" ) jsonCLOSUREGLOBAL'+j+" = {}";eval(i);a=jsonCLOSUREGLOBAL;delete jsonCLOSUREGLOBAL});jsonCLOSUREGLOBAL=a;valueCLOSUREGLOBAL=e;i="jsonCLOSUREGLOBAL"+j+" = valueCLOSUREGLOBAL";eval(i);a=jsonCLOSUREGLOBAL;delete jsonCLOSUREGLOBAL;delete valueCLOSUREGLOBAL}}}}}return a};
(function(b){b.fn.binder=b.fn.binder||function(a,c,d){var e=b(this);if(d)e.bind(a,c,d);else{d=c;e.bind(a,d)}return e};b.fn.once=b.fn.once||function(a,c,d){var e=b(this);if(d){e.unbind(a,d);e.bind(a,c,d)}else{d=c;e.unbind(a,d);e.bind(a,d)}return e};b.fn.enter=b.fn.enter||function(a,c){return b(this).binder("enter",a,c)};b.event.special.enter=b.event.special.cancel||{setup:function(){b(this).bind("keypress",b.event.special.enter.handler)},teardown:function(){b(this).unbind("keypress",b.event.special.enter.handler)},
handler:function(a){b(this);if(a.keyCode===13){a.type="enter";b.event.handle.apply(this,[a]);return true}}};b.fn.cancel=b.fn.cancel||function(a,c){return b(this).binder("cancel",a,c)};b.event.special.cancel=b.event.special.cancel||{setup:function(){b(this).bind("keyup",b.event.special.cancel.handler)},teardown:function(){b(this).unbind("keyup",b.event.special.cancel.handler)},handler:function(a){b(this);var c=a.keyCode===27;if((typeof a.DOM_VK_ESCAPE==="undefined"?false:a.DOM_VK_ESCAPE)||c){a.type=
"cancel";b.event.handle.apply(this,[a]);return true}}};b.fn.lastclick=b.fn.lastclick||function(a,c){return b(this).binder("lastclick",a,c)};b.event.special.lastclick=b.event.special.lastclick||{setup:function(){b(this).bind("click",b.event.special.lastclick.handler)},teardown:function(){b(this).unbind("click",b.event.special.lastclick.handler)},handler:function(a){var c=function(){var d=b(this),e=d.data("lastclick-timeout")||false;e&&clearTimeout(e);e=false;d.data("lastclick-timeout",e)};(function(d){var e=
this;c.call(e);var f=b(e);f.data("lastclick-clicks",(f.data("lastclick-clicks")||0)+1);var g=setTimeout(function(){var h=f.data("lastclick-clicks");c.apply(e,[d]);f.data("lastclick-clicks",0);d.type="lastclick";b.event.handle.apply(e,[d,h])},500);f.data("lastclick-timeout",g)}).apply(this,[a])}};b.fn.firstclick=b.fn.firstclick||function(a,c){return b(this).binder("firstclick",a,c)};b.event.special.firstclick=b.event.special.firstclick||{setup:function(){b(this).bind("click",b.event.special.firstclick.handler)},
teardown:function(){b(this).unbind("click",b.event.special.firstclick.handler)},handler:function(a){var c=function(){var d=b(this),e=d.data("firstclick-timeout")||false;e&&clearTimeout(e);e=false;d.data("firstclick-timeout",e)};(function(d){var e=this;c.call(e);var f=b(e);f.data("firstclick-clicks",(f.data("firstclick-clicks")||0)+1);if(f.data("firstclick-clicks")===1){d.type="firstclick";b.event.handle.apply(e,[d])}var g=setTimeout(function(){c.apply(e,[d]);f.data("firstclick-clicks",0)},500);f.data("firstclick-timeout",
g)}).apply(this,[a])}};b.fn.singleclick=b.fn.singleclick||function(a,c){return b(this).binder("singleclick",a,c)};b.event.special.singleclick=b.event.special.singleclick||{setup:function(){b(this).bind("click",b.event.special.singleclick.handler)},teardown:function(){b(this).unbind("click",b.event.special.singleclick.handler)},handler:function(a){var c=function(){var d=b(this),e=d.data("singleclick-timeout")||false;e&&clearTimeout(e);e=false;d.data("singleclick-timeout",e)};(function(d){var e=this;
c.call(e);var f=b(e);f.data("singleclick-clicks",(f.data("singleclick-clicks")||0)+1);var g=setTimeout(function(){var h=f.data("singleclick-clicks");c.apply(e,[d]);f.data("singleclick-clicks",0);if(h===1){d.type="singleclick";b.event.handle.apply(e,[d])}},500);f.data("singleclick-timeout",g)}).apply(this,[a])}}})(jQuery);
(function(b){b.fn.opacityFix=b.fn.opacityFix||function(){var a=b(this),c=a.css("background-color");if(c&&c!=="rgba(0, 0, 0, 0)")return this;for(var d=a;d.inDOM();){d=d.parent();if((c=d.css("background-color"))&&c!=="rgba(0, 0, 0, 0)"){a.css("background-color",c);break}}return this};b.fn.parentsAndSelf=b.fn.parentsAndSelf||function(a){return b(this).parents(a).andSelf().filter(a)};b.fn.findAndSelf=b.fn.findAndSelf||function(a){return b(this).find(a).andSelf().filter(a)};b.fn.firstInput=b.fn.firstInput||
function(){return b(this).findAndSelf(":input").filter(":first")};b.fn.choose=b.fn.choose||function(a){var c=b(this);if(typeof a==="undefined")a=c.val();else if(c.val()!==a)return this;switch(true){case this.is("option"):c.parents("select:first").choose(a);break;case c.is(":checkbox"):c.attr("checked",true);break;case c.is(":radio"):c.attr("checked",true);break;case c.is("select"):c.val(a);break;default:break}return this};b.fn.unchoose=b.fn.unchoose||function(){var a=b(this);switch(true){case a.is("option"):a.parents(":select:first").unchoose();
break;case a.is(":checkbox"):a.attr("checked",false);break;case a.is(":radio"):a.attr("checked",false);break;case a.is("select"):a.val(a.find("option:first").val());break;default:break}return this};b.fn.wouldSubmit=b.fn.wouldSubmit||function(){var a=b(this).findAndSelf(":input"),c=true;if(!a.length||!(a.attr("name")||0)||a.is(":radio,:checkbox")&&!a.is(":selected,:checked"))c=false;return c};b.fn.values=b.fn.values||function(){var a={};b(this).findAndSelf(":input").each(function(){var c=b(this),d=
c.attr("name")||null,e=c.val();if(!c.wouldSubmit())return true;if(d.indexOf("[]")!==-1){if(typeof a[d]==="undefined")a[d]=[];a[d].push(e)}else a[d]=e});return a};b.fn.submitForm=b.fn.submitForm||function(){var a=b(this);a.parentsAndSelf("form:first").trigger("submit");return a};b.fn.inDOM=b.fn.inDOM||function(){var a=b(this).parent().parent();return a.size()&&(a.height()||a.width())};b.fn.valWrap=b.fn.valWrap||function(a,c){var d=b(this);return d.val(d.val().wrap(a,c))};b.fn.valWrapSelection=b.fn.valWrapSelection||
function(a,c,d,e){var f=b(this),g=f.get(0);a=a||"";c=c||"";if(d||e)f.val(f.val().wrapSelection(a,c,d,e));else{d=g.selectionStart;e=g.selectionEnd;if(document.selection){g.focus();d=document.selection.createRange();d.text=a+d.text+c}else{var h=g.scrollTop;f.val(f.val().wrapSelection(a,c,d,e));g.focus();g.selectionStart=d+a.length;g.selectionEnd=e+a.length;g.scrollTop=h}}return f};b.fn.giveFocus=b.fn.giveFocus||function(){b(this).findAndSelf(":input:visible:first").focus();return this};b.fn.highlight=
b.fn.highlight||function(a){return b(this).effect("highlight",{},a||3E3)}})(jQuery);
(function(b){b.prepareObject=b.prepareObject||function(a,c){var d={};b.extend(d,a||{});b.intercept(true,d,c);var e=arguments;e[0]=e[1]="$.prepareObject.skipValue";b.each(e,function(f,g){if(g==="$.prepareObject.skipValue")return true;b.intercept(true,d,g)});return d};b.intercept=b.intercept||function(){var a=arguments,c,d=false,e=false;if(typeof a[0]==="boolean"){d=a[0];a[0]="$.intercept.skipValue";if(typeof a[1]==="boolean"){e=a[1];a[1]="$.intercept.skipValue";if(e)c={};else{c=a[2];a[2]="$.intercept.skipValue"}}else{c=
a[1];a[1]="$.intercept.skipValue"}}else{c=a[0];a[0]="$.intercept.skipValue"}var f={};b.each(c,function(g){f[g]=true});d?b.each(a,function(g,h){if(h==="$.intercept.skipValue")return true;b.each(h,function(j,i){if(typeof f[j]==="undefined")return true;if(typeof i==="object"&&!(i.test||0))b.extend(c[j],i||{});else c[j]=i})}):b.each(a,function(g,h){b.each(h,function(j,i){if(typeof f[j]==="undefined")return true;if(typeof i==="object"&&!(i.test||0))b.intercept(true,c[j],i);else c[j]=i})});return c}})(jQuery);
(function(b){function a(d){return typeof d=="object"?d:{top:d,left:d}}var c=b.scrollTo=function(d,e,f){b(window).scrollTo(d,e,f)};c.defaults={axis:"xy",duration:parseFloat(b.fn.jquery)>=1.3?0:1};c.window=function(){return b(window)._scrollable()};b.fn._scrollable=function(){return this.map(function(){if(!(!this.nodeName||b.inArray(this.nodeName.toLowerCase(),["iframe","#document","html","body"])!=-1))return this;var d=(this.contentWindow||this).document||this.ownerDocument||this;return b.browser.safari||
d.compatMode=="BackCompat"?d.body:d.documentElement})};b.fn.scrollTo=function(d,e,f){if(typeof e=="object"){f=e;e=0}if(typeof f=="function")f={onAfter:f};if(d=="max")d=9E9;f=b.extend({},c.defaults,f);e=e||f.speed||f.duration;f.queue=f.queue&&f.axis.length>1;if(f.queue)e/=2;f.offset=a(f.offset);f.over=a(f.over);return this._scrollable().each(function(){function g(l){j.animate(k,e,f.easing,l&&function(){l.call(this,d,f)})}var h=this,j=b(h),i=d,n,k={},m=j.is("html,body");switch(typeof i){case "number":case "string":if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(i)){i=
a(i);break}i=b(i,this);case "object":if(i.is||i.style)n=(i=b(i)).offset()}b.each(f.axis.split(""),function(l,r){var o=r=="x"?"Left":"Top",p=o.toLowerCase(),q="scroll"+o,s=h[q],t=c.max(h,r);if(n){k[q]=n[p]+(m?0:s-j.offset()[p]);if(f.margin){k[q]-=parseInt(i.css("margin"+o))||0;k[q]-=parseInt(i.css("border"+o+"Width"))||0}k[q]+=f.offset[p]||0;if(f.over[p])k[q]+=i[r=="x"?"width":"height"]()*f.over[p]}else{o=i[p];k[q]=o.slice&&o.slice(-1)=="%"?parseFloat(o)/100*t:o}if(/^\d+$/.test(k[q]))k[q]=k[q]<=0?
0:Math.min(k[q],t);if(!l&&f.queue){s!=k[q]&&g(f.onAfterFirst);delete k[q]}});g(f.onAfter)}).end()};c.max=function(d,e){var f=e=="x"?"Width":"Height",g="scroll"+f;if(!b(d).is("html,body"))return d[g]-b(d)[f.toLowerCase()]();f="client"+f;var h=d.ownerDocument.documentElement,j=d.ownerDocument.body;return Math.max(h[g],j[g])-Math.min(h[f],j[f])};b.fn.ScrollTo=function(){for(var d=b(this),e=d.parent(),f=false;e.length===1&&!e.is("body");){var g=e.get(0);if(e.css("overflow")!=="visible"&&g.scrollHeight!==
g.clientHeight){f=true;break}e=e.parent()}if(f){e.scrollTo(d);e.ScrollTo()}else b.scrollTo(d);return d}})(jQuery);
(function(b){if(b.History)window.console.warn("$.History has already been defined...");else{b.History={options:{debug:false},state:"",$window:null,$iframe:null,handlers:{generic:[],specific:{}},extractHash:function(a){return a.replace(/^[^#]*#/,"").replace(/^#+|#+$/,"")},extractState:function(a){return a.replace(/#.*$/,"").replace(/^#+|#+$/,"")},extractAnchor:function(a){return a.replace(/^.*#/,"").replace(/^#+|#+$/,"")},getState:function(){return b.History.state},setState:function(a){var c=b.History;
a=c.extractHash(a);c.state=a;return c.state},getHash:function(){return b.History.extractHash(window.location.hash||location.hash)},setHash:function(a){a=b.History.extractHash(a);if(typeof window.location.hash!=="undefined"){if(window.location.hash!==a)window.location.hash=a}else if(location.hash!==a)location.hash=a;return a},go:function(a){var c=b.History;a=c.extractHash(a);var d=c.getHash(),e=c.getState();if(a!==d)c.setHash(a);else{a!==e&&c.setState(a);c.trigger()}return true},hashchange:function(){var a=
b.History,c=a.getHash();a.go(c);return true},bind:function(a,c){var d=b.History;if(c){if(typeof d.handlers.specific[a]==="undefined")d.handlers.specific[a]=[];d.handlers.specific[a].push(c)}else{c=a;d.handlers.generic.push(c)}return true},trigger:function(a){var c=b.History;if(typeof a==="undefined")a=c.getState();var d,e,f,g;if(typeof c.handlers.specific[a]!=="undefined"){g=c.handlers.specific[a];d=0;for(e=g.length;d<e;++d){f=g[d];f(a)}}g=c.handlers.generic;d=0;for(e=g.length;d<e;++d){f=g[d];f(a)}return true},
construct:function(){var a=b.History;b(document).ready(function(){a.domReady()});return true},configure:function(a){var c=b.History;c.options=b.extend(c.options,a);return true},domReadied:false,domReady:function(){var a=b.History;if(!a.domRedied){a.domRedied=true;a.$window=b(window);a.$window.bind("hashchange",this.hashchange);setTimeout(a.hashchangeLoader,200);return true}},hashchangeLoader:function(){var a=b.History;if(b.browser.msie&&parseInt(b.browser.version)>=8)a.getHash()&&a.$window.trigger("hashchange");
else{var c;if(b.browser.msie){a.$iframe=b('<iframe id="jquery-history-iframe" style="display: none;"></$iframe>').prependTo(document.body)[0];a.$iframe.contentWindow.document.open();a.$iframe.contentWindow.document.close();var d=false;c=function(){var e=a.getHash(),f=a.getState(),g=a.extractHash(a.$iframe.contentWindow.document.location.hash);if(f!==e){if(!d){a.$iframe.contentWindow.document.open();a.$iframe.contentWindow.document.close();a.$iframe.contentWindow.document.location.hash=e}d=false;a.$window.trigger("hashchange")}else if(f!==
g){d=true;a.setHash(g)}}}else c=function(){var e=a.getHash();a.getState()!==e&&a.$window.trigger("hashchange")};setInterval(c,200)}return true}};b.History.construct()}})(jQuery);
(function(b){b(document.body).addClass("js");if(b.Ajaxy)window.console.warn("$.Ajaxy has already been defined...");else{b.Ajaxy={options:{root_url:"",base_url:"",relative_url:"",no_log_class:"ajaxy-no_log",redirect:false,relative_as_base:true,support_text:true,analytics:true,auto_ajaxify:true,auto_ajaxify_documentReady:true,auto_sparkle_documentReady:true,add_sparkle_extension:true,debug:true,Controllers:{}},defaults:{Controller:{selector:null,matches:null,controller:null,response:null,request:null,
error:null},Action:{propagate:true,action:null,state:null,State:null,controller:null,Controller:null,forward:function(){window.console.error("Ajaxy.Action.forward: Forward never defined.",[this,arguments]);window.console.trace()},trigger:function(){window.console.error("Ajaxy.Action.trigger: Trigger never defined.",[this,arguments]);window.console.trace()},stopPropagation:function(){this.propagate=false},preventDefault:function(){this.propagate=false},documentReady:function(a){var c=b.Ajaxy,d=this.State||
{},e=c.options.auto_ajaxify_documentReady;if((a||{}).length)a=b("body");if(c.options.auto_sparkle_documentReady&&b.Sparkle){if(c.options.add_sparkle_extension)e=false;a.sparkle()}e&&a.ajaxify();if(a=d.anchor||false){d.anchor=false;b(".target").removeClass("target");b("#"+a).addClass("target").ScrollTo()}return true}},State:{log:null,form:false,anchor:null,state:null,controller:null,Request:{url:null,data:{}},Response:{callback:null,data:{}},Error:{callback:null,data:{}},User:{data:{}}}},constructed:false,
Controllers:{},States:{},ajaxQueue:[],data:{},redirected:false,extractRelativeUrl:function(a){var c=b.Ajaxy;return a.stripLeft(c.options.root_url).stripLeft(c.options.base_url)},extractAnchor:function(a){var c=b.Ajaxy,d=b.History,e=c.extractRelativeUrl(a);return e=d.extractAnchor(e)||c.extractAnchorFromQueryString(a)},extractAnchorFromQueryString:function(a){if((a=a.match(/anchor=([a-zA-Z0-9-_]+)/)||"")&&a.length||false===2)a=a[1]||"";return a},extractState:function(a){var c=b.History;a=b.Ajaxy.extractRelativeUrl(a);
if(a=c.extractState(a))a="/"+a.replace(/^\/+/,"");return a},bind:function(a,c){var d=b.Ajaxy;if(typeof c==="undefined"&&typeof a==="object"){b.each(a,d.bind);return true}else if(typeof c==="function")c={response:c};else if(typeof c!=="object"){window.console.error("Ajaxy.bind: Unknown option type",[this,arguments]);window.console.trace();return false}if(typeof d.getController(a,false)==="undefined")d.storeController(b.prepareObject(d.defaults.Controller,{controller:a},c));else{window.console.error("Ajaxy.bind: Controller already bound.",
[this,arguments]);window.console.trace();return false}if(d.options.auto_ajaxify){d.ajaxifyController(a);return true}return true},trigger:function(a,c,d){var e=b.Ajaxy;e.options.debug&&window.console.debug("Ajaxy.trigger: ",[this,arguments]);var f=true;if(!a){window.console.warn("Ajaxy.trigger: No controller was passed, reset to _generic.",[this,arguments]);a="_generic"}var g=e.getController(a),h=e.getControllerAction(a,c,false),j=e.getState(d,true);d=j.state||undefined;if(typeof g==="undefined"){window.console.error("Ajaxy.trigger: Controller does not exist",
[this,arguments]);window.console.trace();a!=="_generic"&&e.trigger("_generic","error",j);return false}if(typeof h==="undefined"){window.console.error("Ajaxy.trigger: No Controller Action",[this,arguments]);window.console.trace();a!=="_generic"&&e.trigger("_generic","error",j);return false}g=b.extend(true,{},e.defaults.Action,{action:c,controller:a,Controller:g,state:d,State:j});g.forward=g.trigger=function(i,n,k){e.options.debug&&window.console.debug("Ajaxy.Action.trigger:",[this,arguments]);i=i||
a;n=n||c;k=k||d;e.trigger(i,n,k);return true};h.apply(g,[]);if(g.propagate===false)f=false;f&&a!=="_generic"&&g.forward("_generic");return true},get:function(a){var c=b.Ajaxy;if(typeof c.data[a]!=="undefined")return c.data[a]},set:function(a,c){var d=b.Ajaxy;if(typeof c==="undefined")typeof a==="object"&&d.data.extend(true,a);else d.data[a]=c},refresh:function(){return b.Ajaxy.go(b.History.getHash())},go:function(a){var c=b.Ajaxy,d=b.History;c.options.debug&&window.console.debug("Ajaxy.go:",[this,
arguments]);if(typeof a==="string")a={state:a};var e=c.getState(false,true);b.extend(true,e,a);if(e.state)if(e.form){if(e.log===null||e.log===undefined)e.log=false}else{if(e.log===null||e.log===undefined)e.log=true}else{e.state=c.extractState(e.url);delete e.url;if(e.log===null||e.log===undefined)e.log=false}e.log=e.log?true:false;if(e.state)e.state=c.extractState(e.state);else{window.console.error("Ajaxy.go: No state",[this,arguments]);return false}if(e.anchor){var f=e.state.queryStringToJSON();
f.anchor=e.anchor;f=b.param(f);e.state=e.state.replace(/\?.*/,"")+"?"+f}e.state===d.getHash()&&c.options.debug&&c.options.debug&&window.console.debug("Ajaxy.go: Trigger but no change.",e.state);c.storeState(e);e.log?d.go(e.state):c.stateChange(e.state);return true},getControllerAction:function(a,c,d){var e=undefined,f=b.Ajaxy.getController(a,false);if(typeof f==="undefined"){if(d!==false){window.console.error("Ajaxy.getControllerAction: Controller does not exist",[this,arguments]);window.console.trace()}}else{var g=
typeof(f[c]||undefined);if(g==="function"||g==="object")e=f[c];else if(d!==false){window.console.error("Ajaxy.getControllerAction: Controller Action does not exist",[this,arguments]);window.console.trace()}}return e},storeController:function(a){var c=b.Ajaxy,d=true;if(typeof(a||undefined)==="object"&&typeof a.controller==="string")d=c.Controllers[a.controller]=a;else{window.console.error("Ajaxy.getController: Unkown Controller Format",[this,arguments]);window.console.trace();d=false}return d},getController:function(a,
c){var d=b.Ajaxy,e=undefined,f=typeof(a||undefined);if((f==="number"||f==="string")&&typeof d.Controllers[a]!=="undefined")e=d.Controllers[a];else if(f==="object"&&typeof a.controller==="string")e=d.getController(a.controller,c);else if(c)e=b.extend(true,{},d.defaults.Controller);else if(c!==false){window.console.error("Ajaxy.getController: Controller does not exist",[this,arguments]);window.console.trace()}return e},storeState:function(a){var c=b.Ajaxy,d=true;if(typeof(a||undefined)==="object"&&
typeof a.state==="string")d=c.States[a.state]=a;else{window.console.error("Ajaxy.getState: Unkown State Format",[this,arguments]);window.console.trace();d=false}return d},getState:function(a,c){var d=b.Ajaxy,e=undefined,f=typeof(a||undefined);if((f==="number"||f==="string")&&typeof d.States[a]!=="undefined")e=d.States[a];else if(f==="object"&&typeof a.state==="string")e=d.getState(a.state,c);else if(c)e=b.extend(true,{},d.defaults.State);else if(c!==false){window.console.error("Ajaxy.getState: State does not exist",
[this,arguments]);window.console.trace()}return e},track:function(a){var c=b.Ajaxy;if(typeof pageTracker!=="undefined"){var d=c.options.base_url+(a||"?");c.options.debug&&window.console.debug("Ajaxy.track",[this,arguments],[d]);pageTracker._trackPageview(d)}return true},matches:function(a,c){var d=b.Ajaxy,e=false;switch(typeof a){case "function":case "object":if(a.test){e=a.test(c);break}case "array":b.each(a,function(f,g){if(e=d.matches(g,c))return false});break;case "number":case "string":e=String(a)===
c;break}return e},match:function(a){var c=b.Ajaxy,d=false;b.each(c.Controllers,function(e,f){if(c.matches(f.matches||false,a)){d=e;return false}});return d},request:function(a){var c=b.Ajaxy,d=b.History;c.options.debug&&window.console.debug("Ajaxy.request:",[this,arguments]);var e=false;a=c.extractState(a);if(c.redirected!==false)c.redirected=false;else{c.ajaxQueue.push(a);if(c.ajaxQueue.length!==1)return false;c.options.analytics&&c.track(a);var f=c.getState(a,true),g=f.controller||c.match(a)||undefined,
h=f.anchor||c.extractAnchorFromQueryString(a);f.state=a;f.controller=g;f.anchor=h;f.Request.url=f.Request.url||c.options.root_url+c.options.base_url+(a||"?");c.storeState(f);c.trigger(g,"request");g={data:f.Request.data,url:f.Request.url,type:"post",success:function(m){c.options.debug&&window.console.debug("Ajaxy.request.success:",[this,arguments]);m=b.extend(true,{},c.defaults.State.Response.data,m);m.Ajaxy=m.Ajaxy||{};if(m.Ajaxy.redirected){var l=c.extractState(m.Ajaxy.redirected.to);c.redirected=
{status:true,from:a,to:l};d.go(l)}c.ajaxQueue.shift();if((l=c.ajaxQueue.pop())&&l!==a){c.ajaxQueue=[];c.stateChange(l);return false}f.Response.data=m;f.Error.data={};l=m.controller||f.controller||null;if(l===null){l="_generic";window.console.warn("Ajaxy.request.success.controller: The controller was unable to be determined, defaulted to _generic.",[this,arguments],[m.controller,f.controller])}if(f.Response.callback)if(f.Response.callback.apply(f,arguments)||l==="callback")return true;return c.trigger(l,
"response",f)},error:function(m,l,r,o){c.options.debug&&window.console.debug("Ajaxy.request.error:",[this,arguments]);o||(o={responseText:m.responseText.trim()||false});c.ajaxQueue.shift();var p=c.ajaxQueue.pop();if(p&&p!==a){c.ajaxQueue=[];c.stateChange(p);return false}f.Request.XMLHttpRequest=m;f.Response.data=o;f.Error.data={};p=o.controller||f.controller||null;if(p===null){p="_generic";window.console.warn("Ajaxy.request.error.controller: The controller was unable to be determined, defaulted to _generic.",
[this,arguments],[o.controller,f.controller])}if(f.Error.callback)if(f.Error.callback.apply(f,arguments)||p==="callback")return true;return c.trigger(p,"error",f)},complete:function(m){c.options.debug&&window.console.debug("Ajaxy.request.complete:",[this,arguments]);f.Request.XMLHttpRequest=m}};if(f.form){var j=b(f.form);if(j.attr("enctype")==="multipart/form-data"){e="ajaxy_form_iframe_"+Math.floor(Math.random()*99999);var i=b('<iframe style="display:none" src="about:blank" id="'+e+'" name="'+e+
'" >').appendTo("body").hide(),n=b('<input type="hidden" name="ajax" value="true"/>').appendTo(j),k=b('<input type="hidden" name="Ajaxy[form]" value="true"/>').appendTo(j);i.bind("load",function(){if((this.document||this.currentDocument||this.contentWindow.document).location.href==="about:blank")return true;var m=i.contents().find(".response").val(),l=false;try{l=b.parseJSON(m)}catch(r){window.console.error("Ajaxy.request.form: Invalid Response.",[this,arguments],[m])}l?request.success(l):request.error(l);
j.removeAttr("target");i.remove();n.remove();k.remove()});j.attr("target",e);j.submit();h=j.values();g.data=b.extend(true,g.data,h||{});e=true}else{h=j.values();g.data=b.extend(true,g.data,h||{})}}h=true;f.Request=g;e||(h=c.ajax(g));return h}},ajax:function(a){var c=b.Ajaxy;c.options.debug&&window.console.debug("Ajaxy.ajax:",[this,arguments]);var d={};d.success=a.success||function(){c.options.debug&&window.console.debug("Ajaxy.ajax.callbacks.success:",[this,arguments]);b(".error").empty()};d.error=
a.error||function(f,g,h){c.options.debug&&window.console.debug("Ajaxy.ajax.callbacks.error:",[this,arguments]);b(".error").html(h)};d.complete=a.complete||function(){c.options.debug&&window.console.debug("Ajaxy.ajax.callbacks.complete:",[this,arguments])};delete a.success;delete a.error;delete a.complete;var e={type:"post",dataType:c.options.support_text?"text":"json"};b.extend(true,e,a);e.success=function(f,g){c.options.debug&&window.console.debug("Ajaxy.ajax.request.success:",[this,arguments]);
var h={};if(typeof f!=="object"&&c.options.support_text&&f)try{h=b.parseJSON(f)}catch(j){var i=b(f.replace(/<(html|head|body|title)>/g,'<div id="ajaxy-$1">').replace(/<\/(html|head|body|title)/g,"</div>"));h=i.find("#ajaxy-body");var n=i.find("#ajaxy-title");i=i.find("#ajaxy-controller");n=n.length?n.text():null;h=h.length?h.html():f;i=i.length?i.text():null;h={title:n,content:h,controller:i,html:f}}else h=f;c.options.debug&&window.console.debug("Ajaxy.ajax.success:",[this,arguments]);if(typeof h.controller===
"undefined"&&(typeof h.success!=="undefined"&&!h.success||typeof h.error!=="undefined"&&h.error))return d.error.apply(this,[null,g,h.error||true,h]);return d.success.apply(this,[h,g])};e.error=function(f,g,h){c.options.debug&&window.console.debug("Ajaxy.ajax.request.error:",[this,arguments]);var j=f.responseText||false;if(j)j=j.trim();j||(j=false);var i={error:h||true,responseText:j};if(j)try{i=b.parseJSON(j)}catch(n){}finally{return this.success.apply(this,[i,g])}return d.error.apply(this,[f,g,h,
i])};return b.ajax(e)},stateChange:function(a){b.Ajaxy.request(a)},configure:function(a){var c=b.Ajaxy,d=b.History;a=a||{};var e=a.Controllers||a.controllers||a;c.options=b.extend(true,c.options,a.options||a||{});c.bind(e);c.options.root_url=(c.options.root_url||document.location.protocol.toString()+"//"+document.location.hostname.toString()).replace(/\/+$/,"")+"/";c.options.base_url=c.options.base_url||"";c.options.relative_url=c.extractState(c.options.relative_url||document.location.pathname.toString());
if(c.options.relative_as_base)if(c.options.base_url.length===0){c.options.base_url=c.options.relative_url;c.options.relative_url=""}c.options.root_url=c.options.root_url.replace(/\/+$/,"");c.options.base_url=c.options.base_url.replace(/\/+$/,"");c.options.relative_url=c.extractRelativeUrl(c.options.relative_url);c.options.debug&&window.console.debug("Ajaxy.configure:",[this,arguments]);if(c.options.redirect&&c.options.relative_url&&c.options.relative_url!==null){c=c.options.root_url+c.options.base_url+
"#"+c.options.relative_url;if(d=d.getHash())c+="?anchor="+d;document.location=c}return true},construct:function(){var a=b.Ajaxy,c=b.History;if(!a.constructed){a.constructed=true;c.bind(function(d){return a.stateChange(d)});b.fn.ajaxify=a.ajaxify;b.fn.ajaxy=a.ajaxify;b(function(){a.domReady();c.domReady()});return true}},domReady:function(){b.Sparkle&&b.Sparkle.addExtension("ajaxy",function(){b(this).ajaxify()});return true},ajaxify:function(){var a=b.Ajaxy,c=b(this);b.each(a.Controllers,function(d){a.ajaxifyController(d)});
c.findAndSelf("a.ajaxy").once("click",a.ajaxify_helpers.a);c.findAndSelf("form.ajaxy").once("submit",a.ajaxify_helpers.form);return c},ajaxifyController:function(a){var c=b.Ajaxy,d=c.getController(a);d&&typeof d.selector!=="undefined"&&b(function(){b(d.selector).data("ajaxy-controller",a).once("click",c.ajaxify_helpers.a)});return true},ajaxify_helpers:{a:function(a){var c=b.Ajaxy,d=b(this),e=c.extractRelativeUrl(d.attr("href")).replace(/^\/?\.\//,"/"),f=c.extractAnchor(e);e=c.extractState(e);if("/"+
f===e||f===e)f="";var g=!d.hasClass(c.options.no_log_class);d=d.data("ajaxy-controller")||null;c.go({state:e,controller:d,log:g,anchor:f});a.stopPropagation();a.preventDefault();return false},form:function(a){var c=b.Ajaxy,d=b(this),e=d.attr("disabled");if(e=e||e==="false")return false;if(d.attr("target"))return true;d=c.extractState(d.attr("action"));c.go({state:d,form:this});a.stopPropagation();a.preventDefault();return false}}};b.Ajaxy.construct()}})(jQuery);

