var watchAuthor = {
    requestParams:{ },
    ajaxResponse:null,
    requestUrl:'/service/ajax/watch_user.html?',

    init:function(){
    },

    setRequestParam:function(name, value){
        this.requestParams[name] = value;
    },

    makeRequest:function(){
        var callBack = {
            success:this.handleSuccess,
            failure:this.handleFailure,
            scope:this
        }
        for(paramName in this.requestParams){
            this.requestUrl += paramName + "=" + this.requestParams[paramName] + "&";
        }
        this.requestUrl = this.requestUrl.slice(0, this.requestUrl.length -1);
        this.request = yuiConnect.asyncRequest('GET', this.requestUrl, callBack);
    },

    handleSuccess:function(response){
        this.ajaxResponse = YAHOO.lang.JSON.parse(response.responseText);
        if (this.ajaxResponse.success){
            yuiDom.getElementsByClassName("watchAuthor", "span", "", changeWatchAuthorDisplay)
        } else {
            mm.Error.add(this.ajaxResponse.error);
            mm.Error.generateBridge();
        }
    },

    handleFailure:function(response){
        mm.Error.add("Your request to watch this author failed.  Please try again later.");
        mm.Error.generateBridge();
    },

    initBridge:function(){
        var self = watchAuthor;
        self.init();
    }

};

function changeWatchAuthorDisplay(watchLink){
    watchLink.innerHTML = "<img src=\"/images/watching_user.gif\" alt=\"\"/>";
}

function watchAuthorBridge(authorId){
    var self = watchAuthor;
    self.setRequestParam("authorId", authorId);
    self.makeRequest();
}

yuiEvent.onDOMReady(watchAuthor.initBridge);