jQuery.extend({
    historyCurrentHash: undefined,
    historyCallback: undefined,
    historyInit: function(callback){
        jQuery.historyCallback = callback;
        var current_hash = location.hash;
        jQuery.historyCurrentHash = current_hash;
        if (jQuery.browser.msie) {
            if (jQuery.historyCurrentHash == '') {
                jQuery.historyCurrentHash = '#'
            }
            $("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');
            var ihistory = $("#jQuery_history")[0];
            var iframe = ihistory.contentWindow.document;
            iframe.open();
            iframe.close();
            iframe.location.hash = current_hash
        }
        jQuery.historyCallback(current_hash.replace(/^#/, ''));
        setInterval(jQuery.historyCheck, 100)
    },
    historyAddHistory: function(hash){
        jQuery.historyBackStack.push(hash);
        jQuery.historyForwardStack.length = 0;
        this.isFirst = true
    },
    historyCheck: function(){
        if (jQuery.browser.msie) {
            var ihistory = $("#jQuery_history")[0];
            var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
            var current_hash = iframe.location.hash;
            if (current_hash != jQuery.historyCurrentHash) {
                location.hash = current_hash;
                jQuery.historyCurrentHash = current_hash;
                jQuery.historyCallback(current_hash.replace(/^#/, ''));
            }
        }
        else 
            {
                var current_hash = location.hash;
                if (current_hash != jQuery.historyCurrentHash) {
                    jQuery.historyCurrentHash = current_hash;
                    jQuery.historyCallback(current_hash.replace(/^#/, ''));
                }
            }
    },
    historyLoad: function(hash, callback){
        var newhash;
        
		newhash = '#' + hash;
		location.hash = newhash
        
        jQuery.historyCurrentHash = newhash;
        if (jQuery.browser.msie) {
            var ihistory = $("#jQuery_history")[0];
            var iframe = ihistory.contentWindow.document;
            iframe.open();
            iframe.close();
            iframe.location.hash = newhash;
            jQuery.historyCallback(hash)
        }
		else {
                jQuery.historyCallback(hash)
            };
        if (typeof(callback) == 'function') {
            callback();
        }
    }
});

