/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.3.0
build: 3167
*/
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=H.location,N=A.config.useHistoryHTML5;function G(){G.superclass.constructor.apply(this,arguments);}A.extend(G,C,{_init:function(O){var P=G.parseHash();O=O||{};this._initialState=O.initialState?A.merge(O.initialState,P):P;A.after("hashchange",A.bind(this._afterHashChange,this),H);G.superclass._init.apply(this,arguments);},_change:function(Q,P,O){J.each(P,function(S,R){if(F.isValue(S)){P[R]=S.toString();}});return G.superclass._change.call(this,Q,P,O);},_storeState:function(R,Q){var P=G.decode,O=G.createHash(Q);G.superclass._storeState.apply(this,arguments);if(R!==B&&P(G.getHash())!==P(O)){G[R===C.SRC_REPLACE?"replaceHash":"setHash"](O);}},_afterHashChange:function(O){this._resolveChanges(B,G.parseHash(O.newHash),{});}},{NAME:"historyHash",SRC_HASH:B,hashPrefix:"",_REGEX_HASH:/([^\?#&]+)=([^&]+)/g,createHash:function(Q){var O=G.encode,P=[];J.each(Q,function(S,R){if(F.isValue(S)){P.push(O(R)+"="+O(S));}});return P.join("&");},decode:function(O){return decodeURIComponent(O.replace(/\+/g," "));},encode:function(O){return encodeURIComponent(O).replace(/%20/g,"+");},getHash:(A.UA.gecko?function(){var P=/#(.*)$/.exec(M.href),Q=P&&P[1]||"",O=G.hashPrefix;return O&&Q.indexOf(O)===0?Q.replace(O,""):Q;}:function(){var P=M.hash.substr(1),O=G.hashPrefix;return O&&P.indexOf(O)===0?P.replace(O,""):P;}),getUrl:function(){return M.href;},parseHash:function(R){var O=G.decode,S,V,T,P,Q={},U=G.hashPrefix,W;R=F.isValue(R)?R:G.getHash();if(U){W=R.indexOf(U);if(W===0||(W===1&&R.charAt(0)==="#")){R=R.replace(U,"");}}T=R.match(G._REGEX_HASH)||[];for(S=0,V=T.length;S<V;++S){P=T[S].split("=");Q[O(P[0])]=O(P[1]);}return Q;},replaceHash:function(O){if(O.charAt(0)==="#"){O=O.substr(1);}M.replace("#"+(G.hashPrefix||"")+O);},setHash:function(O){if(O.charAt(0)==="#"){O=O.substr(1);}M.hash=(G.hashPrefix||"")+O;}});E=K._notifiers;if(!E){E=K._notifiers=[];}A.Event.define("hashchange",{on:function(Q,O,P){if(Q.compareTo(H)||Q.compareTo(A.config.doc.body)){E.push(P);}},detach:function(R,P,Q){var O=L.indexOf(E,Q);if(O!==-1){E.splice(O,1);}}});D=G.getHash();I=G.getUrl();if(C.nativeHashChange){A.Event.attach("hashchange",function(Q){var O=G.getHash(),P=G.getUrl();L.each(E.concat(),function(R){R.fire({_event:Q,oldHash:D,oldUrl:I,newHash:O,newUrl:P});});D=O;I=P;},H);}else{if(!K._hashPoll){if(A.UA.webkit&&!A.UA.chrome&&navigator.vendor.indexOf("Apple")!==-1){A.on("unload",function(){},H);}K._hashPoll=A.later(50,null,function(){var O=G.getHash(),P;if(D!==O){P=G.getUrl();L.each(E.concat(),function(Q){Q.fire({oldHash:D,oldUrl:I,newHash:O,newUrl:P});});D=O;I=P;}},null,true);}}A.HistoryHash=G;if(N===false||(!A.History&&N!==true&&(!C.html5||!A.HistoryHTML5))){A.History=G;}},"3.3.0",{requires:["event-synthetic","history-base","yui-later"]});