var m_id=[0];
var m_ind=[0];
var timer_id=null;
var MenuTimeOut=500;

function m_over(m_id1,m_id2)
{
    m_rtimer();
	 
    if (m_ind[m_id1]!=null)
        hide_ms(m_ind[m_id1]+1);

    if (m_id2!=0) {
      m_visibility(m_id2,'visible');
      m_ind[m_id2]=m_id.length;
      m_id[m_id.length]=m_id2;
    }
    
}

function m_out() {
 
    if (timer_id!=null) {
      return;
    }
    if (m_id.length==1) {
      return;
    }

    timer_id=setTimeout('m_hide()',MenuTimeOut);        
}

function m_in()
{
    m_rtimer();
}

function m_hide() {
  
  if (m_id.length>2) {
    hide_ms(m_id.length-1);
    timer_id=setTimeout('m_hide()',MenuTimeOut);
  }
  else {
    hide_ms(1);
    timer_id=null;
  }
}

function hide_ms(i) {
  var j;
  
  for(j=m_id.length-1;j>=i;j--) {
    m_ind[m_id[j]]=null;
    m_visibility(m_id[j],'hidden');
    //reset_over(m_id[j]);
  }    
  m_id.length=i;
}

function m_visibility(id,visibility)
{
    if (document.getElementById)
	document.getElementById('menu'+id).style.visibility=visibility;
    else
        document.all['dropmenu'+id].style.visibility=visibility;
    
	if(visibility=="visible") document.getElementById("m"+id).bgColor="#304A8B";
	if(visibility=="hidden") document.getElementById("m"+id).bgColor="#AFADA1";
}

function m_rtimer()
{
    if (timer_id!=null)
    {
	clearTimeout(timer_id);
	timer_id=null;
    }
}

function m_do_hide()
{
    m_rtimer();
    m_hide();
}

document.onclick=m_do_hide;

function getPosition(obj,id) {
    var o=obj; 
	o=o.offsetParent;
    var x=0, y=0; 
    while(o) { 
        x+=o.offsetLeft; 
        y+=o.offsetTop; 
        o=o.offsetParent; 
    } 
	
	obj=obj.offsetParent;
	//alert("x="+x+" y="+y);
	
	document.getElementById(id).style.left=x+"px";
	document.getElementById(id).style.top=(y+30)+"px";
	document.getElementById(id).style.width=obj.offsetWidth+"px";
}



function place_image(url,descr)
{ if(document.getElementById('photo')) document.getElementById('photo').src=url;
  if(document.getElementById('photo_description')) document.getElementById('photo_description').innerText=descr;
}