$(function () {
    var zIndexNumber = 1000;
    $("div").each(function() {
        $(this).css("zIndex", zIndexNumber);
        zIndexNumber -= 10;
    });

    $("a.nolink").click(function() {
        return false;
    });

    $("a.popup").click(function() {
        window.open(this.href);
        return false;
    });
});

/**
 * Selects a tab based on the location's hash.  Should only be run after tab-enabling
 * JS has been run for it to have any effect.  Assumes we're using P7_TP tabs.
 * Also triggers a tab change when the location hash changes after page load
 * (e.g. when clicking on a link or hitting the back button).
 *
 * @return void
 */
jQuery.fn.selectHashTab = function()
{
    var _anchorTabDiv = this;

    /**
     * Selects a tab by the given hash.
     *
     * @param string hash
     * @return void
     */
    var _selectTabByHash = function(hash)
    {
        _anchorTabDiv.find("a[href='" + hash + "']").each(function() {
            P7_TPtrig(this);
        });
    };

    /**
     * Selects a tab by the current document's hash.
     *
     * @return void
     */
    var _selectTab = function() {
        var hash = document.location.hash;
        if (hash == "") {
            // Find first available hash
            hash =_anchorTabDiv.find("a:first").attr("href");
        }
        _selectTabByHash(hash);
    };

    $(window).hashchange(function() {
        _selectTab();
    });
    _selectTab();
}
