/*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("history-hash",function(a){var c=a.HistoryBase,f=a.Lang,l=a.Array,j=a.Object,k=YUI.namespace("Env.HistoryHash"),b="hash",e,d,i,h=a.config.win,m=a.config.useHistoryHTML5;function g(){g.superclass.constructor.apply(this,arguments);}a.extend(g,c,{_init:function(n){var o=g.parseHash();n=n||{};this._initialState=n.initialState?a.merge(n.initialState,o):o;a.after("hashchange",a.bind(this._afterHashChange,this),h);g.superclass._init.apply(this,arguments);},_change:function(p,o,n){j.each(o,function(r,q){if(f.isValue(r)){o[q]=r.toString();}});return g.superclass._change.call(this,p,o,n);},_storeState:function(q,p){var o=g.decode,n=g.createHash(p);g.superclass._storeState.apply(this,arguments);if(q!==b&&o(g.getHash())!==o(n)){g[q===c.SRC_REPLACE?"replaceHash":"setHash"](n);}},_afterHashChange:function(n){this._resolveChanges(b,g.parseHash(n.newHash),{});}},{NAME:"historyHash",SRC_HASH:b,hashPrefix:"",_REGEX_HASH:/([^\?#&]+)=([^&]+)/g,createHash:function(p){var n=g.encode,o=[];j.each(p,function(r,q){if(f.isValue(r)){o.push(n(q)+"="+n(r));}});return o.join("&");},decode:function(n){return decodeURIComponent(n.replace(/\+/g," "));},encode:function(n){return encodeURIComponent(n).replace(/%20/g,"+");},getHash:(a.UA.gecko?function(){var n=a.getLocation(),p=/#(.*)$/.exec(n.href),q=p&&p[1]||"",o=g.hashPrefix;return o&&q.indexOf(o)===0?q.replace(o,""):q;}:function(){var n=a.getLocation(),p=n.hash.substring(1),o=g.hashPrefix;return o&&p.indexOf(o)===0?p.replace(o,""):p;}),getUrl:function(){return location.href;},parseHash:function(q){var n=g.decode,r,u,s,o,p={},t=g.hashPrefix,v;q=f.isValue(q)?q:g.getHash();if(t){v=q.indexOf(t);if(v===0||(v===1&&q.charAt(0)==="#")){q=q.replace(t,"");}}s=q.match(g._REGEX_HASH)||[];for(r=0,u=s.length;r<u;++r){o=s[r].split("=");p[n(o[0])]=n(o[1]);}return p;},replaceHash:function(p){var n=a.getLocation(),o=n.href.replace(/#.*$/,"");if(p.charAt(0)==="#"){p=p.substring(1);}n.replace(o+"#"+(g.hashPrefix||"")+p);},setHash:function(o){var n=a.getLocation();if(o.charAt(0)==="#"){o=o.substring(1);}n.hash=(g.hashPrefix||"")+o;}});e=k._notifiers;if(!e){e=k._notifiers=[];}a.Event.define("hashchange",{on:function(p,n,o){if(p.compareTo(h)||p.compareTo(a.config.doc.body)){e.push(o);}},detach:function(q,o,p){var n=l.indexOf(e,p);if(n!==-1){e.splice(n,1);}}});d=g.getHash();i=g.getUrl();if(c.nativeHashChange){a.Event.attach("hashchange",function(p){var n=g.getHash(),o=g.getUrl();l.each(e.concat(),function(q){q.fire({_event:p,oldHash:d,oldUrl:i,newHash:n,newUrl:o});});d=n;i=o;},h);}else{if(!k._hashPoll){k._hashPoll=a.later(50,null,function(){var o=g.getHash(),n,p;if(d!==o){p=g.getUrl();n={oldHash:d,oldUrl:i,newHash:o,newUrl:p};d=o;i=p;l.each(e.concat(),function(q){q.fire(n);});}},null,true);}}a.HistoryHash=g;if(m===false||(!a.History&&m!==true&&(!c.html5||!a.HistoryHTML5))){a.History=g;}},"3.5.1",{requires:["event-synthetic","history-base","yui-later"]});