function update_comparison_controls_add() {
    $('a.add_to_comparison').click(function() {
        var myClass = $(this).attr('class');
        if (myClass == 'add_to_comparison') {
            $.get(
                    this.href,
                    function(data) {
                        $('#comparison').html(data);
                    }
                    );
            $('img', this).attr('src', '/images/remove_comparison.jpg');

            var new_href = site_url + 'removeFromComparison/' + this.href.substring(site_url.length + 16);
            $(this).attr('href', new_href);
            $(this).attr('class', 'remove_from_comparison');
            jAlert('Votre véhicule a été ajouté à la fiche de comparaison. Vous pouvez consulter cette fiche en cliquant en haut de page.', 'Comparer des modèles');
            return false;
        } else {
            $.get(
                    this.href,
                    function(data) {
                        $('#comparison').html(data);
                    }
                    );
            $('img', this).attr('src', '/images/comparer.png');
            
            var new_href = site_url + 'addToComparison/' + this.href.substring(site_url.length + 21);
            $(this).attr('href', new_href);
            $(this).attr('class', 'add_to_comparison');
            return false;
        }
    })
}
function update_comparison_controls_remove() {
    $('a.remove_from_comparison').click(function() {
        var myClass = $(this).attr('class');
        if (myClass == 'remove_from_comparison') {
            $.get(
                    this.href,
                    function(data) {
                        $('#comparison').html(data);
                    }
                    );
            $('img', this).attr('src', '/images/comparer.png');

            var new_href = site_url + 'addToComparison/' + this.href.substring(site_url.length + 21);
            $(this).attr('href', new_href);
            $(this).attr('class', 'add_to_comparison');
            return false;
        } else {
            $.get(
                    this.href,
                    function(data) {
                        $('#comparison').html(data);
                    }
                    );
            $('img', this).attr('src', '/images/remove_comparison.jpg');

            var new_href = site_url + 'removeFromComparison/' + this.href.substring(site_url.length + 16);
            $(this).attr('href', new_href);
            $(this).attr('class', 'remove_from_comparison');
            jAlert('Votre véhicule a été ajouté à la fiche de comparaison. Vous pouvez consulter cette fiche en cliquant en haut de page.', 'Comparer des modèles');
            return false;
        }
    })
}

$(document).ready(function() {
    update_comparison_controls_add();
    update_comparison_controls_remove();
})

