var backButton={event:{hash:"",refer:"",type:"load"},copyHistory:[],addEvent:function(b,a){if(b=="backbutton"&&(!this.events||!this.events.backbutton)){this.addEvent("domready",backButton.start.bind(backButton))}return this._addEvent(b,a)},getHash:function(){return location.hash.substring(1)},start:function(){window.hash=this.hash.bind(this);if(window.ie){this.onHash=this.onIframe}if(window.khtml){this.history=$A(history).slice(1);this.history.push(this.getHash());this.oldHistoryLength=location.hash?-1:history.length;this.onHash=this.onLink}this.timer=this.onHash.pass(false,this).periodical(100)},onHash:function(a){var b=this.getHash();if(b!=this.event.hash||a){this.fireEvent(b)}},onLink:function(b){var a=history.length;if(a!=this.oldHistoryLength||b){if(typeof(this.history[a-1])=="undefined"){this.history=this.copyHistory.copy()}this.fireEvent(this.history[a-1]);this.oldHistoryLength=a}},onIframe:function(){$clear(this.timer);this.iframe=new Element("iframe").setStyle("display","none").injectInside(document.body).contentWindow.document;if(this.getHash()){this.updateIFrame(this.getHash())}},updateIFrame:function(a){this.iframe.open();this.iframe.write('<script>parent.location.hash = "'+a+'"; parent.backButton.fireEvent("'+a+'");<\/script>');this.iframe.close()},hash:function(c){if($type(c)!="string"){return this.event.hash}this.event.type="click";if(!window.ie){if(window.khtml){var b=new Element("a").setProperty("href","#"+c),a=document.createEvent("MouseEvents");a.initEvent("click",true,true);b.dispatchEvent(a);if(this.history.length>=history.length){this.copyHistory=this.history.copy();this.history=this.history.splice(0,history.length-1)}this.history.push(c)}else{location.hash=c||"#"}this.onHash(true)}else{this.updateIFrame(c)}},fireEvent:function(a){this.event.hash=a;Element.prototype.fireEvent.call(window,"backbutton",[Object.extend({},this.event)]);Object.extend(this.event,{refer:a,type:"backbutton"})}};window.extend({_addEvent:window.addEvent,addEvent:backButton.addEvent,hash:Class.empty});