﻿$(document).ready(function() {
    CollapseAllExpanders(null);
    $('.expandercommand').each(function(i) { $(this).bind('mouseover', Expander_Hover); });
});

function CollapseAllExpanders(skippingItemRel) {
    $('.expandercommand').each(function(i) {
        Expander_ActionSet(i, $(this), skippingItemRel);
    });
};

function Expander_ActionSet(i, thisItem, skippingItemRel) {
    if ((skippingItemRel == null) || (thisItem.attr('rel') != skippingItemRel)) {
        if (thisItem.attr('action') == undefined) {
            var subcategory = thisItem.attr('rel');
            $('#' + subcategory).slideUp('fast');
            thisItem.attr('action', 'expand');
        } else if (thisItem.attr('action') == 'collapse') {
            var subcategory = thisItem.attr('rel');
            $('#' + subcategory).slideUp('fast');
            thisItem.attr('action', 'expand');
        }
    }
};

function Expander_Hover() {
    $(this).die();

    var subcategory = $(this).attr('rel');
    var action = $(this).attr('action');

    CollapseAllExpanders(subcategory);

    if (action == 'expand') {
        $('#' + subcategory).slideDown('fast');
        $(this).attr('action', 'collapse');
    } else if (action == 'collapse') {
        $('#' + subcategory).slideDown('fast');
        $(this).attr('action', 'collapse');
    }

    $(this).hover(Expander_Hover);
};