function Comment() {}

Comment.prototype.toggleReply = function( commentId, returnUri ) {
    var itemId       = $( '#itemId' ).attr('value');
    var itemType     = $( '#itemType' ).attr('value');
    var commentToken = $( '#token' ).attr('value');
    var returnUri    = $( '#return' ).attr('value');
    
    var formId = 'reply' + commentId;
    var replyLinkId = '#replyLink' + commentId;
    
    if ( $( '#' + formId ).attr( 'id' ) != undefined ) {
        $( '#' + formId ).remove();
        $( replyLinkId ).text( 'reply' );
    }
    else {
        var form = '<div id="' + formId + '"><form action="/comments/do_comment" method="post"><textarea name="comment" rows="8" cols="40"></textarea><br /><input type="submit" name="submit" value="comment" /><input onclick="toggleReply('+ commentId +')" type="button" name="cancel" value="cancel" /><input type="hidden" name="itemType" value="'+ itemType +'" /><input type="hidden" name="itemId" value="'+ itemId +'" /><input type="hidden" name="token" value="'+ commentToken +'" /><input type="hidden" name="return" value="'+ returnUri +'" /><input type="hidden" name="parentId" value="'+ commentId +'" /></form></div>';
        $( '#commentNav' + commentId ).append( form );
        $( replyLinkId ).text( 'cancel' );
    }
}

function toggleReply( commentId ) {
    comment.toggleReply( commentId );
}

comment = new Comment;