var HELP_BUDDY = function() {
    // Set up the white box properties
    jQuery('#buddyYourEquipment .whiteBox').data({ 'min': 2 });
    jQuery('#buddyYourRecentlyViewed .whiteBox').data({ 'min': 3 });

    // Set size of buddy white boxes
    HELP_BUDDY.defaultHeight = function(oDivs) {
        oDivs.each(function() {

            var iLessHeight = 0,
				iMoreHeight = 0;

            var oSelf = jQuery('.whiteBox', this),
				oLi = oSelf.find('ul li').not('ul li li');

            // Get height of first 3 Li's
            var iLessHeight = 0;

            oLi.each(function(i) {

                var iHeight = jQuery(this).outerHeight(true);

                // Only add to less height for the first 3 items
                if (i < oSelf.data().min) {
                    iLessHeight += iHeight;
                }

                iMoreHeight += iHeight;

            });

            // IE 7 fix
            if (jQuery.browser.msie && jQuery.browser.version <= 7) {
                iMoreHeight += 10;
            }
            iLessHeight = iLessHeight - 1;

            // Set to lesser height first
            oSelf.height(iLessHeight);

            // Hide the MORE link if we don't have enough items to warrant it
            if (oLi.length <= oSelf.data().min) {
                jQuery(this).find('.lnkMore').hide();
            }   //if
            else {
                jQuery(this).find('.lnkMore').css('display', 'block').show();
            }   //else

            oSelf.data({ 'less': iLessHeight, 'more': iMoreHeight });

        });

    }

    HELP_BUDDY.wireEvents = function() {
        // Event for sign in
        jQuery('#helpBuddy .lnkSignIn').click(function(e) {

            e.preventDefault();
            jQuery('#buddyNotSignedIn').hide();
            jQuery('#buddyRecognized').show();

        });

        // Event for more
        jQuery('#helpBuddy .lnkMore').click(function(e) {

            e.preventDefault();
            setHeight(this, 'more');
            jQuery(this).next().show();

        });

        // Event for less
        jQuery('#helpBuddy .lnkLess').click(function(e) {

            e.preventDefault();
            setHeight(this, 'less');
            jQuery(this).prev().show();

        });
    }

    function setHeight(oEl, sType) {

        var oSelf = jQuery(oEl),
		oContainer = oSelf.parent().find('.whiteBox');

        oContainer.animate({
            height: oContainer.data(sType)
        }, 'fast');

        oSelf.hide();

    }
}

jQuery(document).ready(function() {
    HELP_BUDDY();
    HELP_BUDDY.wireEvents();
});




