function toBasket(id, count) {
	$.ajax({
		url: '/store/set/'+id+'/'+count,
		success: function(msg){
			if (msg == 'OK')
				updateBasket('add', id);
			if (msg == 'UPD')
				updateBasket('update', id);
			if (msg == 'DEL')
				updateBasket('del', id);
		}
	});
	return false;
}

function delBasket(id) {
	$.ajax({
		url: '/store/del/'+id,
		success: function(msg){
			if (msg == 'OK')
				updateBasket('del', id);
		}
	});
	return false;
}

function updateBasket(type, id) {
	$(".basketinfo").css({display: 'none'});
    $(".basketinfo_loader").css({display: 'inline'});
	showbasketBox();
	$.ajax({
		url: '/store/getinfo/',
		success: function(msg){
			$(".basketinfo").html(msg);
            $(".basketinfo_loader").css({display: 'none'});
			$(".basketinfo").fadeIn(300);
		}
	});

	if (type == 'add'){
		$.ajax({
			url: '/store/getitem/'+id,
			success: function(msg){
				basketcount++;
				showArrows();
				contentheight = contentheight+286;
                $("#basket_container").css({width: contentheight+'px'});
				$("#basket_container").prepend(msg);
				basketMessage();
                $('#basket_order').show();
			}
		});
	}
	if (type == 'update'){
		$.ajax({
			url: '/store/getitem/'+id,
			success: function(msg){
				$("#basketItem_"+id).remove();
				$("#basket_container").prepend(msg);
                basketMessage();
                $('#basket_order').show();
			}
		});
	}


	if (type == 'del') {
		if (! $("#basketItem_"+id).html() ) return;
		$("#basketItem_"+id).fadeOut(300, function(){
			$("#basketItem_"+id).remove();
		});
		contentheight = contentheight-286;
		basketcount = basketcount-1;
		showArrows();
		$("#basket_container").css({width: contentheight+'px'});
		if (basketcount == 0) {
	        $('#basket_order').hide();
		}
	}

}

$.alerts.overlayOpacity = .50;
$.alerts.overlayColor = '#000000';
$.alerts.okButton = 'bezárás';
function basketMessage() {
	jAlert('A termék bekerült a kosárba!', 'Rendszerüzenet', '', function(r) {});
}

function movedown_basket(){
	if (window.moveupvar)
		clearTimeout(moveupvar);
	if (parseInt(crossobj.style.left)>=(parseInt($('#basket_container').width())-parseInt($('#basket_scroller').width()))*(-1)+4)
		crossobj.style.left=parseInt(crossobj.style.left)-speed+"px";
	movedownvar=setTimeout("movedown_basket()",20);
}

function moveup_basket(){
	if (window.movedownvar)
		clearTimeout(movedownvar);
	if (parseInt(crossobj.style.left)<0)
		crossobj.style.left=parseInt(crossobj.style.left)+speed+"px";
	moveupvar=setTimeout("moveup_basket()",20);
}

function stopscroll_basket(){
	if (window.moveupvar)
		clearTimeout(moveupvar);
	if (window.movedownvar)
		clearTimeout(movedownvar);
}

function showArrows() {
    if ( basketcount > 3 ) {
        $('#left_arrow').show();
        $('#right_arrow').show();
    } else {
        $('#left_arrow').hide();
        $('#right_arrow').hide();
    }
}
