UCLU.list = {
    init: function() {
       // Add event handlers to subscribe buttons
       YAHOO.util.Event.addListener('subscribe-email', 'click', this.handleSubscribe);
       YAHOO.util.Event.addListener('subscribe-homepage', 'click', this.handleSubscribe);
    },
    
    handleSubscribe: function(e) {
        if (e) YAHOO.util.Event.stopEvent(e);
            
        if (!$('subscribe-module')) {
            var html = '<div class="hd">&#160;</div>' +
                       '<div class="bd">' +
                           '<p>'+
                               'Click "Save" to subscribe to a regular email newsletter '+
                               'containing all the posts made to this blog.' +
                           '</p>' +
                           '<p>' +
                               '<button type="button" id="subscribe-save" title="Save">' + 
                                    '<img src="styling/i/subscribe-save.gif" alt="Save">' +
                               '</button>' +
                               '<a href="javascript:void(0)" id="subscribe-cancel">Cancel</a>' +
                           '</p>' +
                       '</div>' +
                       '<div class="ft">&#160;</div>';

            var div = document.createElement("div");
            div.className = 'module fill';
            div.id = 'subscribe-module';

            var bt = $('blog-title').nextSibling;
            bt.parentNode.insertBefore(div, bt);
            div.innerHTML = html;

            YAHOO.util.Event.addListener('subscribe-save', 'click', function(e) {
                community.callCustomMethod('POST', 'list-subscribe', {
                    success: function() {
                       $('subscribe-module').style.display = 'none';
                    }
                }, {
                    listname: community.getData('listName')
                });

            });
            
            YAHOO.util.Event.addListener('subscribe-cancel', 'click', function(e) {
                if (e) YAHOO.util.Event.stopEvent(e);
                $('subscribe-module').style.display = 'none';
            });
        } else if ($('subscribe-module').style.display == 'none') {
            $('subscribe-module').style.display = 'block';
        } else {
            $('subscribe-module').style.display = 'none';
        }
    }
}

UCLU.list.init();