/*
** kosárba pakolás
*/

function basketUp() {
	$("#basketBox").animate({bottom: "0"}, 600, function(){
		$("#up").css({display: 'none'});
		$("#up2").css({visibility: 'hidden'});
		$("#down").css({display: 'block'});
		$("#down2").css({visibility: 'visible'});
	});

//	alert(document.getElementById('basketBox').style.bottom);
}

function basketDown() {
	$("#basketBox").animate({bottom :"-140px"}, 600, function(){
		$("#up").css({display: 'block'});
		$("#up2").css({visibility: 'visible'});
		$("#down").css({display: 'none'});
		$("#down2").css({visibility: 'hidden'});
	});
}

function updateBasket(type, id) {
	$("#basketinfo").css({display: 'none'});
    $("#basketinfo_loader").css({display: 'inline'});
	basketUp();
	$.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){
				contentheight = contentheight+205;
                $("#basket_container").css({width: contentheight+'px'});
				$("#basket_container").append(msg);
			}
		});
	}

	if (type == 'del') {
		$("#basketItem_"+id).fadeOut(300, function(){ 
            $("#basket_container").css({width: contentheight+'px'});
			$("#basketItem_"+id).remove();
			contentheight = contentheight-205;
            $("#basket_container").css({width: contentheight+'px'});
		});
	}

}

function toBasket(id) {
	$.ajax({
		url: '/store/set/'+id,
		success: function(msg){
			if (msg == 'OK')
				updateBasket('add', id);					
		}
	});
}

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

function incBasket(id) {
	$.ajax({
		url: '/store/inc/'+id,
		success: function(msg){
			if (msg) {
				$('#item_count_'+id).html(msg);		
				updateBasket();		
			}
		}
	});
}

function decBasket(id) {
	$.ajax({
		url: '/store/dec/'+id,
		success: function(msg){
			if (msg) {
				$('#item_count_'+id).html(msg);		
				updateBasket();		
			}
		}
	});
}




function searchNav( num ) {
	$('#searchLayer').slideToggle();
}


function doSearch(szoveg) {
	$.ajax({
		type: 'POST',
		data: "form_kereses[keyword]="+szoveg,
		url: '/search/',
        success: function(msg){
            window.location = '/konyvek/kereses/';
        }
	});
}


function setavail() {
	if ($('#chb').attr('checked')) un = ''; else un = 'un';

	$.ajax({
		url: '/ajax/'+un+'set_available/',
        success: function(msg){
			window.location.reload();
	    }
	});
}

