(function(window, $){
$.history = {
init: function(callback){
var timer = 100,
self = this,
nohashevent = false,
set = function (a, target) {
if(target) window.location.href = target + '#' + a;
else window.location.hash = a;
},
current = this.current = function(){
var loc = window.location, hash = loc.hash, str = loc+'', i = str.indexOf('#');
i != -1 && (hash = str.slice(i));
return hash.substring(1);
},
init = $.browser.msie && parseInt($.browser.verion, 10) < 8 || document.documentMode < 8 || !('onhashchange' in window) || !('onhashchange' in document.body) ? (nohashevent = true) && function(){
setInterval(function(){
var check = current();
if(check != self.current){
$.browser.msie && addIEHistory(check);
callback(check, self.current);
}
self.current = check;
}, timer)
} : function(){
window.onhashchange = function(){
var update = current();
callback(update, self.current);
self.current = update;
}
};
this.callback = callback;
if ($.browser.opera) history.navigationMode = setOverrideHistoryNavigationMode = 'compatible';
if($.browser.msie && nohashevent){
var IEHistoryFrame = document.createElement('iframe'),
addIEHistory = function(hash){
if(hash==IEHistoryFrame.contentWindow.curHash) return;
IEHistoryFrame.contentWindow.document.open();
IEHistoryFrame.contentWindow.document.write('<scr'+'ipt>window.curHash = "'+hash+'"; parent.location.hash = "'+hash+'"</scr'+'ipt>');
IEHistoryFrame.contentWindow.document.close();
};
IEHistoryFrame.src = 'javascript:true;';
IEHistoryFrame.style.display = 'none';
document.body.appendChild(IEHistoryFrame);
}
this.push = function(update, target) {
if (this.current != update) set(update, target);
return true
}
init();
//callback(current());
}
};
}(this, this.jQuery));