var t=0;
var sh=0;
var ids;
var timerId; 
function getPosition(o)
    {
    var x=y=0;
    while(o)
        {
        x+=o.offsetLeft;
        y+=o.offsetTop;
        o=o.offsetParent;
        }
    return[x,y];
    }
function show_sub_menu(id)
    {
    close_all();
    var c=getPosition(document.getElementById(id+'_check'))
    var x=c[0]
    var y=c[1]
    document.getElementById(id).style.left=x;
    document.getElementById(id).style.top=y+18;
    document.getElementById(id).style.display='';
    }
function hide_sub_menu(id)
    {
    ids=id;
    if(t==0)
        {
        timerId=setTimeout('hide_sub_menu_ex()',200);
        //document.getElementById('res').innerHTML+='t=1{35}, '; 
        t=1;
        }
    //document.getElementById('res').innerHTML+='sh=0{37}, ';
    sh=0;    
    }
function hide_sub_menu_ex()
    {
    //document.getElementById('res').innerHTML+='';
    if(sh==0&&t==1)
        { 
        //document.getElementById('res').innerHTML+='close, '; 
        document.getElementById(ids).style.display='none';
        }
    //document.getElementById('res').innerHTML+='t=0{49}, ';
    t=0;
    } 
function clear_timer()
    {
    //document.getElementById('res').innerHTML+='sh=1{54}, ';
    sh=1;
    try
        {    
        timerId.clearTimeout();
        }
    catch(e)
        {}
    //document.getElementById('res').innerHTML+='t=1{62}, ';
    t=1;
    }
function close_all()
    {
    var divs=document.getElementsByTagName('div');
    var len=divs.length;
    for(i=1;i<len;i++)
        {
        re=/^sm/;
        idc=divs[i].id;
        if(re.test(idc))
            {
            document.getElementById(idc).style.display='none';
            }  
        }
    }
var changeph;
function prev_photo()
    {
    changeph=parseInt(cur_photo)-1;
    if(changeph<0)
        {
        changeph=photos.length-1;
        }
    anim_up();
    }
function next_photo()
    {
    changeph=parseInt(cur_photo)+1;
    if(changeph>photos.length-1)
        {
        changeph=0;
        }
    anim_up();
    }
function anim_up()
    {
    document.getElementById('wblock').style.display='';
    op=document.getElementById('wblock').style.opacity;
    nop=parseFloat(op)+0.2;
    if(nop<=1)
        {
        document.getElementById('wblock').style.opacity=nop;
        document.getElementById('wblock').style.filter='alpha(opacity = '+nop*100+')';
        setTimeout('anim_up()',100);
        }
    else
        {  
        document.getElementById('prel').style.display=''; 
        change_img();
        }
    }
function change_img()
    {
    document.getElementById('testimg').src='dataimg/gallery/'+photos[changeph];
    //document.getElementById('imaga').style.display='none';
    document.getElementById('cur_img').innerHTML=changeph+1;
    cur_photo=changeph; 
    document.getElementById('testimg').onLoad=change_img_ex();   
    }
function change_img_ex()
    {
    if (document.getElementById('testimg').complete == true) 
        {
        timerId=setTimeout('change_img_ex2()',500);
        }
    else
        {
        timerId=setTimeout('change_img_ex()',200);
        }
    }
function change_img_ex2()
    {
    h=document.getElementById('testimg').height+2;
    document.getElementById('wblock').style.height=h+'px'; 
    document.getElementById('imaga').src='dataimg/gallery/'+photos[changeph];
    //document.getElementById('imaga').style.display='';
    document.getElementById('prel').style.display='none';
    anim_down();
    }
function anim_down()
    {
    op=document.getElementById('wblock').style.opacity;
    nop=parseFloat(op)-0.2;
    if(nop>=0.2)
        {
        document.getElementById('wblock').style.opacity=nop;
        document.getElementById('wblock').style.filter='alpha(opacity = '+nop*100+')';
        setTimeout('anim_down()',100);
        }
    else
        {
        document.getElementById('wblock').style.display='none';
        }
    }