$(document).ready(function(){

    function format(expr, deplaces) {
                var str = "" + Math.round(eval(expr) * Math.pow(10, deplaces));
                while (str.length <= deplaces) {
                    str = "0" + str;
                }
                var decpoint = str.length - deplaces;
                return str.substring(0, decpoint) + " p. " + str.substring(decpoint, str.length) + " \u043a." ;
    }

    $('.menu_item_count').click(function(){
        $(this).select();
    });
    $('.menu_item_count').keyup(function(){

        var itemCount = parseInt($(this).val());
        itemCount = isNaN(itemCount) ? 0 : itemCount;
        $(this).val(itemCount);
        var sumItemPrice = $(this).prev().val() * $(this).val();
        $(this).next().val(sumItemPrice);
        $(this).parent().prev().html(format(sumItemPrice, 2));
        var resultPrice = 0;
        $.each($('.menu_item_sum_price_float'), function() { resultPrice += Math.abs($(this).val()) });
        $('#result_price').html(format(resultPrice, 2));
        $('#indent_price').val(resultPrice);
    });


    $('.img_to_full_recipe').hover(function() {
        $(this).css('top', '-3px');
        $("div.link_to_full_recipe > a[id='"+this.id+"']").css('text-decoration', 'underline');
    },function() {
        $(this).css('top', '-2px');
        $("div.link_to_full_recipe > a[id='"+this.id+"']").css('text-decoration', 'none');
    });
    $('.link_to_full_recipe > a').hover(function() {
        $(this).css('text-decoration', 'underline');
        $('div.img_to_full_recipe#'+this.id).css('top', '-3px');
    },function() {
        $(this).css('text-decoration', 'none');
        $('div.img_to_full_recipe#'+this.id).css('top', '-2px');
    });

    $(".img_to_full_recipe a").fancybox({'frameWidth': 630, 'frameHeight': 440 });
    $(".link_to_full_recipe a").fancybox({'frameWidth': 630, 'frameHeight': 440 });

    $('select[name=to_date]').change(function(){
      window.location = $(this).prev().val() + '?to_date=' + $(this).val();
    });
});