/*
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 3.0.0b1
build: 1163
*/
YUI.add("history",function(D){var I=D.Lang,V=D.UA,X=D.Event.Target,S=D.config,B=S.win.history,c=S.win.location,R=S.doc.documentMode,E=encodeURIComponent,T=decodeURIComponent,M,N,Z="Missing or invalid argument",P=/([^=&]+)=([^&]*)/g,O="history:ready",W="history:globalStateChange",J="history:moduleStateChange";if(!YUI.Env.history){YUI.Env.history=N={ready:false,_modules:[],_fqstates:[],_stateField:null,_historyIFrame:null};}function Q(){return c.hash.substr(1);}function a(){var G=[],A=[],C;D.Object.each(N._modules,function(H,L){G.push(L+"="+H.initialState);A.push(L+"="+H.currentState);});C=G.join("&")+"|"+A.join("&");if(V.webkit){C+="|"+N._fqstates.join(",");}N._stateField.set("value",C);}function U(H){var A,G,C=false;if(!H){D.Object.each(N._modules,function(L,Y){if(L.currentState!==L.initialState){L.currentState=L.initialState;L.fire(J,L.currentState);C=true;}});if(C){M.fire(W);}return;}G=[];P.lastIndex=0;while((A=P.exec(H))){G[A[1]]=A[2];}D.Object.each(N._modules,function(L,d){var Y=G[d];if(!Y||L.currentState!==Y){L.currentState=Y||L.initialState;L.fire(J,L.currentState);C=true;}});if(C){M.fire(W);}}function K(H){var A,G;A="<html><body>"+H+"</body></html>";try{G=N._historyIFrame.get("contentWindow.document");G.invoke("open");G.invoke("write",A,"","","","");G.invoke("close");return true;}catch(C){return false;}}function F(){var A,G,C;if(!N._historyIFrame.get("contentWindow.document")){setTimeout(F,10);return;}A=N._historyIFrame.get("contentWindow.document.body");G=A?A.get("innerText"):null;C=Q();setInterval(function(){var Y,H,L;A=N._historyIFrame.get("contentWindow.document.body");Y=A?A.get("innerText"):null;L=Q();if(Y!==G){G=Y;U(G);if(!G){H=[];D.Object.each(N._modules,function(d,e){H.push(e+"="+d.initialState);});L=H.join("&");}else{L=G;}c.hash=C=L;a();}else{if(L!==C){C=L;K(L);}}},50);N.ready=true;M.fire(O);}function b(){var C,e,Y,H,A,L,G,d;e=N._stateField.get("value").split("|");if(e.length>1){P.lastIndex=0;while((C=P.exec(e[0]))){Y=C[1];A=C[2];H=N._modules[Y];if(H){H.initialState=A;}}P.lastIndex=0;while((C=P.exec(e[1]))){Y=C[1];L=C[2];H=N._modules[Y];if(H){H.currentState=L;}}}if(e.length>2){N._fqstates=e[2].split(",");}if(V.ie){if(I.isUndefined(R)||R<8){F();}else{D.on("hashchange",function(){var f=Q();U(f);a();},window);N.ready=true;M.fire(O);}}else{G=B.length;d=Q();setInterval(function(){var h,f,g;f=Q();g=B.length;if(f!==d){d=f;G=g;U(d);a();}else{if(g!==G&&V.webkit){d=f;G=g;h=N._fqstates[G-1];U(h);a();}}},50);N.ready=true;M.fire(O);}}M={register:function(G,A){var C;if(!I.isString(G)||I.trim(G)===""||!I.isString(A)){throw new Error(Z);}if(N._modules[G]){return;}if(N.ready){return null;}G=E(G);A=E(A);C=new M.Module(G,A);N._modules[G]=C;return C;},initialize:function(A,H){var C,G;if(N.ready){return true;}A=D.get(A);if(!A){throw new Error(Z);}C=A.get("tagName").toUpperCase();G=A.get("type");if(C!=="TEXTAREA"&&(C!=="INPUT"||G!=="hidden"&&G!=="text")){throw new Error(Z);}if(V.ie&&(I.isUndefined(R)||R<8)){H=D.get(H);if(!H||H.get("tagName").toUpperCase()!=="IFRAME"){throw new Error(Z);}}if(V.opera&&!I.isUndefined(B.navigationMode)){B.navigationMode="compatible";}N._stateField=A;N._historyIFrame=H;D.on("domready",b);return true;},navigate:function(C,G){var A;if(!I.isString(C)||!I.isString(G)){throw new Error(Z);}A={};A[C]=G;return M.multiNavigate(A);},multiNavigate:function(C){var G=[],H,A=false;if(!N.ready){return false;}D.Object.each(N._modules,function(Y,d){var e,L=T(d);if(!D.Object.owns(C,L)){e=Y.currentState;}else{e=E(C[L]);if(e!==Y.upcomingState){Y.upcomingState=e;A=true;}}G.push(d+"="+e);});if(!A){return false;}H=G.join("&");if(V.ie&&(I.isUndefined(R)||R<8)){return K(H);}else{c.hash=H;if(V.webkit){N._fqstates[B.length]=H;a();}return true;}},getCurrentState:function(C){var A;if(!I.isString(C)){throw new Error(Z);}if(!N.ready){return null;}A=N._modules[C];if(!A){return null;}return T(A.currentState);},getBookmarkedState:function(H){var A,C,G;if(!I.isString(H)){throw new Error(Z);}G=c.href;C=G.indexOf("#");if(C>=0){G=G.substr(C+1);P.lastIndex=0;while((A=P.exec(G))){if(A[1]===H){return T(A[2]);}}}return null;},getQueryStringParameter:function(L,C){var A,H,G;C=C||c.href;G=C.indexOf("?");H=G>=0?C.substr(G+1):C;G=H.lastIndexOf("#");H=G>=0?H.substr(0,G):H;P.lastIndex=0;while((A=P.exec(H))){if(A[1]===L){return T(A[2]);}}return null;}};D.mix(M,X.prototype);X.call(M);M.Module=function(C,A){X.call(this);this.id=C;this.initialState=A;this.currentState=A;this.upcomingState=A;};D.mix(M.Module,X,false,null,1);D.History=M;},"3.0.0b1",{skinnable:false,use:["event","node"]});