﻿FriendsBox.prototype = new Box();
FriendsBox.prototype.constructor = FriendsBox;

function FriendsBox(){

}

FriendsBox.prototype.onData = function(data){
           
    var sb = new Array();
    var body = this.getBody();
    sb.push(Box.formatSections(data, this.boxId, FriendsBox.onFriendBoxSectionLink, FriendsBox.onFriendBoxEventLink, FriendsBox.onFriendBoxRel, "tooltip"));
    body.innerHTML = sb.join("");
}

FriendsBox.prototype.update = function(){
    if(!this.isMinimized){
        var body = this.getBody();
        if(body!=null){
            this.loadData();
        }
    }else{
        this._onToggleMinimize();
    }
    this._updateEdit();
}

FriendsBox.prototype.onAddFriendClick = function(){
    this.hideEdit();
    var friendTextField = $("#"+this.boxId+"_edit_friend");
    MyMofusService.FriendsBoxAddFriend(this.boxId, friendTextField.val(), FriendsBox._onAddFriendClickSuccess, FriendsBox._onAddFriendClickFail, this)
}

FriendsBox.prototype._updateEdit = function(){
    var friendTextField = $("#"+this.boxId+"_edit_friend");
    Box.prototype._updateEdit.call(this);
    if(this.isEditOpen){
        friendTextField.focus();
    }else{
        friendTextField.blur();
    }
}

FriendsBox._onAddFriendClickFail = function(error, context){
    context.error(error);
}

FriendsBox._onAddFriendClickSuccess = function(data, context){
    context.update();
}

FriendsBox.onFriendBoxSectionLink = function(section){
    return Box.siteRoot + "/User/" + section.Id + "/Default.aspx";
}

FriendsBox.onFriendBoxEventLink = function(evt){
    return Box.siteRoot + "/Event/" + evt.Id + "/Default.aspx";
}

FriendsBox.onFriendBoxRel = function(section){
    return Box.siteRoot + "/Rpc/Mofus/UserTooltip.aspx?UserId=" + section.Id;
}
