$(document).ready(function() {

    $("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});

    $("#material, #objem, #vaha, #kategorie").easySelectBox();

    var $pausal = 440;
    var $pausal2 = 624;
    var $nakladka = 80;
    var $beton = [0, 120, 170, 300, 600];
    var $cihla = [0, 160, 200, 300, 400];
    var $asfalt = [0, 200, 200 ,200, 200];
    var $zemina = [0, 150, 200, 300, 400];
    var $pole = [$beton, $cihla, $asfalt, $zemina];
    var $vysledek = 0;
    var $vysledekdph = 0;

    $("#line3 li").hide();
    $("#line3 li:lt(7)").show();

    $("#line1 li:eq(1)").click(function() {
        $("#note1").html("<em>Omítky,zásypy plynu /atest/</em>");
    });
    $("#line1 li:eq(2)").click(function() {
        $("#note1").html("<em>Beton potěr</em>");
    });
    $("#line1 li:eq(3)").click(function() {
        $("#note1").html("<em>Beton hrubý /základy,věnce/</em>");
    });
    $("#line1 li:eq(0), #line1 li:eq(4), #line1 li:eq(5), #line1 li:eq(6), #line1 li:eq(7), #line1 li:eq(8), #line1 li:eq(8)").click(function() {
        $("#note1").html("<em></em>");
    });
    $("#line1 li:eq(10)").click(function() {
        $("#note1").html("<em>Obsypy kanalizací,zásyp </em>");
    });
    $("#line1 li:eq(11), #line1 li:eq(12), #line1 li:eq(13)").click(function() {
        $("#note1").html("<em>Základové desky,účelové komunikace</em>");
    });

    $("#line2 li:eq(0)").click(function() {
        $("#note2").html("");
        $("#line3 option:eq(0)").attr("selected", "selected");
        $("#line3 .easy-select-box-disp").html("0.5 T");
        $("#line3 li").hide();
        $("#line3 li:lt(7)").show();
        $pausal = 0;
        $pausal2 = 0;
        $nakladka = 0;
    });

    $("#line2 li:eq(1)").click(function() {
        $("#note2").html("<em>Kontejner MINI uveze zhruba 3,5 tuny materiálu)</em>");
        $("#line3 option:eq(0)").attr("selected", "selected");
        $("#line3 .easy-select-box-disp").html("0.5 T");
        $("#line3 li").hide();
        $("#line3 li:lt(7)").show();
        $pausal = 440;
        $pausal2 = 624;
        $nakladka = 80;
    });
    $("#line2 li:eq(2)").click(function() {
        $("#note2").html("<em>Kontejner MAXI uveze zhruba 9 tun materiálu</em>");
        $("#line3 option:eq(8)").attr("selected", "selected");
        $("#line3 .easy-select-box-disp").html("4 T");
        $("#line3 li").hide();
        $("#line3 li:gt(6)").show();
        $("#line3 li:gt(18)").hide();
        $pausal = 660;
        $pausal2 = 932;
        $nakladka = 100;
    });
    $("#line2 li:eq(3)").click(function() {
        $("#note2").html("<em>Kontejner MAXIPLUS uveze zhruba 18 tun materiálu</em>");
        $("#line3 option:eq(20)").attr("selected", "selected");
        $("#line3 .easy-select-box-disp").html("10 T");
        $("#line3 li").hide();
        $("#line3 li:gt(18)").show();
        $pausal = 820;
        $pausal2 = 1188;
        $nakladka = 100;
    });

    $("#pocitej1").click(function() {
        if($('#vzdalenost').val() <= 10) {
            $vysledek = Math.round(($('#material').val() * $('#vaha').val()) + $pausal);
        } else {
            $vysledek = Math.round(($('#material').val() * $('#vaha').val()) + (2 * $('#vzdalenost').val() * $('#objem').val()));
        }
        $vysledekdph = Math.round($vysledek * 1.2);
        $("#cena1").html($vysledek);
        $("#cena2").html($vysledekdph);
    });

    $("#pocitej2").click(function() {
        if($('#vzdalenost').val() <= 10) {
            $vysledek = Math.round(($pole[$('#material').val()][$('#kategorie').val()] * $('#vaha').val()) + $pausal2);
        } else {
            $vysledek = Math.round(($pole[$('#material').val()][$('#kategorie').val()] * $('#vaha').val()) + (4 * $('#vzdalenost').val() * $('#objem').val()) + $nakladka);
        }
        $vysledekdph = Math.round($vysledek * 1.2);
        $("#cena1").html($vysledek);
        $("#cena2").html($vysledekdph);
    });

});

