var basket = {
    'add': function(id) {
    	s = 0;
    	var cond_setup = 0;
    	basket.prepare();

    	x_add2basket(id, s, cond_setup, basket.showAnimate);
    },


    'prepare': function() {
    	if (document.getElementById('pix') && document.getElementById('pix').checked == true)
            s = $('#pix').val();

    	if (document.getElementById('cond_setup') && document.getElementById('cond_setup').checked == true)
            cond_setup = 1;
    },


    'recount': function(id, num) {
    	x_recount(id, num, basket.show);
    },


    'recount_detail': function(id, num) {
    	x_recount_new(id, num, function(a){
            if (a.num != undefined) document.getElementById('basket_num').innerHTML = a.num;
    	    if (a.total != undefined) document.getElementById('basket_total').innerHTML = a.total;
    	    if (a.cost != undefined) document.getElementById('basket_price_' + id).innerHTML = a.cost;
        });
    },


    'show': function(a) {
    	if (a[1]) document.getElementById('basket_content').innerHTML = a[1];
/*
    	if (a[0]) {
            document.getElementById('b_popup').innerHTML = a[0];
        	document.getElementById('b_popup').style.display = 'block';
    	}
*/
    },


    'showAnimate': function(a) {
    	basket.animate(a[2], a, basket.show);
    },


    'animate': function(id, a, callback) {
    	var base_img = $('#image_' + id);

    	if (!base_img.length) return;

        var pos = base_img.offset();
    	var result_pos = $('#basket_content').offset();

    	var img = document.createElement('img');

    	document.body.appendChild(img);

    	$(img).attr('src', base_img.attr('src')).css({
            position: 'absolute',
            top: pos.top,
            left: pos.left,
            opacity: 0.9,
            'z-index': 600
        }).animate({
            top: result_pos.top,
            left: result_pos.left
        }, 600, function(){
            $(this).remove();
            callback(a);
        });
    }
};
