var Basket = {
	URL: SHOP_URL,

	add: function(id) {
		if (id == undefined) {
			return;
		}	
		
        var count = 1;
        
        if ($('#product_count').val() != undefined) {
			count = $('#product_count').val();
        }
        
	    $.ajax({
	    	url: Basket.URL+'ajax.php?page=ajax_basket_add&count='+count+'&addproduct='+id,
	    	async: false,
	    	success: function(response){
				if (parseInt(response) > 0) {
					// enable if pageTracker is needed
					//$('#google_basket_ajax').html(response);
					
					var height = ($(window).height()-$('#basket-dialog').height())/2;
					var left = ($(window).width()-$('#basket-dialog').width())/2;
					
					// nacteme jenom jednou
					if( $('#bought_exists').length == 0 ) {
						$.ajax({
								url: Basket.URL+'ajax.php?page=ajax_basket_dialog',
								async: false,
								success : function(response) {
									$('#basket-dialog, #basket-dialog5').replaceWith(response);
									$('#basket-dialog, #basket-dialog5').css({'display': 'block'});
									//	    			.animate({top: height+'px'}, 1000);
								}
						});
					}
					
				} else {
					// enable if pageTracker is needed
					//$('#google_basket_ajax').html(response);
					
					var height = ($(window).height()-$('#basket-dialog-error').height())/2;
					var left = ($(window).width()-$('#basket-dialog-error').width())/2;
					
					$('#basket-dialog-error')
						.css({'display': 'block'})
	//	    			.animate({top: height+'px'}, 1000);
				}
	    	}
	    });
		$.ajax({
	    	url: Basket.URL+'ajax.php?page=ajax_basket_info',
	    	async: false,
	    	success : function(response) {
				$('#basket-wrapper').html(response);
	    	}
		});
		
	}

};

$(document).ready(function(){
		
	var height = $('#basket-dialog').height();
	if(height == 0) {
		var height = $('#basket-dialog5').height();	
	}
		
	$('#basket-dialog-close').live('click', function() {
		$('#basket-dialog, #basket-dialog5').css({'display': 'none'})
		$('#bought_exists').replaceWith('');
	});

	$('#basket-dialog-close2').live('click', function() {
		$('#basket-dialog, #basket-dialog5').css({'display': 'none'})
		$('#bought_exists').replaceWith('');
	});
		
	$('#basket-dialog-error-close').live('click', function() {
		$('#basket-dialog-error')
	    			.css({'display': 'none'})
	});

	$('#basket-dialog-error-close2').live('click', function() {
		$('#basket-dialog-error')
	    			.css({'display': 'none'})
	});
});

