//---------------------------------------------------------------
var d=document
var NN=d.layers?true:(window.opera&&!d.createComment)?true:false
var preHash = window.location.hash;
var preNews = '';
var hashTimer;
//---------------------------------------------------------------

function menuinit() {
    $('#menu li div').click(function() {
        var el = $(this).next();
        var href = $(this).children('a').attr('href');
        var dirType = $(this).children('a').attr('rel');
        if((el.is('ul')) && (el.is(':visible'))) return false;
        if((el.is('ul')) && (!el.is(':visible'))) {
            //Первый уровень
            if(el.attr('class')=='lvl0') {
                $('#menu .lvl0:visible').slideUp('normal');
                el.slideDown('normal', function(){
                    if(dirType!='static') window.location = href;                
                });
            }
            //Второй уровень
            if(el.attr('class')=='lvl1') {
                $('#menu .lvl1:visible').slideUp('normal');
                el.slideDown('normal', function(){
                    //if(dirType!='static') window.location = href;
                    return false;                
                });
            }            
            return false;            
        }
    });    
    $('#menu li div a').click(function() {   
         var el = $(this).parent().next();
         if(el.attr('class')=='lvl0') {
            $('#menu .lvl0:visible').slideUp('normal', function(){                     
                return true;
            });
         }
         if(el.attr('class')=='lvl1') {
            $('#menu .lvl1:visible').slideUp('normal', function(){                     
                return true;
            });
         }         
         
    });    
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    if(!title) title='';
    if(title=='Скачать файл' || title=='Открыть файл') title='';
    if(preNews!='') title = preNews;
    preNews = '';
    return '<div><table width="100%" cellpadding="0" cellspacing="0"><tr><td width="100%" align="left">'+title+'</td><td valign="top" align="right"><a href="javascript:;" onclick="$.fancybox.close();"><img height="22" border="0" src="/p/closelabel.gif" /></a></td></tr></table></div>';
}

function onChangeHash(){  
    if(preHash!=window.location.hash) {
        hash = window.location.hash;
        if(pos=hash.search('#action=')!=-1) ajax_location(hash.substring(pos+7), true);  
    }
    preHash = window.location.hash;
    hashTimer = setTimeout(onChangeHash, 500);    
}

function ajax_location(url, changeHash){
    var content = '';
    $.ajax({
        url: url,
        timeout: 5000,
        beforeSend: function(){ 
            clearTimeout(hashTimer);
        },
        complete: function(){
                if(content.search('<!-- AJAX PAGE -->')!=-1) $('.content_text').html(content);
                else $('.content_text').html('<b>Ошибка</b><br>Действие не может быть выполнено.');                
                if(changeHash) window.location.hash = 'action='+url;
                preHash = window.location.hash;
                onChangeHash();
        },
        success: function(data){
            content = data;
        },
        error: function(){
            $('.content_text').html('<b>Ошибка</b><br>Сервер не отвечает, попоробуйте позже.');             
        }
    });
    return false;        
}   

function showTime(){
 var tmN=new Date()
 var dH=''+tmN.getHours(); dH=dH.length<2?'0'+dH:dH
 var dM=''+tmN.getMinutes(); dM=dM.length<2?'0'+dM:dM
 var dS=''+tmN.getSeconds(); dS=dS.length<2?'0'+dS:dS
 var tmp=dH+':'+dM+':'+dS;
 if(NN) d.F.chas.value=tmp; else jQuery('#timenow').html(tmp);
 var t = setTimeout('showTime()',1000)
}

jQuery(function(){ 
    showTime();
    $('input[type=checkbox]').css('border','');
    menuinit();    
}); 
