﻿var previousTab = "MDTTabPanes_Events";
jQuery(document).ready(function() {
    jQuery("#tabs").css({ 'visibility': 'visible' });

    jQuery("#MDTTabPanes_Events").click(function() {
        jQuery("#tab1").css({ 'background-image': 'url(/DesktopModules/TabPanes/css/ui-lightness/graphics/tabs_events_on.gif)' });
        jQuery(document).attr('title', 'Events Listed By Date -- Missouri Things to See and Do');
        if (previousTab != jQuery(this).attr("id")) {
            resetTabDisplay(previousTab);
            previousTab = jQuery(this).attr("id");
        }
    });

    jQuery("#MDTTabPanes_Listings").click(function() {
        jQuery("#tab2").css({ 'background-image': 'url(/DesktopModules/TabPanes/css/ui-lightness/graphics/tabs_listings_on.gif)' });
        jQuery(document).attr('title', 'Listings -- Missouri Things to See and Do');
        if (previousTab != jQuery(this).attr("id")) {
            resetTabDisplay(previousTab);
            previousTab = jQuery(this).attr("id");
        }
    });

    jQuery("#MDTTabPanes_Articles").click(function() {
        jQuery("#tab3").css({ 'background-image': 'url(/DesktopModules/TabPanes/css/ui-lightness/graphics/tabs_articles_on.gif)' });
        jQuery(document).attr('title', 'Articles Listed By Date -- Missouri Things to See and Do');
        if (previousTab != jQuery(this).attr("id")) {
            resetTabDisplay(previousTab);
            previousTab = jQuery(this).attr("id");
        }
    });

    jQuery("#MDTTabPanes_Media").click(function() {
        jQuery("#tab4").css({ 'background-image': 'url(/DesktopModules/TabPanes/css/ui-lightness/graphics/mediaTab_ON.png)' });
        jQuery(document).attr('title', 'Media -- Missouri Things to See and Do');
        if (previousTab != jQuery(this).attr("id")) {
            resetTabDisplay(previousTab);
            previousTab = jQuery(this).attr("id");
        }
    });

    jQuery("#MDTTabPanes_Coupons").click(function() {
        jQuery("#tab5").css({ 'background-image': 'url(/DesktopModules/TabPanes/css/ui-lightness/graphics/tabs_coupons_on.gif)' });
        jQuery(document).attr('title', 'Coupons -- Missouri Things to See and Do');
        if (previousTab != jQuery(this).attr("id")) {
            resetTabDisplay(previousTab);
            previousTab = jQuery(this).attr("id");
        }
    });


    if (jQuery('.eventsResultsCount').val() == 0) {
        if (jQuery('.listingsResultsCount').val() == 0) {
            if (jQuery('.articlesResultsCount').val() == 0) {
                if (jQuery('.mediaResultsCount').val() == 0) {
                    if (jQuery('.couponsResultsCount').val() != 0) {
                        jQuery('.MDTTabPanes_Coupons').click();
                    }
                }
                else {
                    jQuery('#MDTTabPanes_Media').click();
                }
            }
            else {
                jQuery('#MDTTabPanes_Articles').click();
            }
        }
        else {
            jQuery('#MDTTabPanes_Listings').click();
        }
    }
    else {
        jQuery('#MDTTabPanes_Events').click();
    }

    jQuery('a').filter('#MDTTabPanes_Events').html("(" + jQuery('.eventsResultsCount').val() + ")");
    jQuery('a').filter('#MDTTabPanes_Listings').html("(" + jQuery('.listingsResultsCount').val() + ")");
    jQuery('a').filter('#MDTTabPanes_Articles').html("(" + jQuery('.articlesResultsCount').val() + ")");
    jQuery('a').filter('#MDTTabPanes_Media').html("(" + jQuery('.mediaResultsCount').val() + ")");
    jQuery('a').filter('#MDTTabPanes_Coupons').html("(" + jQuery('.couponsResultsCount').val() + ")");
});

function resetTabDisplay(previousTab) {
    switch (previousTab) {
        case 'MDTTabPanes_Events':
            jQuery("#tab1").removeAttr("style");
            break;
        case 'MDTTabPanes_Listings':
            jQuery("#tab2").removeAttr("style");
            break;
        case 'MDTTabPanes_Articles':
            jQuery("#tab3").removeAttr("style");
            break;
        case 'MDTTabPanes_Media':
            jQuery("#tab4").removeAttr("style");
            break;
        case 'MDTTabPanes_Coupons':
            jQuery("#tab5").removeAttr("style");
            break;
        default:
            break;
    }
};

