var offsets = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]];

//////////////////////////////////////////////////////////////////////
/////// ============= IA?AEI ?AAAEOE?OAIIE ?ANOE ============= ///////

//  Iano?ieea iiceoee auiaaa?ueo iai?
//  Ia?aay oeo?a oeacuaaao aey eaeiai o?iaiy i?iecaiaeony iano?ieea
//  Aoi?ay oeo?a:  1 - neaaa;  2 - naa?oo.

  offsets[1][1] = 0;     // ionooi neaaa
  offsets[1][2] = 0;       // ionooi naa?oo

  offsets[2][1] = 0;     // ionooi neaaa
  offsets[2][2] = 0;       // ionooi naa?oo

  offsets[3][1] = 9;      // ionooi neaaa
  offsets[3][2] = 2;       // ionooi naa?oo

  offsets[4][1] = 7;      // ionooi neaaa
  offsets[4][2] = 4;       // ionooi naa?oo

  offsets[5][1] = -20;      // ionooi neaaa
  offsets[5][2] = 15;       // ionooi naa?oo


//  Iano?ieea noeeae ioieoia iai? i?e auaaeaiee

function highlight(elem){
  if(elem){

     // elem.className = "bg";
     elem.style.backgroundColor="#6263FF";
    
  }
}

function lowlight(elem){
  if(elem){

    //  elem.className = "nobg";
     elem.style.backgroundColor="";

  }
}

/////// ============= EIIAO ?AAAEOE?OAIIE ?ANOE ============== ///////
//////////////////////////////////////////////////////////////////////



closing=[]  // oaeiaoou

function getPageOffset(o, level){
  var menu_level = level+1;

  var KL_left=offsets[menu_level][1];
  var KL_top=offsets[menu_level][2];

  do{
    KL_left+=o.offsetLeft
    KL_top+=o.offsetTop
  }while(o=o.offsetParent)

  // correction filters for different browsers
  if (isOpera && menu_level>3){
      KL_top = KL_top - 6;
  }

  return [KL_left, KL_top]
}

function show_menu(id, offsetparent, level){
  dd=document.getElementById('dropdown_menu_'+id)
  if(!dd) return

  cancel_close(id)

  offset=getPageOffset(offsetparent, level)
  if(dd.offsetHeight+offset[1] > getWindowHeight()+getScrollY()){
    offset[1]=getWindowHeight()+getScrollY()-dd.offsetHeight
  }

  dd.style.left=(offset[0]+offsetparent.offsetWidth-10)+"px"
  dd.style.top=offset[1]+"px"


  dd.style.visibility="visible"

  //highlight parent
  //setTimeout("highlight(document.getElementById('item_"+id+"'))",10)

}
//===================================
function show_menu1(id, offsetparent, level){
  dd=document.getElementById('dropdown_menu_'+id)
  if(!dd) return

  cancel_close(id)

  offset=getPageOffset(offsetparent, level)
  if(dd.offsetHeight+offset[1] > getWindowHeight()+getScrollY()){
    offset[1]=getWindowHeight()+getScrollY()-dd.offsetHeight
  }

  dd.style.left=(offset[0]+offsetparent.offsetWidth)-120+"px"
  dd.style.top=offset[1]+18+"px"
  
//  dd.style.bottom=160
// dd.style.top=(offset[0]+offsetparent.offsetWidth+150)+"px"

  dd.style.visibility="visible"

 
  //setTimeout("highlight(document.getElementById('item_"+id+"'))",10)

}




//===================================

//===================================
function show_menu11(id, offsetparent, level){
  dd=document.getElementById('dropdown_menu_'+id)
  if(!dd) return

  cancel_close(id)

  offset=getPageOffset(offsetparent, level)
  if(dd.offsetHeight+offset[1] > getWindowHeight()+getScrollY())
  {
    offset[1]=getWindowHeight()+getScrollY()-dd.offsetHeight
  }
else
  offset[1]=getWindowHeight()+getScrollY()-23

  dd.style.left=(offset[0]+offsetparent.offsetWidth-120)+"px"
  dd.style.top=offset[1]-46+"px"
  
//  dd.style.bottom=160
// dd.style.top=(offset[0]+offsetparent.offsetWidth+150)+"px"

  dd.style.visibility="visible"

 
  //setTimeout("highlight(document.getElementById('item_"+id+"'))",10)

}




//===================================



//===================================
function show_menu2(id, offsetparent, level){
  dd2=document.getElementById('dropdown_menu_'+id)
  if(!dd2) return

  cancel_close(id)

  offset=getPageOffset(offsetparent, level)
  
//  if(dd2.offsetHeight + offset[1] < getWindowHeight()+getScrollY())
//  {
 
 
	//  iaeaiueee 
	offset[1]=getWindowHeight()+getScrollY()-dd2.offsetHeight-53
	
	
// }
  

  

  dd2.style.left=(offset[0]+offsetparent.offsetWidth)-120+"px"
  dd2.style.top=offset[1]+"px"
  
//  dd.style.=160
// dd.style.top=(offset[0]+offsetparent.offsetWidth+150)+"px"

  dd2.style.visibility="visible"

 
  //setTimeout("highlight(document.getElementById('item_"+id+"'))",10)

}




//===================================



function cancel_close(id){
  ids=id.split('__')
  id=''
  for(var i=0;i<ids.length;i++){
    id+="__"+ids[i]
    clearTimeout(closing[id.substring(2)])
  }
}

function hide_menu(id){
  menus=document.getElementsByTagName('div');
  for(var i=0;i<menus.length;i++){
    var id=menus[i].id
    if(id.indexOf('dropdown_menu_')==0){
      id=id.substr(14)
      clearTimeout(closing[id])
      closing[id]=setTimeout('hide_menu2("'+id+'")',1)
    }else{
      highlight(document.getElementById('item_'+id))
    }
  }
}

function hide_menu2(id){
  dd=document.getElementById('dropdown_menu_'+id)
  if(!dd) return
  dd.style.visibility="hidden"
  lowlight(document.getElementById('item_'+id))
}
