$(document).ready(function() {    
    $('a[rel*=facebox]').fancybox({
        'overlayShow'          : true,
        'showNavArrows'        : false,
        'centerOnScroll'       : true,
        'mouseWheelNavigation' : false, // my custom, not present in original js
        'padding'              : 30
    });
});

/**
 * Create new object for VoteControls class if now exists
 */
if (typeof(VoteControls) == 'undefined') VoteControls = new Object();
/**
 * VoteVonctrols class constructor
 * 
 * @author  Denis Chmelyuk <D.Chmelyuk@gmail.com>
 * @param   url     String
 * @param   set     String
 * @param   element Object
 */
VoteControls.Manager = function(url, set, element) {
    this.request_url    = url;
    this.vote_set       = set;
    this.action_element = element;
    currentObject       = this;
}

/**
 * Send vote request to the server via jQury.post
 */
VoteControls.Manager.prototype.doVote = function() {
    $.fancybox.showActivity();
    $.post(this.request_url, {set: this.vote_set}, this.callbackVote, 'json');
}

/**
 * doVote post callback. recieve and show response.
 *
 * @param   Response    JSON
 */
VoteControls.Manager.prototype.callbackVote = function(Response) {
    $.fancybox(Response.message);
    if (!Response.error) {
        window.setTimeout(currentObject.hideCallback, 3000);
    } //if
}

/**
 * Hide response message if success and remove object action element.
 */
VoteControls.Manager.prototype.hideCallback = function() {   
    if (currentObject.action_element != null) $(currentObject.action_element).remove();
    $.fancybox.close();
}

/**
 * Make vote call function
 *
 * @param   url String  vote call url
 * @param   set String  vote call param set (coach,like,go)
 * @param   el  Object  action element
 */
function call_vote(url, set, el) {
    voteManager = new VoteControls.Manager(url, set, el);
    voteManager.doVote();
}


if (typeof(WallControls)=="undefined") WallControls = new Object();

WallControls.Manager = function(url) {
    this.request_url    = url;
}

WallControls.Manager.prototype.open = function() {
    var currentObject       = this;
    $.fancybox({href:currentObject.request_url,type:'inline'});
}

function call_wall_edit(url) {
    wallManager = new WallControls.Manager(url);
    wallManager.open();
}
