(function($,window,top){var instance;$.history=function(method,param){if(typeof method=="function"){param=method;method="bind"}else if(/bind|unbind/.test(method)&&!$.isFunction(param))return;if(!instance){instance=new hist;instance.init()}method!="init"&&instance[method](param)};function hist(){var self=this,IE67=$.browser.msie&&parseInt($.browser.version)<8,IE8=$.browser.msie&&parseInt($.browser.version)>=8,$iframe,$wnd=$(window),stop=false;self.value=top.location.hash.substr(1);this.init=function(){if(IE8)$wnd.bind("hashchange",IE8Handler);else if(IE67)initIframe();else(function(){if(stop)return;top.location.hash.substr(1)!==self.value&&changed(top.location.hash);setTimeout(arguments.callee,50)})()};this.destroy=function(){stop=true;$iframe&&$iframe.remove();$wnd.unbind("hashchanged");instance=null;IE8&&$wnd.unbind("hashchange",IE8Handler)};this.bind=function(callback){$wnd.bind("hashchanged",callback)};this.unbind=function(callback){$wnd.unbind("hashchanged",callback)};this.add=function(value){top.location.hash=value};this.forward=function(){history.go(1)};this.back=function(){history.go(-1)};function initIframe(){$iframe=$iframe||$('<iframe style="display: none;" class="x-history-iframe"/>').appendTo(document.body);try{$iframe[0].contentWindow}catch(e){setTimeout(arguments.callee,50);return}var iHash=iDoc().location.hash,hash=top.location.hash,iHashNew,hashNew;(function(){if(stop)return;iHashNew=iDoc().location.hash;hashNew=top.location.hash;if(iHashNew!==iHash){iHash=iHashNew;hash=iHash;top.location.hash=changed(iHash)}else if(hashNew!==hash){hash=hashNew;updateIFrame(hash)}setTimeout(arguments.callee,50)})();function iDoc(){return $iframe[0].contentWindow.document}function updateIFrame(value){iDoc().open();iDoc().close();iDoc().location.hash=value}}function changed(value){self.value=value.substr(1);$wnd.trigger("hashchanged",[self]);return self.value}function IE8Handler(){changed(top.location.hash)}}})(jQuery,window,top);
