$(document).ready(function() {
    $("a.lpopup").fancybox({
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'hideOnContentClick': false,
        'overlayOpacity': 0.41,
        'padding': 0
    });

    $("a#gmap").fancybox({
        'zoomSpeedIn': 0,
        'zoomSpeedOut': 0,
        'overlayShow': true,
        'hideOnContentClick': false,
        'overlayOpacity': 0.41,
        'frameWidth': 600,
        'frameHeight': 600
    });

    sizeCalc();
    setTimeout("sizeCalc()", 2000);

});

function sizeCalc() {
    document.getElementById('data').style.height = '';
    var contentdataHeight = document.getElementById('content-data').offsetHeight;
    document.getElementById('data').style.height = contentdataHeight + 'px';
}

/*
** jquery alerts parameters
*/

$.alerts.okButton = '';
$.alerts.cancelButton = '';
$.alerts.draggable = false;
$.alerts.overlayOpacity = .41;
$.alerts.overlayColor = '#000000';

function confirmMsg(msg) {
	var con = confirm(msg);
	if (con) return true;
	else return false;
}

function toggleSubCat(cls, id) {
	$('.'+cls).hide();
	$('#'+id).show();
}

function loadPage(link) {
//	$('#leftProdlist').fadeTo(10, 0.5);
    $.ajax({
		type: 'POST',
		data: $('#filterForm').serialize(),
        url: link,
        success: function(msg){
//			$('#leftProdlist').fadeTo(1000, 1);
            $("#leftProdlist").html(msg);
            document.getElementById('data').style.height = '';
            var contentdataHeight = document.getElementById('content-data').offsetHeight;
            document.getElementById('data').style.height = contentdataHeight + 'px';

            $.ajax({
				url: '/ajax/getpager/',
				success: function(msg){
					$(".prodpager").html(msg);
                    document.getElementById('data').style.height = '';
                    var contentdataHeight = document.getElementById('content-data').offsetHeight;
                    document.getElementById('data').style.height = contentdataHeight + 'px';
				}
			});
        }
    });
	return false;
}

function toBasket(id, count, konfig) {
	$.ajax({
		url: '/store/set/'+id+'/'+count+'/'+konfig,
		success: function(msg){
			if (msg == 'UPDATE')
				updateBasket('update', id);
			else if (msg == 'OK')
				updateBasket('add', 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'});
	basketDown();
	$.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++;
				showArrowsBasket();
				contentheight_basket = contentheight_basket+154;
                $("#scb-content-scroll-basket").css({width: contentheight_basket+'px'});
				$("#scb-content-scroll-basket").prepend(msg);
                jAlert('A termék bekerült a kosárba!', 'Rendszerüzenet', 'addcomment', function(r) {
                    if ( r ) {
                        location.href = '#top';
                    }
                });
                $('#basket_order').show();
			}
		});
	}

	if (type == 'update'){
		$.ajax({
			url: '/store/getitem/'+id,
			success: function(msg){
				$("#item_"+id).remove();
				$("#scb-content-scroll-basket").prepend(msg);
                jAlert('A termék bekerült a kosárba!', 'Rendszerüzenet', 'addcomment', function(r) {
                    if ( r ) {
                        location.href = '#top';
                    }
                });
                $('#basket_order').show();
			}
		});
	}


	if (type == 'del') {
		$("#item_"+id).fadeOut(300, function(){
			$("#item_"+id).remove();
		});
		contentheight_basket = contentheight_basket-154;
		basketcount = basketcount-1;
		showArrowsBasket();
		$("#scb-content-scroll-basket").css({width: contentheight_basket+'px'});
        if ( basketcount == 0 ) {
            basketUp();
            $('#basket_order').hide();
            $('#basket_open').hide();
        }
	}

}

function basketUp() {
	basketbox('close','open');
}

function basketDown() {
	basketbox('open','close');
}

function basketbox(id1, id2) {
    $('#basket_'+id1).hide();
    $('#basket_'+id2).show();
    if ( id1 == 'open' ) { $('#basketbox-scroll').show(); } else { $('#basketbox-scroll').hide(); }
}
