/*
 * dsHistory, v1-beta5 $Rev: 78 $
 * Revision date: $Date: 2008-12-08 14:46:08 -0800 (Mon, 08 Dec 2008) $
 * Project URL: http://code.google.com/p/dshistory/
 * 
 * Copyright (c) Andrew Mattie (http://www.akmattie.net)
 * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
 * THIS IS FREE SOFTWARE, BUT DO NOT REMOVE THIS COMMENT BLOCK
 */
var dsHistory=function(){var e=(function(){var g=window.navigator.userAgent;var f=!!(window.attachEvent&&!window.opera&&g.indexOf("Opera")==-1);return{IE:f,IE6:f&&g.indexOf("MSIE 6")!=-1,IE7:f&&g.indexOf("MSIE 7")!=-1,Opera:!!window.opera&&g.indexOf("Opera")!=-1,WebKit:g.indexOf("AppleWebKit/")>-1,Gecko:g.indexOf("Gecko")>-1&&g.indexOf("KHTML")==-1}})();var R=e.IE||e.Gecko;var I=e.Gecko;var E=e.IE||e.WebKit;var C=15;var Y=0;var X=lastRawHash="";var A=window.encodeURIComponent;var d=initialHash=a(true);var S=[];var F=[];var P=[];var B=[];var c=false;var H;var Q;var K=[];var L;var U,T;var N=false;var O;function V(){window.clearInterval(L);H=null;P=null}function b(h,g,f){if(typeof f!="undefined"){return function(j){h.call(g||window,f,j)}}else{return function(j){h.call(g||window,j)}}}function M(){if(!R){M=function(){return 0}}else{if(I){M=function(){return H.document.body?parseInt(H.document.body.textContent):0}}else{M=function(){return parseInt(H.document.body.innerText)}}}return M()}function G(f){if(I){G=function(g){H.document.body.textContent=String(g)}}else{G=function(g){H.document.body.innerText=String(g)}}G(f)}function Z(g){if(E){var f=window.decodeURIComponent;Z=function(h){return f(h)}}else{Z=function(h){return h}}return Z(g)}function a(l){var k=window.location.hash;if(!l&&k==lastRawHash){return X}lastRawHash=k;var g=k.substring(1).split("&");var j;if(g.length>9){var m=[];for(var h=0,f=g.length;h<f;++h){hashSplit=g[h].split("=");m.push(A(Z(hashSplit[0]))+(hashSplit.length==2?"="+A(Z(hashSplit[1])):""))}j=m.join("&")}else{j="";for(var h=0,f=g.length;h<f;++h){hashSplit=g[h].split("=");j+=(h==0?"":"&")+A(Z(hashSplit[0]))+(hashSplit.length==2?"="+A(Z(hashSplit[1])):"")}}return j}function J(){O.QueryElements={};if(window.location.hash==""||window.location.hash=="#"){return }var f=window.location.hash.substring(1).split("&");var g;for(i=0,len=f.length;i<len;++i){g=f[i].split("=");O.QueryElements[Z(g[0])]=g.length==2?Z(g[1]):""}X=a(true)}function D(h){var g=R?M():0;var f,j;if((S.length>0&&e.Gecko)||e.WebKit||(!R&&M()>0)){if(X==""&&S.length>1){window.location.hash="_";X=a(true);S.push(X)}else{if(X!=""||e.WebKit){f=P.splice(P.length-1,1)[0];window.location.hash=X+String(S.length);S.push(X+String(S.length));window.location.hash=X==""?"-":X;S.push(X==""?"-":X);P.push(function(k){if(N?k:k.direction=="back"){U=true;window.history.back()}else{T=true;window.history.forward()}});P.push(f)}}return }if(g==0&&((S.length==(h?1:0)&&!e.IE)||(S.length==2&&e.IE))&&P.length<=1){G(1)}else{if(I){document.getElementById("dsHistoryFrame").src="data:,"+String(g+1)}else{H.document.open();H.document.write(String(g+1));H.document.close()}}}function W(){var f=R?M():0;var g=a();if(!T&&(f<Y||(X!=g&&S[S.length-2]==g&&!e.IE))){c=true;U=false;if((X!=g&&S[S.length-2]==g)||e.IE){F=F.concat(S.splice(S.length-1,1));if(e.IE){if(O.deferProcessing){window.setTimeout(function(){window.location.hash=S[S.length-1]},10)}else{window.location.hash=S[S.length-1]}}J();d=X}if(P.length>1){P[P.length-2](N?"back":{calledFromHistory:true,direction:"back"});B=B.concat(P.splice(P.length-1,1))}}else{if(c&&!U&&(f>Y||(X!=g&&F[F.length-1]==g&&!e.IE))){T=false;if((X!=g&&F[F.length-1]==g)||e.IE){if(e.IE){window.location.hash=F[F.length-1]}J();d=X;S=S.concat(F.splice(F.length-1,1))}B[B.length-1](N?"forward":{calledFromHistory:true,direction:"forward"});P=P.concat(B.splice(B.length-1,1))}}Y=f}O={QueryElements:{},deferProcessing:false,initialize:function(f){if(typeof f=="function"){f()}},addFunction:function(h,g,f){if(R&&(!H||!H.document||!H.document.body)){K.push({type:arguments.callee,fnc:h,scope:g,objectArg:f});return }c=false;B=[];F=[];if(e.IE){S.push(a())}P.push(b(h,g,f));D()},setQueryVar:function(h,k){var j,g;var f;h=String(h);k=String(typeof k=="undefined"?"":k);j=A(h);g=A(k);if(d=="#"||d==""||d.indexOf("#_serial")==0){if(g!=""){d="#"+j+"="+g}else{d="#"+j}}else{if(typeof this.QueryElements[h]!="undefined"&&k!=""){f=d.search(j+"\\b");d=d.substr(0,d.indexOf(j)+j.length+1)+g+d.substr(d.indexOf(j)+j.length+1+String(A(this.QueryElements[h])).length)}else{if(typeof this.QueryElements[h]=="undefined"){if(k==""){d+="&"+j}else{d+="&"+j+"="+g}}}}this.QueryElements[h]=k;if(S>1&&S[S.length-2]==d){d+="&_serial="+S.length}else{if(d.indexOf("_serial")!=-1){this.removeQueryVar("_serial")}}},removeQueryVar:function(h){if(!this.QueryElements[h]&&h!="_serial"){return }var j,f,g;if(this.QueryElements[h]==""){j=A(h)}else{j=A(h)+"="+A(this.QueryElements[h])}f=d.indexOf(j);if(d[f-1]=="&"){j="&"+j;f--}d=d.substr(0,f)+d.substr(f+j.length);if(d[0]=="&"){d=d.substr(1,d.length-1)}delete this.QueryElements[h];if(d=="#"||d==""){d="_serial="+S.length}},bindQueryVars:function(k,h,f,j){if(R&&(!H||!H.document||!H.document.body)){K.push({type:arguments.callee,fnc:k,scope:h,objectArg:f});return }if(a()==d.replace("#","")&&P.length>0){return false}if(this.deferProcessing&&!j){var g=arguments.callee;window.setTimeout(function(){g(k,h,f,true)},10);return }c=false;B=[];F=[];if(S.length==0&&P.length>0&&!e.IE){S.push(a())}window.location.hash=d;X=a(true);S.push(X);P.push(b(k,h,f));if(e.IE){D(true)}J()},setFirstEvent:function(h,g,f){if(P.length>0){P[0]=b(h,g,f)}},setUsingStringIndicators:function(){N=true}};if(R){if(I){document.write('<iframe id="dsHistoryFrame" name="dsHistoryFrame" style="display:none" src="data:,0"></iframe>')}else{document.write('<iframe id="dsHistoryFrame" name="dsHistoryFrame" style="display:none" src="javascript:document.open();document.write(\'0\');document.close();"></iframe>')}H=window.frames.dsHistoryFrame;if(!H||!H.document||!H.document.body){Q=window.setInterval(function(){H=window.frames.dsHistoryFrame;if(H&&H.document&&H.document.body){window.clearInterval(Q);L=window.setInterval(W,C);for(i=0,len=K.length;i<len;++i){var f=K[i];f.type(f.fnc,f.scope,f.objectArg)}K=null}},50)}else{L=window.setInterval(W,C)}}else{L=window.setInterval(W,C)}if(e.IE||e.WebKit){S.push(initialHash)}J();if(window.addEventListener){window.addEventListener("unload",V,false)}else{if(window.attachEvent){window.attachEvent("onunload",V)}}return O}();
