//==============================================================================
//
//     Copyright (c) 2006, by Deluxe-Menu.com
//     http://deluxe-menu.com
//
//==============================================================================

d_o.write('<div id="dmAD" style="position:absolute;cursor:default;width:60px;display:none;padding:2px;z-index:999999;border:solid 1px #AAAAAA;background-color:#FFFFFF;font:normal 12px Tahoma,Arial;color:#000000">Loading...</div>');

var dmDataLoadTimer=null;
var dmAD;

function dm_downloadSubmenu(parentID)
{
  if (dmDataLoadTimer)
    clearInterval(dmDataLoadTimer);

  // Reset menuItems variable before load new submenu from server
  menuItems = null;
  var scr, sid='dmScr';

  // Remove existent <script>
  if (scr=dm_gE(sid)) docElement.removeChild(scr);

   // Create new <script>, assign ID and SRC attributes
  scr = d_o.createElement('SCRIPT');
  scr.id  = sid;
  scr.src = dm_getVarByID(parentID).ajax;
  docElement.appendChild(scr);


  dmAD = dm_gE('dmAD');
  var itSize = dm_getObjectSize(dm_getObjectByID(parentID+'tbl'));
  with (dmAD.style)
  {
      left    = itSize[0] + 'px';
      top     = itSize[1]+itSize[3] + 'px';
      display = '';
  }

  // Wait for new data loading or create new submenu instantly
  if (!menuItems) dmDataLoadTimer = setInterval('dm_createSubmenu("'+parentID+'")', 50);
  else
      dm_createSubmenu(parentID);
}


function dm_createSubmenu(parentID)
{       
  window.status = 'Menu data loading...';
  if (!menuItems) return;

  clearInterval(dmDataLoadTimer);
  dmDataLoadTimer    = null;
  window.status      = '';
  dmAD.style.display = 'none';
  

  var itVar = dm_getVarByID(parentID);
  var menu  = dm_menu[itVar.mInd];
  var smVar = menu.m[itVar.smInd];

  // Create submenu and items params using new loaded data
  for (var i=0; (i<menuItems.ln() && typeof(menuItems[i])!=_un); i++)
  {
      if (!i) dm_createSubmenuParams(menu, smVar, itVar, menuItems[i][7]);

      curMenu.itInd = curMenu.smVar.i.ln();                                     // set current item index
      dm_createItemParams(menu, curMenu.smVar, curMenu.itInd, menuItems[i], statusString);
  }

  itVar.childID = curMenu.smVar.id;

  // Show new loaded submenu
  if (itVar.isHighlighted)
    dm_showMenu(itVar.childID, parentID);
}
