function showFilesChilderen( cfileid ) {
    var disp = window.document.getElementById( 'fch' + cfileid );
    var pdisp = window.document.getElementById( 'fa' + cfileid );
    if ( disp != null && pdisp != null ) {
        if ( disp.style.display == 'none' ) {
            disp.style.display = 'block';
            pdisp.style.background = 'url(/images/ru/tms/menu_left_li_item_o.jpg) no-repeat 0% 2px';
        } else {
            disp.style.display = 'none';
            pdisp.style.background = 'url(/images/ru/tms/menu_left_li_item.jpg) no-repeat 0% 2px';
        }
    }
    return false; // чтобы ссылка не срабатывала
}

var pops_opened = new Array();

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            return true;
        }
    }
    return false;
}

//Функции для левого меню (в menu.xsl)
function showLeftSubmenu( liid, level ) {
    var scroll1 = $(document).height();
    while ( pops_opened.length >= level + 1 ) {
        pops_opened.pop();
    }
    pops_opened.push( liid );
    var scroll1 = $(document).height();
    $('.popup_menu').each( function() {
        //if ( pops_opened.in_array( $(this).attr('id').replace(/\D+/g,'') ) ) {
        if ( pops_opened[ $(this).attr('id').replace(/^\D+(\d+)_\d+/g,'$1') ] == $(this).attr('id').replace(/^\D+\d+_/g,'') ) {
            $(this).show();
            var scroll2 = $(document).height();
            var diff_h = scroll2 - scroll1;
            if ( diff_h > 0 ) { $(this).offset({top:($(this).offset().top - diff_h),
                                                left:($(this).offset().left)}); } //смещение влево возникает из-за мелькнувшей полосы прокрутки страницы
        } else {
            $(this).hide();
        }
    });
}
function hideLeftSubmenu( liid ) {
    if ( $('#pop' + liid)[0] ) {
        $('#pop' + liid).hide();
    }
}

function getClientWidth() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

jQuery.fn.center = function() {
    var w = $(window);
    this.css("position","absolute");
    this.css("top",(getClientHeight()-this.height())/2 + $(window).scrollTop() + "px");
    this.css("left",(getClientWidth()-this.width())/2 + $(window).scrollLeft() + "px");
    return this;
}

function showBigImage( imgid ) {
    if ( ! $( '#dialogimg' + imgid ).is( ':visible' ) ) {
        $( '#dialogimg' + imgid ).show().center();
    } else {
        $( '#dialogimg' + imgid ).hide();
    }
}

function stylizeTables() {
    //content_table заменён на description
    /*$('.description table tr:odd').removeClass('dark_tr').addClass('dark_tr');
    $('.description table tr:first').css('borderTop','none');
    $('.description table tr:last').css('borderBottom','none');
    $('.description table tr').each( function() {
        $(this).find('td:first').css('borderLeft','none');
        $(this).find('td:last').css('borderRight','none');
        $(this).find('th:first').css('borderLeft','none');
        $(this).find('th:last').css('borderRight','none');
    });
    $('.description table tr').hover(function(){
        $(this).addClass('hovered');
    }, function(){
        $(this).removeClass('hovered');
    });*/
    $('.description table').each( function() {
        $(this).find('tr:odd').removeClass('dark_tr').addClass('dark_tr');
        $(this).find('tr:first').css('borderTop','none');
        $(this).find('tr:last').css('borderBottom','none');
        $(this).find('tr').each( function() {
            $(this).find('td:first').css('borderLeft','none').css('textAlign','left');
            $(this).find('td:last').css('borderRight','none');
            $(this).find('th:first').css('borderLeft','none');
            $(this).find('th:last').css('borderRight','none');
        });
        $(this).find('tr').hover(function(){
            $(this).addClass('hovered');
        }, function(){
            $(this).removeClass('hovered');
        });
    });
        
    
}

function printFragment( fragmentSelector ) {
    w=window.open();
    w.document.write($(fragmentSelector).html());
    w.print();
    w.close();
}


$(document).ready(function() {
    //replaceDdownSelects();
    //$( 'select' ).select_skin();
    //$( '.big_picture' ).click( function() { $( this ).hide(); } );
    stylizeTables();
    $(function(){
        $(".div1").css('width',$(".div2").width()+20);
        $(".wrapper1").scroll(function(){
            $(".wrapper2")
            .scrollLeft($(".wrapper1").scrollLeft());
        });
        
        if ($(".div2").width() < 650) {$(".wrapper1").hide();}
        $(".wrapper2").scroll(function(){
            $(".wrapper1")
            .scrollLeft($(".wrapper2").scrollLeft());
        });
    });
    $( '.big_picture' ).click( function() { $( this ).hide(); } );
    $(document).click( function() { $('.popup_menu').hide() } );
});

function showBigImage( imgid ) {
    if ( ! $( '#dialogimg' + imgid ).is( ':visible' ) ) {
        $( '#dialogimg' + imgid ).show().center();
    } else {
        $( '#dialogimg' + imgid ).hide();
    }
}
