window.afterInitTable = function() {
    tableUrl = function() {
        return tableController() + tableAction() + "/" + $('#id').val();
    };
    inittable();
};

$(document).ready(function() {
    $('body').on('jsp-scroll-x', '#scrollerclone', function() {
        var clonePositionLeft = $('div.jspPane').css('left');
        $('div#tablescroller').css('left', clonePositionLeft);
    });
    $(window).bind("resize", function() {
        setScrollWidth($('#tableholder').width() - $('td#fixedblock').width());
        $('#floatingblock').width($('#tableholder').width());
        $('div#scrollerclone').data('jsp').scrollTo(0,0);
    });
    if ($.browser.msie) {
        $('#tableholder').css('margin-top', '22px');
        $('#floatingblock').find('#fixedblock').width($('#tableholder').find('#fixedblock').width());
    }
});

function inittable() {
    $('div#scroller').width($('div#tableholder').width() - $('td#fixedblock').width());
    $('div#scrollerclone').width($('div#tableholder').width() - $('td#fixedblock').width());
    $('tbody#fixedcols tr').each(function() {
        var rowid = $(this).attr("rowid");
        var maxheight = 0;
        $('td[rowid=' + rowid + ']').each(function() {
            if ($(this).height() > maxheight) maxheight = $(this).height();
        });
        $('td[rowid=' + rowid + ']').each(function() {
            $(this).height(maxheight + 11);
        });
    });
    showHeader();
    var $bar = $('div.jspHorizontalBar');
    $bar.css("position", "relative").css("z-index", "2");
    //плавающие заголовок таблицы и прокрутка
    $('#floatingblock').css('top', '0px');
    $('#floatingblock').css('position', 'fixed');
}

function showHeader() {
    $('#floatingblock').width($('#tableholder').width());
    if ($.browser.mozilla) {
        $('#floatingblock').height($('#leftheader th:first').height() + 64);
    }
    else {
        $('#floatingblock').height($('#leftheader th:first').height() + 65);
    }
    $('#scrollerclone').jScrollPane();
    $('div.jspDrag').append('<img class="scroll-icon" src="img/scroll-icon.png"/>');
    if (!$.browser.safari) {
        setScrollWidth($('#tableholder').width() - $('td#fixedblock').width());
    }
    $('.jspPane').css('width', '100%');
    $('.jspVerticalBar').remove();
    if ($.browser.safari)
    { $('.jspDrag').width($('.jspDrag').width() - 2); }
}

function setScrollWidth(width) {
    $('div#scrollerclone').width(width);
    $('div#scroller').width(width);
    $('div.jspContainer').width(width);
    $('div#scrollerclone').data('jsp').ReinitScrollerH(width);
    $('.jspPane').css('width', '100%');
}