function calcHeight(el){
    return $(el).outerHeight() + parseInt($(el).css('margin-top').replace('auto', 0)) + parseInt($(el).css('margin-bottom').replace('auto', 0));
}

$(function() {

    $('.topmenu-item')
        .mouseenter(function(){$('.direction-menu',this).stop(true,true).slideDown()})
        .mouseleave(function(){$('.direction-menu',this).stop(true,true).delay(400).slideUp()})
    
    // calculating and setting actual width for delimiters in topmenu
    var sumwidth = 0;
    $('.topmenu-item').each(function(){sumwidth += $(this).outerWidth()});
    var delimiterwidth = ($('#container-topmenu').width()-sumwidth)/$('.topmenu-delimiter').length - 3;
    $('.topmenu-delimiter').width(delimiterwidth);
    
    var direction_menu_count = $('.direction-menu').length;
    var parentOffsetTop = $('.direction-menu').eq(0).parent().offset() ? $('.direction-menu').eq(0).parent().offset().top : 0;
    $('.direction-menu').each(function(index){
        if(index > 0){
            var left = ($(this).parent().outerWidth()-$(this).outerWidth())/2+4;
            $(this).css('left',left);
        }
        if(index == direction_menu_count - 1)$(this).css('left',left - 30);

        if($(this).parent().offset().top > parentOffsetTop)
            $(this).css('top', (parseInt($(this).css('top')) - $(this).parent().offset().top + parentOffsetTop) + 'px');
    });

    // --------------------- JUSTIFYING COLUMNS (LEFT, MIDDLE AND CONTENT) -----------------------------------------------------

    if($.browser.msie){// танцы с бубном
        // уменьшение непонятно откуда взявшейся огромной ширины блока контента
        $('#container-content').width($(window).width()-$('#container-left').width()-$('#container-middle').width()-74);
        // куда то пропала минимальная высота контента
        if($('#main-dir-index').height()<parseInt($('#main-dir-index').css('min-height')))
            $('#main-dir-index').height(parseInt($('#main-dir-index').css('min-height')));
        // ну это просто сказка, если убрать, у контента справа пропадет пикселов 74))
        $('#container-content').width($('#container-content').width()+65);
        $('.content-header').width($('#container-content').width());
    }

    var maxHeight = Math.max($('#container-middle').outerHeight(),$('#container-content').outerHeight());

    $('#container-left-float').height(maxHeight-$('#container-left').outerHeight()+$('#container-logo').outerHeight());
    $('#container-middle-float').height(maxHeight-$('#container-middle').outerHeight());
    $('#container-content-float').height(maxHeight-$('#container-content').outerHeight());
    
    if($.browser.msie){// танцы с бубном
        if($('#container-middle').hasClass('container-middle-2')){
            $('#container-left-float').height($('#container-left-float').height()+21);
            $('#container-middle-float').height($('#container-middle-float').height()+17);
        }else{
            if($('#container-content').height() < $('#container-middle').height())
                $('#container-content-float').height($('#container-content-float').height()+37)
            else $('#container-content-float').height($('#container-content-float').height()+5);
            if($.browser.version == 6){
                if($('#container-content').height() > $('#container-middle').height())
                    $('#container-content-float').height($('#container-content-float').height()-20)
                else $('#container-content-float').height($('#container-content-float').height()+5);
            }
        }
    }

    // --------------------- END OF JUSTIFYING COLUMNS (LEFT, MIDDLE AND CONTENT) ----------------------------------------------
    
    // align top-menu selected item name
    if($('#td_icap').width() < $('.topmenu-item-name').width() && $('.topmenu-item').eq(0).attr('id') != 'td_icap')
        $('.topmenu-item-name').css('margin-left',($('#td_icap').width()-$('.topmenu-item-name').width())/1.6);
    
    // start page adjustment
    $('#container-elephant').css('margin-left',($('body').width()-250)/2.5);
    $('#mainpage-float').height($(window).height()-$('#layout').height()+20);
    
    
    
});

$('#feedback-box').ready(function(){
    $('#feedback-box').load('/injection/'+$('#feedback-box').text()).show();
});

function sendEMail(){
    var res=true;

    var error = check();
    if(error)alert(error);
    else{
        
        $("#formBody")
            .after('<div id="formAnswer" style=""><img alt="" src="/img/ajax-loader.gif" /><br/>Пожалуйста подождите, идет отправка...</div>')
            .hide();
            
        $("#callbackForm").ajaxSubmit(function(data){
            $("#formAnswer").html(data);
        });
    }

}
function show_ipwhois(){
    var obj = document.getElementById("show_ipwhois");if (obj.style.display == "none") obj.style.display = "";else obj.style.display = "none";return false;
}




