jQuery.extend({
    historyCurrentHash: undefined,
    historyCallback: undefined,
    historyInit: function (d) {
        jQuery.historyCallback = d;
        var c = location.hash;
        jQuery.historyCurrentHash = c;
        if (jQuery.browser.msie) {
            if (jQuery.historyCurrentHash == "") {
                jQuery.historyCurrentHash = "#"
            }
            $("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');
            var a = $("#jQuery_history")[0];
            var b = a.contentWindow.document;
            b.open();
            b.close();
            b.location.hash = c
        } else {
            if ($.browser.safari) {
                jQuery.historyBackStack = [];
                jQuery.historyBackStack.length = history.length;
                jQuery.historyForwardStack = [];
                jQuery.isFirst = true
            }
        }
        jQuery.historyCallback(c.replace(/^#/, ""));
        setInterval(jQuery.historyCheck, 100)
    },
    historyAddHistory: function (a) {
        jQuery.historyBackStack.push(a);
        jQuery.historyForwardStack.length = 0;
        this.isFirst = true
    },
    historyCheck: function () {
        if (jQuery.browser.msie) {
            var a = $("#jQuery_history")[0];
            var d = a.contentDocument || a.contentWindow.document;
            var f = d.location.hash;
            if (f != jQuery.historyCurrentHash) {
                location.hash = f;
                jQuery.historyCurrentHash = f;
                jQuery.historyCallback(f.replace(/^#/, ""))
            } else {
                if (location.hash.replace(/^#/, "") != f.replace(/^#/, "")) {
                    d.location.hash = location.hash
                }
            }
        } else {
            if ($.browser.safari) {
                if (!jQuery.dontCheck) {
                    var b = history.length - jQuery.historyBackStack.length;
                    if (b) {
                        jQuery.isFirst = false;
                        if (b < 0) {
                            for (var c = 0; c < Math.abs(b); c++) {
                                jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())
                            }
                        } else {
                            for (var c = 0; c < b; c++) {
                                jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())
                            }
                        }
                        var e = jQuery.historyBackStack[jQuery.historyBackStack.length - 1];
                        if (e != undefined) {
                            jQuery.historyCurrentHash = location.hash;
                            jQuery.historyCallback(e)
                        }
                    } else {
                        if (jQuery.historyBackStack[jQuery.historyBackStack.length - 1] == undefined && !jQuery.isFirst) {
                            if (document.URL.indexOf("#") >= 0) {
                                jQuery.historyCallback(document.URL.split("#")[1])
                            } else {
                                var f = location.hash;
                                jQuery.historyCallback("")
                            }
                            jQuery.isFirst = true
                        }
                    }
                }
            } else {
                var f = location.hash;
                if (f != jQuery.historyCurrentHash) {
                    jQuery.historyCurrentHash = f;
                    jQuery.historyCallback(f.replace(/^#/, ""))
                }
            }
        }
    },
    historyLoad: function (d) {
        var e;
        if (jQuery.browser.safari) {
            e = d
        } else {
            e = "#" + d;
            location.hash = e
        }
        jQuery.historyCurrentHash = e;
        if (jQuery.browser.msie) {
            var a = $("#jQuery_history")[0];
            var c = a.contentWindow.document;
            c.open();
            c.close();
            c.location.hash = e;
            jQuery.historyCallback(d)
        } else {
            if (jQuery.browser.safari) {
                jQuery.dontCheck = true;
                this.historyAddHistory(d);
                var b = function () {
                    jQuery.dontCheck = false
                };
                window.setTimeout(b, 200);
                jQuery.historyCallback(d);
                location.hash = e
            } else {
                jQuery.historyCallback(d)
            }
        }
    }
});
