jQuery(function() {
    var $tabular = jQuery(".tabular");
    var $pages = jQuery(">.tab-page", $tabular);
    var positions = {
        "products": [0, -22],
        "markets": [0, -44]
    };

    jQuery(">.tabs>a", $tabular).each(function() {
        var tab = jQuery(this);
        var id = tab.attr("id").replace(/tab\-/, "");
        var position = tab.backgroundPosition();

        tab.bind("click", function() {
            jQuery(this).backgroundPosition(position.replace(/(\-?\d+)px$/, positions[id][1]+"px"))
                .siblings().each(function() {
                    var bgPos = jQuery(this).backgroundPosition();
                    jQuery(this).backgroundPosition(bgPos.replace(/(\-?\d+)px$/, positions[id][1]+"px"));
                });
            $pages.hide().filter("#tab-" + id + "-page").show();
            return false;
        });
    }).filter(":first").trigger("click");

    // There's an issue where IE 6 won't show the background on cleared elements,
    // this is a workaround.
    if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
        var f_height = $("#feature").height() + 40; // 40 is the padding around the left bar elements
        var l_height = $("#left-bar").height();
        var r_height = $("#right-bar").height();

        if (r_height > f_height + l_height) {
            $("#left-bar #info-center, #left-bar #hot-topics").height((r_height - f_height) + "px");
        }
    }

    return this;
});
