$(document).ready(function(){
        
    /* Fancybox */    
    $("a.lightbox").fancybox({
        'titleShow'     : false
    });
    
    $("a.do_kosiku").click(function(){
        var id = $(this).attr("id");
        var pocet = parseInt($('#hkosik').attr("class")) + parseInt(1);
        //the main ajax request
        $.ajax({
            type: "POST",
            data: "id="+$(this).attr("id")+"&pocet="+$('#pocet_kusu').val(),
            url: "/e-shop/do-kosiku.php",
            success: function(msg)
            {
                $('#systemMessages').html(msg);
                $('#systemMessages').hide().slideDown(200).animate({opacity: 0.2}, 200).animate({opacity: 1}, 200);
                setTimeout(function(){
                    $('#systemMessages').hide().slideUp(200).animate({opacity: 0.2}, 200).animate({opacity: 1}, 200);
                }, 4000);
                
                $('#hkosik').html('<a href="/e-shop/kosik/">Košík (' + pocet + ')</a>');
            }
        });
   	});
    
    
    $("#show_adress").click(function(){
        $('#zbozi_jinam').toggle();
   	});
    
    
    
    $('#systemMessage').hide().slideDown(200).animate({opacity: 0.2}, 200).animate({opacity: 1}, 200);
    $.scrollTo($("#systemMessage"),200,{easing:'easein'});
    $('span.closeSystemMessage a').click(function(){$("#systemMessage").slideUp(100);return false;});
});

function showSystemMessage(message, type) {
    if(!type) type = 'warning';
    var html = '<div id="systemMessage" class="' + type + '"><span class="closeSystemMessage"><a href="#">x</a></span><ol>' + message + '</ol></div>';
    $('#messageBox').html(html);
    $('#systemMessage').hide().slideDown(200).animate({opacity: 0.2}, 200).animate({opacity: 1}, 200); 
    $('span.closeSystemMessage a').click(function(){$("#systemMessage").slideUp(100);return false;});
    $.scrollTo($("#messageBox"),200,{easing:'easein'});
}

function showSystemAlert(message, type)
{
    if(!type) type = 'warning';
    var html = '<div id="systemAlert" class="sa' + type + '"><span class="closeSystemMessage"><a href="#">x</a></span><ol>' + message + '</ol></div>';
    $('#messageBox').html(html);
    $('#systemAlert').hide().slideDown(200).animate({opacity: 0.2}, 200).animate({opacity: 1}, 200).animate({opacity: 1}, 10000).slideUp(100); 
    $('#systemAlert').click(function(){$(this).stop();});
    $('span.closeSystemMessage a').click(function(){$(this).stop();});
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    num = Math.floor(num/100).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+' '+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '' + num);
}

