_onload = window.onload;

window.onload = function() {

    _onload();

    // TODO: Figure out how to share this code between here and front page
    $$('.follow').invoke('observe', 'click', onFollow);
}

function onFollow(event) {
    event.stop();
    var followElem = event.findElement('.follow');
    // get the id from the link
    var lastIndex = followElem.href.lastIndexOf('/');
    var channelId = followElem.href.substring(lastIndex + 1);
    new Ajax.Request('/dialog/follow/' + channelId, {
        method: 'get',
        onSuccess: function(transport) {
            $('arrowingContent').update(transport.responseText);
            arrowDialog.show(followElem.cumulativeOffset());

            decorateSaveChannelDialog();

            $('createChannelCancel').observe('click', function(event) {
                arrowDialog.hide();
            });

        }
    });
}


// TODO: Redundant with channel.js
function submitChangeSectionForm() {
    var form = $('changeSectionForm');
    var sectionId = form.down('select').value;
    form.request({
        onSuccess: function() {
            Navbar.moveChannel(channelId, sectionId);
        }
    });
}
