function runEffect(){
	var options = {};
	options = { to: ".shopping", className: 'ui-effects-transfer' };
	$(".productImage").effect("transfer", options, 500, callback);
	options = {};
	$(".shopping").effect("bounce", options, 300, callback);
}
function callback(){
	setTimeout(function(){
		$("#effect:hidden").removeAttr('style').hide().fadeIn();
	}, 1000);
}
/*For adding product to the basket*/
function toBasket(item) {
	$.post("/?toBasket=1&item=" + item, {}, function(data){
		runEffect();
		items = $("#itemsInBasket").text();
		items = parseInt(items) + 1;
		$("#itemsInBasket").text(items);
	});
}
function removeBasket(item) {
	$.post("/?removeBasket=1&item=" + item, {}, function(data){
		runEffect();
		$("#itemsInBasket").text(data);
		$('#' + item).remove();
		old_total = parseInt($('#sum_number_' + item).html());
		$('#total_number').html(parseInt($('#total_number').html())-old_total);
	});
}
function changeBasket(item) {
	quantity = parseInt($('#quantity_' + item).val());
	$.post("/?changeBasket=1&item=" + item + "&quantity="+quantity, {}, function(data){
		runEffect();
		$("#itemsInBasket").text(data);
	});
	old_total = parseInt($('#sum_number_' + item).html());
	new_total = parseInt($('#price_number_' + item).html())*quantity;
	$('#sum_number_' + item).html(new_total);
	$('#total_number').html(parseInt($('#total_number').html())-old_total+new_total);
}
function changeTransport(val) {
	$.post("/?changeTransport=1&item=" + val, {}, function(data){
		old = parseInt($('#transport_number').html());
		$('#transport_number').html(val);
		$('#total_number').html(parseInt($('#total_number').html())-old+parseInt(val));
	});

}
function selectSoja(much, text) {

	$('.calcDrop').hide();
	$('#much').html(text);
	$('#size').html(much);

}
function calculateSoja() {
	
	price1 = parseInt($('#price').val());
	price2 = parseInt($('#price2').val());
	size = parseInt($('#size').html())/1000
	save_price = price1*size*30;
	months = price2/save_price;
	
	text = 'Sojapiima liiter maksab poes '+price1+'.- Midzuga ühe liitri sojapiima valmistamiskulud on 5 krooni. Võit liitrilt '+(price1-5)+' krooni. Kui inimene/perekond tarbib '+size+' liitrit päevas, siis võit kuuga on <strong>30x'+price1*size+' = '+save_price+'.- kr</strong>. Masin teenib tasa <strong>'+price2+' : '+save_price+' = '+Math.round(months)+' kuuga.</strong>';
	
	$('.calcResult').html(text);

}