/* 
 * Created by David Galvis
 */


function Favorite() {
    
}
Favorite.prototype =
{
    /**
     * Adds the restaurant to users list
     */
    there: function(idRestaurant,fnc){
        jQuery.post("/application/addFavorite.php", {id_etab: idRestaurant},
        		function()
        		{
        			if( jQuery.isFunction(fnc) )
        				fnc();
        		});
    },

    /**
     * Adds the restaurant to users list
     */
    notThere: function(idRestaurant){
        jQuery.post("/application/ajax/delFavorite.php", {id_etab: idRestaurant});
    },

    init : function(callback){
        var _this = this;
        jQuery( "input[ name = 'favoriteRestaurant' ]" ).click( function( event ){
            if( jQuery( this ).attr( "checked" ) ){
                _this.there(jQuery( this ).val(),callback);
                jQuery(this).prev('img').show();
                jQuery(this).next('span').html(trad_added_to_favorites);
            }
            else {
                _this.notThere(jQuery( this ).val());
                jQuery(this).prev('img').hide();
                jQuery(this).next('span').html(trad_add_to_favorites);
            }
        });
    }
};

var favorite = new Favorite();


