jQuery(function() {

    $('#groupinvite').livequery(function() {
        $('li', this).hover(function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
        });

        $('li', this).click(function() {
            $('input', this).change();
        });

        $('input[type=checkbox]', this).change(function() {
            var input = $(this);
            var li = input.parent('li:first');

            if (input.is(':checked')) {
                input.removeAttr('checked');
                li.removeClass('checked');
            } else {
                input.attr('checked', 'checked');
                li.addClass('checked');
            }

            return false;
        });
    });

    $('input.type-color').livequery(function() {
        $(this).ColorPicker({
            livePreview: true,
            onBeforeShow: function () {
                    $(this).ColorPickerSetColor($(this).val());
            },
            onShow: function (colpkr) {
                    $(colpkr).fadeIn('fast');
                    return false;
            },
            onHide: function (colpkr) {
                    $(colpkr).fadeOut('fast');
                    return false;
            },
            onChange: function (hsb, hex, rgb) {
                    $('input.type-color').val(hex);
                    $('div.preview div.bg').css('backgroundColor', '#' + hex);
            },
            onSubmit: function(hsb, hex, rgb, el) {
                    $(el).val(hex);
                    $(el).ColorPickerHide();
            }
        });
    });

    $('a.showdetails').click(function() {
        $(this).fadeOut('fast').parents('dd:first').find('div.details').hide().removeClass('hide').slideDown('fast');
        return false;
    });

});