$(document).ready(function() {
    $('#verlanglijst img').click(function() {
        id = $(this).attr('id').split('_')[1];
        remove_url = jsSiteHtmlUrl + '/verlanglijst/remove_present.php',
        $.ajax({
            url: jsSiteHtmlUrl + '/verlanglijst/add_present.php',
            dataType: 'json',
            data: 'cadeau_id=' + id,
            success: function(data) {
                $('#thelist ul').append('<li id="list_' + id + '"><strong>' + data.name 
                    + '</strong> (<a href="#" id="remove_' + id + '">verwijderen</a>)<br />' 
                    + data.text + '<br /><br /></li>'
                );
                
                $('#remove_'+id).click(function() {
                    id = $(this).attr('id').split('_')[1];
                    $.ajax({
                        url: jsSiteHtmlUrl + '/verlanglijst/remove_present.php',
                        data: 'cadeau_id=' + id,
                        success: function(data) {
                            $('#list_' + id).remove();
                        }
                    });
                    return false;
                })
            }
        });
        return false;
    })

    // For cadeaus, currently in session, add click event
    $('#thelist ul li a').each(function() {
        $(this).click(function() {
            id = $(this).attr('id').split('_')[1];
            $.ajax({
                url: jsSiteHtmlUrl + '/verlanglijst/remove_present.php',
                data: 'cadeau_id=' + id,
                success: function(data) {
                    $('#list_' + id).remove();
                }
            });
            return false;
        })
    })
});

