﻿var WebFavoritesActionType = { add: 0, remove: 1, none: 2 }

function WebFavorites() {
}

WebFavorites.add = function(callback, ident) {
    var params = {
        actionType: WebFavoritesActionType.add,
        ident: ident
    }

    this.increment('ctl00_Sidebar_lnkFavorites', true);
    $.getJSON('json/web/favorites.aspx', params, callback);
}

WebFavorites.remove = function(callback, ident) {
    var params = {
        actionType: WebFavoritesActionType.remove,
        ident: ident
    }

    this.increment('ctl00_Sidebar_lnkFavorites', false);
    $.getJSON('json/web/favorites.aspx', params, callback);
}


WebFavorites.get = function(callback) {
    var params = {
        actionType: WebFavoritesActionType.none
    }
    $.getJSON('json/web/favorites.aspx', params, callback);
}

WebFavorites.increment = function(control, increment) {
    var number = Number($('#' + control).html());
    var total = 0;
    if (increment) total = number + 1;
    else total = number - 1;
    $('#' + control).text(total);
}