var WallPosts = {};

WallPosts.Settings = {
    ContainerId : 'operator_wall_posts',
    Layers : {
        Posts : 'operator_wall_posts_content',
        Loading : 'operator_wall_posts_loader'
    }
};

WallPosts.Get = function(iProfile, iOffset) {
    new Ajax.Request('/ajax/utilities/wall_posts/get', {
        method : 'post',
        parameters : {
            Profile : iProfile,
            Offset : iOffset
        },
        onLoading : function() {
            WallPosts.Layers.ActivateLayer('Loading');
        },
        onFailure : function() {
            WallPosts.Layers.ActivateLayer('Posts');
        },
        onSuccess : function(oTransfer) {
            oResponse = oTransfer.responseJSON;
            if (oResponse == null || Object.isUndefined(oResponse.Status)
                    || oResponse.Status == 0) {
                return WallPosts.Layers.ActivateLayer('Posts');
            }
            Element.update(WallPosts.Settings.ContainerId, oResponse.HTML);
        }
    });
};

WallPosts.Layers = {
    ActivateLayer : function(LayerId) {
        $H(WallPosts.Settings.Layers).each(function(pair) {
            Element.hide($(pair[1]));
        });
        Element.show(WallPosts.Settings.Layers[LayerId]);
    }
};

