var favorite = {
    toggle: function(product_id) {
        var faction = $('#actf_'+product_id).is('.is_fav') ? 'del' : 'add';

        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/ajax/ajax_fav/'+faction,
            data: {p_id: product_id},
            success: function(data) {
                notice.clear();
                if (data.res == true) {
                    // toggle is_fav flag
                    $('#actf_'+product_id).toggleClass('is_fav');

                    notice.add('success', data.notice);
                    // update links
                    favorite.updateTxt(product_id, data);
                } else {
                    notice.add('error', data.notice);
                }
                notice.show();
            },
            error: function() {
                notice.clear();
                notice.add('error', 'Failed to submit');
                notice.show();
            }
        })
    },
    updateTxt: function(product_id, data) {
        $('#actf_'+product_id).text(data.link_txt);
    }
}
