﻿jQuery(document).ready(function () {
    jQuery('.sbsSection:last').css('border-bottom', 'none');

    //    jQuery('.sbsProfiles').each(function () {
    //        var self = jQuery(this);
    //        var profileWidth = jQuery('.sbsProfile:first', self).width() + 17; // 8px each side + 1 margin right
    //        var numProfiles = jQuery('.sbsProfile', self).size();
    //        var width = numProfiles * profileWidth;
    //        self.width(width);

    //        var height = 0;
    //        jQuery('.sbsProfile', self).each(function () {
    //            if (jQuery(this).height() > height)
    //                height = jQuery(this).height();
    //        });
    //        self.height(height); // set the profiles wrapper height to the heightiest profile's height
    //        self.parent().parent().height(self.parent().height()); // force the section's height to match its contents' height

    //        jQuery('.sbsProfilesLeftButton', self).click(function () {
    //            var mleft = Number(self.css('margin-left').replace('px', ''));
    //            if (mleft < 0) {
    //                self.animate({
    //                    'margin-left': '+=' + profileWidth
    //                });
    //                // now show the correct buttons
    //                jQuery('.sbsProfilesRightButton', self).show();
    //                if (mleft < 0)
    //                    jQuery(this).hide();
    //            }
    //        });
    //        jQuery('.sbsProfilesLeftButton', self).hide(); // defaults to the first, can't go left from the first
    //        jQuery('.sbsProfilesRightButton', self).click(function () {
    //            var mleft = Number(self.css('margin-left').replace('px', ''));
    //            if (-mleft < (numProfiles - 1) * profileWidth) {
    //                self.animate({
    //                    'margin-left': '-=' + profileWidth
    //                });
    //                // now show the correct buttons
    //                jQuery('.sbsProfilesLeftButton', self).show();
    //                if (-mleft < (numProfiles - 1) * profileWidth)
    //                    jQuery(this).hide();
    //            }
    //        });

    //        jQuery('.sbsProfileName', jQuery(this)).each(function () {
    //            var name = jQuery(this).html();
    //            name = name.toUpperCase();
    //            jQuery(this).html(name);
    //        });

    //    });

    jQuery('.sbsSection').each(function () {
        var section = jQuery(this);

        section.appendTo(jQuery('#sbsSections'));

        var title = jQuery('.sbsSectionTitle:first', section);
        var content = jQuery('.sbsSectionContent:first', section);

        var height = content.height();

        title.click(function (e) {
            if (!section.hasClass('sbsSection-selected')) {
                var cls = 'sbsSection-selected';
                var sel = jQuery('.' + cls);

                //content.animate({ height: height }, 350);
                content.slideDown(350);
                var selContent = jQuery('.sbsSectionContent:first', sel);
                if (!sel.hasClass('sbsFixedOpen'))
                    selContent.slideUp(350);
                    //selContent.animate({ height: 0 }, 350);

                sel.removeClass(cls);
                section.addClass(cls);
            }
        });
    });
    jQuery('.sbsSectionContent:gt(0)').slideUp(0);
    jQuery('.sbsSectionTitle:first').click();
});
