//==============================================================================
//
//     Copyright (c) 2006, by Deluxe-Menu.com
//     Version 2.0
//     http://deluxe-menu.com
//
//==============================================================================

Array.prototype.ln=function() {return this.length}
with (String)
{
  prototype.sb=function(s,e) {return this.substring(s,e)}
  prototype.io=function(s)   {return this.indexOf(s)}
  prototype.ln=function()    {return this.length}
}


var b_IE    = 0;
var b_IE5   = 0;
var b_IE6   = 0;
var b_IEPC  = 0;
var b_IEMAC = 0;
var b_NS    = 0;
var b_NS4   = 0;
var b_NS6   = 0;
var b_OP    = 0;
var b_MZ    = 0;
var b_DOM   = 0;
var b_MAC   = 0;
var b_IEComp= 0;
var b_SAF   = 0;
var b_VER   = 0;
var d_o     = document;
var _un     = 'undefined';
var dmZOrder = 1000;

dm_getBrowser();


//##############################################################################
var addedScripts = [];
if (typeof(dmWorkPath)==_un) var dmWorkPath = '';

function dm_addScript(fname)
// Includes additional script files
{
  for (var i=0; i<addedScripts.ln(); i++) if (addedScripts[i]==fname) return;
  addedScripts[addedScripts.ln()] = fname;
  d_o.write('<SCR'+'IPT SRC="'+dmWorkPath+fname+'.js" type="text/javascript"></SCR'+'IPT>');
}

if (b_NS4) dm_addScript('dmenu4');
//##############################################################################

// Create style for special <DIV id="dmlinks"> where menu links are placed (for search engines)
d_o.write('<style>#dmlinks{display:none}</style>');


var dUnits = 'px';                               // units
var docElement;                                  // Document object variable depending on <!DOCTYPE> tag. Used as document.body object.
var fdocElement;                                 // Document object variable in a frame depending on <!DOCTYPE> tag. Used as document.body object of a frame.
var userLoadFunc = null;                         // Variable to remember user's onLoad event
var assignFloating = 0;
var assignMoving   = 0;

var dm_menu   = [];                              // Main menu object
var isLoaded  = 0;                               // Are submenus loaded
var regexp_m  = /dm([0-9]+)m([0-9]+)/;           // Mask to extact indexes from menu id
var regexp_i  = /dm([0-9]+)m([0-9]+)i([0-9]+)/;  // Mask to extact indexes from item id


var curMenu =
{
  ind  : 0,    	        // index of current processed menu
  smInd: 0,         	  // index of current processed submenus
  itInd: 0,   		      // index of current processed item
  smVar: null,          // current submenu variable
  itVar: null           // current item variable
}


var moveRec =
{
  isMoving   : 0,       // if the menu is in a moving process
  prepareSmID: '',
  cX      : 0,          // capturing X coord
  cY      : 0,          // capturing Y coord
  smObj   : 0,          // current movable submenu object
  smVar   : null        // current movable submenu variable
}


var toggleRec =
{
   pressedSelf    : 0,   // script sets pressed item, not user
   changeStyleOnly: 0    // change item style only
}


var keyMode =
{
  isEnabled : 0,             // keystokes are activated
  menu      : null,          // menu object
  rsmVar    : null,          // root submenu variable
  ritVar    : null,          // root items variable
  smVar     : null,          // submenu variable
  itVar     : null           // item variable
}


// Cross-frame mode ############################################################
var cfEnabled      = 0;
var cfFsetID       = '';
var cfMFrameInd    = 0;
var cfSFrameInd    = 1;
var cfOrientation  = 0;
var cfType         = 1;  // values: 1 - standard cross-fame mode
                         //         3 - standard cross-fame mode + submenus resize main frame when subframe isn't ible (IE only)
var oldFsetSizes;        // variable to remember frames dimensions in frameset (rows/cols attributes of frameset)
//##############################################################################


function dm_getBrowser()
// Detects client's browser
{
  var nv = navigator;
  var a  = nv.userAgent;
  var n  = nv.appName;
  var v  = nv.appVersion;
  var ns = 'Netscape';
  var gk = 'Gecko';
  var pf = function(r) {return parseFloat(r)}
  b_MAC  = v.io("Mac") >= 0;
  b_DOM  = d_o.getElementById?1:0;

  // Safari detect
  if ((parseInt(nv.productSub)>=20020000) && (nv.vendor.io('Apple Computer') != -1) && (nv.product==gk))
  {
      b_NS  = 1;
      b_VER = 6;
      b_SAF = 1;
      return;
  }
  
  // Konqueror detect
  if (n.toLowerCase()=='konqueror')
  {
      b_MZ  = 1;
      b_VER = 1.6;
      return;
  }

  if (a.io('Opera')>=0)
  {
      b_OP     = 1;
      b_VER    = pf(a.sb(a.io('Opera')+6, a.ln()));
      b_IEComp = (b_VER>=7);
		  return;
  }

  if (n.toLowerCase()=='netscape')
  {
      if (a.io('rv:')!=-1 && a.io(gk)!=-1 && a.io(ns)==-1)
      {
          b_MZ  = 1;
          b_VER = pf(a.sb(a.io('rv:')+3, a.ln()));
      }
      else
      {
          b_NS = 1;
          if (a.io(gk) != -1 && a.io(ns)>a.io(gk))
          {
    	        if (a.io(ns+'6')>-1) b_VER = pf(a.sb(a.io(ns)+10, a.ln()));
	            else
                  if (a.io(ns)>-1) b_VER = pf(a.sb(a.io(ns)+9, a.ln()));
          }
          else
              b_VER = pf(v);
      }
      if (b_NS)
      {
          b_NS4 = b_VER<6;
          b_NS6 = !b_NS4 && b_VER<7;
      }
      return;
  }

  if (d_o.all?1:0)
  {
      b_IE     = 1;
      b_VER    = pf(a.sb(a.io('MSIE ')+5, a.ln()));
      b_IE5    = (b_VER>=5);
      b_IE6    = (b_VER>=6);
      b_IEComp = 1;
      b_IEPC   = (b_MAC?0:1);
      b_IEMAC  = b_MAC;
  }
  //alert("b_IE = "+b_IE+"\n"+"b_OP = "+b_OP+"\n"+"b_MZ = "+b_MZ+"\n"+"b_NS = "+b_NS+"\n"+"b_DOM = "+b_DOM+"\n"+"b_MAC = "+b_MAC+"\n"+"b_VER = "+b_VER);	
}


//##############################################################################
// GLOBAL PARAMS FUNCTIONS
//##############################################################################

dm_preDefineGlobalParams();

function dm_gE(id) { return d_o.getElementById(id) }

function dm_preDefineGlobalParams()
// Pre-defines global menu variables
{
  separatorPadding="0px";
  dmCacheImages = 0;

  useHTTPS    = location.protocol=='https:' ? 1 : 0;
  dm_writeAll = 0;

  popupMode = 0;
}


function dm_checkGlobalParams()
// Sets default global menu parameters
{
  // Opera 7+ always creates submenus on the fly.
  // It allows to set correct submenus position when the menu is placed within object with absolute/relative position
  // Opera 7- always writes submenus html during page loading, doesn't work on the fly.
  if (b_OP) dm_writeAll = (b_VER>=7) ? 0 : 1;

  with (curMenu)
  {
      smInd=0;
      itInd=0;
      smVar=null;
      itVar=null;
  }

  // Menu will be contextual
  if (popupMode) absolutePos = 1;
  
  // Menu will be floatable
  // Disable floatable feature for Opera 5: links don't work if floatable mode is enabled
  if (floatable && !(b_OP && b_VER<6)) assignFloating = 1;

  // Menu will be movable
  if (movable) assignMoving = 1;
  
  if (typeof(itemPadding)!='string') itemPadding += 'px';
}


//##############################################################################
// OBJECT & VAR FUNCTIONS
//##############################################################################

function dm_getObjectWH(o)
// Returns width & height of object
{
  var op=(b_OP && b_VER<6);
  var w = op ? o.style.pixelWidth  : b_NS4 ? o.clip.width  : o.offsetWidth;
  var h = op ? o.style.pixelHeight : b_NS4 ? o.clip.height : o.offsetHeight;
  return [w,h];
}


function dm_getObjectSize(o)
// Returns object dimensions and position [x, y, width, height]
{
  if (!o) return [0,0,0,0];
  var l=0, t=0, wh = dm_getObjectWH(o), d=0, a='absolute', r='relative';

  while (o)
  {
      l += parseInt(b_NS4?o.pageX:o.offsetLeft);
      t += parseInt(b_NS4?o.pageY:o.offsetTop);
      o = o.offsetParent;

      // Detect if the menu is placed within object with relative/absolute position
      // and this object doesn't belong to the menu
      // Not used in Opera, because it renders submenus in different way
      if (!b_OP && o && o.style && (o.style.position==a || o.style.position==r) && o.id.sb(0,2)!='dm')
      {
          if (b_IEPC && o.style.position==r && docElement.leftMargin) l -= parseInt(docElement.leftMargin); // IE calculates body's left margin in some cases, so subtrack it
          d = 1;
          break;
      }
  }

  return [l, t, wh[0], wh[1], d];
}


function dm_getObjectByID(id)
// Returns object by ID
{
  if (!id) return null;
  if (b_NS4) return dm_getObjectByID4(id);
  if (b_IE && b_VER<5) return d_o.all[id];

  var itVar = dm_getVarByID(id);
  var menu  = dm_menu[itVar.mInd];

  // Cross-frame mode is enabled and submenus are placed within subframe
  return ((itVar.smInd!=0 && menu.isCrossFrame && cfType!=3) ? dm_getObjectInFrame(id, menu.cfSFInd) : dm_gE(id));
}


function dm_getVarByID(id)
// Returns variable by object ID (for menu elements only, ID should be written in the following format: dm([0-9]+)m([0-9]+)i([0-9]))
{
  var ex;
  // Do NOT use io() prototype instead of indexOf() - doesn't work in Opera 7, cross-frame mode.
  if (id.indexOf('i')>0)
  {
      ex=regexp_i.exec(id);
      return dm_menu[parseInt(ex[1])].m[parseInt(ex[2])].i[parseInt(ex[3])];
  }
  else
  {
      ex = regexp_m.exec(id);
      return dm_menu[parseInt(ex[1])].m[parseInt(ex[2])];
  }
}



//##############################################################################
// DOCUMENT FUNCTIONS
//##############################################################################

function dm_getClientSize(menu)
// Returns document dimensions where submenus are placed: [scrollX, scrollY, width, height]
{
    var l=0,t=0,w=0,h=0,cf=(menu && menu.isCrossFrame && cfType==1);
    if (b_NS || b_MZ || b_OP)
    {
        var doc = cf ? parent.frames[menu.cfSFInd].window : window;
        // Do NOT combine the following expressions into with() statement, it doesn't work on Opera 7-
        l = doc.pageXOffset;
        t = doc.pageYOffset;
        w = doc.innerWidth;
        h = doc.innerHeight;	
    }
    else
    {
        var doc = cf ? dm_getDocElement(parent.frames[menu.cfSFInd].document) : docElement;
        with (doc)
        {
            l = scrollLeft;
            t = scrollTop;
            w = clientWidth;
            h = clientHeight;				
        }
    }
    return [l,t,w,h];
}


function dm_setOnLoad()
// Assigns onLoad event for document
{
  if (window.attachEvent) window.attachEvent('onload', dm_onload);            // attach menu event if browser supports window.attachEvent() method
  else
  {
      userLoadFunc = (typeof(onload)=='function') ? onload : null;            // remember user's onLoad event
      onload = dm_onload;                                                     // set menu's onLoad event
  }
}


function dm_getDocElement(docObj)
// Detects body element according to <!DOCTYPE> specification
{
  return (docObj.compatMode=='CSS1Compat' && !b_MZ) ? docObj.documentElement : docObj.body;
}


function dm_onload()
// Function is assigned to document's onLoad event
{
  docElement = dm_getDocElement(d_o);                                         // detect body element according to <!DOCTYPE> specification


  // Enable movable/floatable features
  if (assignFloating) window.setInterval('dm_scrollWindow()', 20);            // enable floatable feature
  if (assignMoving) dm_assignMoveEvent();                                     // assign mousemove event to document (will be used for movable menus)


  isLoaded = 1;	                                                              // menu is loaded
  if (userLoadFunc) userLoadFunc();                                           // execute user's onLoad event


  // Enable keyboard support
  if (keystrokes && !b_NS4 && !(b_OP && b_VER<7)) d_o.onkeydown = function (event) { return dm_ext_keystrokes(event) }

  // Cache menu images
  //for (var i=0; i<dm_menu.ln(); i++) if (dm_menu[i].cacheImages) dm_ext_cacheImages(i);

  // Check if debug mode is enabled. Otherwise disable error reporting
  if (typeof(dm_debug)==_un) onerror = dm_error;
}


// Processes window.onError() method
function dm_error(eMessage, url, line) { return true }


//##############################################################################
// CROSS-FRAME FUNCTIONS
//##############################################################################

function dm_initFrame(fsetID, mFrameInd, sFrameInd, orient)
// Initializes cross-frame mode
{
  if (b_NS4) return dm_init4();                               // no cross-frame mode for Netscape 4, create standard menu

  if ((b_OP && b_VER<7) || (b_IE && b_VER<5)) cfEnabled = 0;  // crossframe mode is always turn off for these browsers
  else
  {
      cfEnabled     = 1;
      cfFsetID      = fsetID;
      cfMFrameInd   = mFrameInd;
      cfSFrameInd   = sFrameInd;
      cfOrientation = orient;
  }
  cfType = 1;
  dm_init();
}



//##############################################################################
// PREFIX FUNCTIONS
//##############################################################################

var fixPrefixes = ['javascript:', 'mailto:', "http://", "https://", "ftp://"];

function dm_canPrefix(url)
// Detects if path prefix can be added
{
  for (var i=0; i<fixPrefixes.ln(); i++)
      if (url.io(fixPrefixes[i])==0) return false;
  return true;
}


function dm_setPathPrefix(paths, prefix)
// Sets prefix for specified array of paths or string
{

  function dm_addPrefix(pathStr)
  // Adds prefix to specified path string
  {
      return pathStr ? ((dm_canPrefix(pathStr) ? prefix : '') + pathStr) : '';
  }
  

  if (typeof(paths)=='string') return dm_addPrefix(paths);
  else
  {
      var p=[];
      for (var i=0; i<paths.ln(); i++) p[i] = paths[i] ? dm_addPrefix(paths[i]) : '';

      return p;
  }
}


//##############################################################################
// PARAMETERS & INDIVIDUAL STYLES FUNCTIONS
//##############################################################################

function dm_getParam(param, defParam) {
  return (typeof(param)!=_un && param) ? param : defParam;
}


function dm_getStyleParam(pName, sInd, sType, defValue, isIndividual)
// Returns individual style value from styles array for item/submenu
{
  if (sInd==-1 || ''+sInd+''=='' || !isIndividual) return defValue;
  var sp = sType ? itemStyles[sInd] : menuStyles[sInd];                       // assign items or submenus styles variable

  // Search for parameter name
  for (var i=0; i<=sp.ln(); i++)
      if (i==sp.ln() || typeof(sp[i])==_un) return defValue;
      else
          if (sp[i].io(pName)>=0) break;
          

  var val = sp[i].split('=')[1];                                              // get parameters' value
  if (val.io(',')>=0) val = val.split(',');                                   // if values is array -> create the array of values

  return val;
}


function dm_getSubmenuStyle(menu, sInd, is)
// Returns specified submenu style
{
  if (typeof(sInd)==_un) return menu.standardSmStyle;

  var pPrefix = !menu ? pathPrefix_img : menu.pPrefix_img;
  
  var bI = is ? dm_getStyleParam('menuBackImage', sInd, 0, '', is) : 0;
  
  var st = {
      backColor  : dm_getStyleParam('menuBackColor',  sInd, 0, menuBackColor, is),
      backRepeat : dm_getStyleParam('menuBackRepeat', sInd, 0, menuBackRepeat, is),

      backImage  : bI ? dm_setPathPrefix(bI, pPrefix) : dm_setPathPrefix(menuBackImage, pPrefix),

      columnsCnt : parseInt(dm_getStyleParam('smColumns', sInd, 0, smColumns, is)),
      // Border
      brdWidth   : dm_getStyleParam('menuBorderWidth',  sInd, 0, menuBorderWidth, is),
      brdStyle   : dm_getStyleParam('menuBorderStyle',  sInd, 0, menuBorderStyle, is),
      brdColor   : dm_getStyleParam('menuBorderColor',  sInd, 0, menuBorderColor, is),
      // Items
      itSpacing  : dm_getStyleParam('itemSpacing',      sInd, 0, itemSpacing, is),
      itPadding  : dm_getStyleParam('itemPadding',      sInd, 0, itemPadding, is),
      // CSS
      cssClass   : dm_getStyleParam('CSS',              sInd, 0, cssSubmenu, is),
      // Size
      smW        : dm_getStyleParam('smWidth',          sInd, 0, smWidth, is),
      smH        : dm_getStyleParam('smHeight',         sInd, 0, smHeight, is)
  };

  return st;
}


function dm_getItemStyle(menu, sInd, is)
// Returns specified item style
{
  if (typeof(sInd)==_un) return menu.standardItStyle;
  
  var pPrefix = !menu ? pathPrefix_img : menu.pPrefix_img;

  var aM = is ? dm_getStyleParam('arrowImageMain', sInd, 1, '', is) : 0;
  var aS = is ? dm_getStyleParam('arrowImageSub',  sInd, 1, '', is) : 0;
  var bI = is ? dm_getStyleParam('itemBackImage',  sInd, 1, '', is) : 0;

  var st = {
      itWidth    : dm_getStyleParam('itemWidth',        sInd, 1, '100%', is),
      backColor  : dm_getStyleParam('itemBackColor',    sInd, 1, itemBackColor, is),
      // Border
      brdWidth   : dm_getStyleParam('itemBorderWidth',  sInd, 1, itemBorderWidth, is),
      brdStyle   : dm_getStyleParam('itemBorderStyle',  sInd, 1, itemBorderStyle, is),
      brdColor   : dm_getStyleParam('itemBorderColor',  sInd, 1, itemBorderColor, is),
      // Font
      fntColor   : dm_getStyleParam('fontColor',        sInd, 1, fontColor, is),
      fntStyle   : dm_getStyleParam('fontStyle',        sInd, 1, fontStyle, is),
      fntDecor   : dm_getStyleParam('fontDecoration',   sInd, 1, fontDecoration, is),
      // Images
      arrowMain  : aM ? dm_setPathPrefix(aM, pPrefix) : dm_setPathPrefix(arrowImageMain, pPrefix),
      arrowSub   : aS ? dm_setPathPrefix(aS, pPrefix) : dm_setPathPrefix(arrowImageSub,  pPrefix),
      backImage  : bI ? dm_setPathPrefix(bI, pPrefix) : dm_setPathPrefix(itemBackImage,  pPrefix),
      // CSS
      cssClass     : dm_getStyleParam('CSS',     sInd, 1, cssItem, is),
      cssClassText : dm_getStyleParam('CSSText', sInd, 1, cssItemText, is)
  };

  return st;
}

//##############################################################################
// MENU PARAMETERS FUNCTIONS
//##############################################################################

function dm_createMenuParams(curInd)
// Creates menu parameters
{
  dm_menu[curInd] = {
     	m            : [],                     // menu arrays
     	ind          : curInd,                 // index of the menu
     	id           : 'dm'+curInd,            // HTML id
     	hideAllTimer : null,                   // timer to hide all submenus
     	absPos       : absolutePos,
     	floating     : floatable,
     	floatingX    : floatableX,
     	floatingY    : floatableY,
     	iterations   : floatIterations,
      // Toggle mode
      toggleMode   : pressedItem,
     	curPressedSm : 0,
     	curPressedIt : (pressedItem>=0) ? pressedItem : -1,
      // Cross-frame mode
     	isCrossFrame : cfEnabled,
     	cfMFInd      : cfMFrameInd,
     	cfSFInd      : cfSFrameInd,
     	cfOrient     : cfOrientation,          // 0 - top-to-bottom, 1 - left-to-right; 2 - bottom-to-top; 3 - right-to-left.
     	cfFSID       : cfFsetID,
     	// Standard styles
     	standardSmStyle : dm_getSubmenuStyle(null, 0, 0),
     	standardItStyle : dm_getItemStyle(null, 0, 0),
     	// CSS mode
     	isCSSMode    : cssStyle,
      // Common
     	isPopup        : popupMode,            // context menu mode
      saveNavigation : saveNavigationPath,   // show highlighted items during a menu nvigation
      smView         : smViewType,           // 0 - top-to-bottom, 1 - bottom-to-top, 2 - top-to-bottom + right-to-left, 3 - bottom-to-top + right-to-left
      smShowClick    : showByClick,          // show submenus by mouse click only
      smShowClicked  : 0,

      isVisible  : (popupMode)?0:1,          // menu is visible
      isDisabled : 0,                        // menu is disabled
      // Disabled item params
      fntColorDisabled : fontColorDisabled,

      smAlign    : subMenuAlign,
      smHideClick: smHideOnClick,
      cacheImages: dmCacheImages,
      
      sepImg : separatorImage,
      sepW   : separatorWidth,
      sepH   : separatorHeight,
      sepVImg: separatorVImage,
      sepVW  : separatorVWidth,
      sepVH  : separatorVHeight,
      sepPadding : separatorPadding,
      
      pPrefix_img: pathPrefix_img
  };
  
  return dm_menu[curInd];
}


function dm_createSubmenuParams(parentM, parentSm, parentIt, styleInd)
// Creates submenu parameters
{
  var lvl       = parentSm ? parentSm.level+1 : 0;
  var menu      = parentM;
  curMenu.ind   = parentM.ind;
  curMenu.smInd = menu.m.ln();
  var ii=curMenu.smInd;

  menu.m[ii] = {
      i            : [],                                       // array of items
      mInd         : curMenu.ind,                              // index of parent menu
      ind          : ii,                                       // index of the submenu
      id           : 'dm'+curMenu.ind+'m'+ii,                  // ID of the submenu object
      rootItemID   : parentIt ? parentIt.id : '',              // ID of parent item
      shownChildID : '',                                       // current shown submenu ID
      showTimer    : null,                                     // timer for delay the appearance of submenus
      level        : lvl,                                      // submenu level
      // Positioning
      left         : ii ? '-1000px' : posX,
      top          : ii ? '0px'     : posY,
      // Moving
      moving       : ii ? smMovable : movable,
      isMoved      : 0,
      // Offsets
      offx         : (lvl>1)?DX:topDX,                         // x offset
      offy         : (lvl>1)?DY:topDY,                         // y offset
      // Appearance
      smStyle      : dm_getSubmenuStyle(menu, styleInd, 1),
      isHoriz      : ii ? smOrientation : isHorizontal,
      mainWidth    : ii ? 'auto' : dm_getParam(menuWidth, ((b_NS && b_VER<7) ? 'auto' : '1px')),
      mainHeight   : menuHeight,
      // Effects
      opacity      : !ii ? 100 : transparency,                 // submenu opacity
      effect       : !ii ? 0 : (transition ? transition : 1),  // transition type
      duration     : transition ? transDuration  : 0,                      // transition delay (on show)
      duration2    : transition ? transDuration2 : 0,                      // transition delay (on hide)
      // Shadow
  	  shadowColor  : shadowColor,
  	  shadowLen    : (b_IEPC && b_IE5) ? shadowLen : 0,
      // Submenu HTML code
      smHTML       : '',                                                  // HTML code of the submenu
      // For submenu scrolling
      sX       : 0,
      sY       : 0,
      sEnabled : 0,
      sObj     : null,
      // Objects' intersection
      hidObjs  : []
  };
  curMenu.smVar = menu.m[ii];
}


function dm_getStatusText(str, itText, itLink, itTip) {                       // Returns item status text
  return (!str || str=='link') ? itLink : (str=='text') ? itText : (str=='tip') ? itTip : str;
}


function dm_getItemTarget(targetVal) {                                        // Returns item target
  return (!targetVal && itemTarget) ? itemTarget : targetVal;
}


function dm_getItemLink(linkVal) {                                            // Returns item link
  return dm_setPathPrefix(dm_getParam(linkVal, ''), pathPrefix_link);
}


function dm_createItemParams(parentM, parentSm, itInd, iParams, statusStr)
// Creates item parameters
{
  var smVar   = parentM.m[parentSm.ind];
  var iText   = iParams[0];
  var iLink   = dm_getItemLink(iParams[1]);
  var iTarget = dm_getItemTarget(dm_getParam(iParams[5], ''));
  var iAlign  = (parentSm.level==0) ? itemAlignTop : itemAlign; //subMenuAlign : itemAlign;
  var iTip    = dm_getParam(iParams[4],'');
  var iAJAX   = dm_getParam(iParams[8],'');

  var onNextRow = 0;
  if (iText.charAt(0)=='$')
  {
      onNextRow = 1;
      iText = iText.substr(1, iText.ln()-1);
  }

	smVar.i[itInd] = {
      mInd    : parentM.ind,
      smInd   : parentSm.ind,
      ind     : itInd,
      id      : 'dm'+parentM.ind+'m'+parentSm.ind+'i'+itInd,
      childID : iAJAX ? '_' : '',                                             // id of child submenu, set '_' if AJAX is enabled
      // Common
      text    : iText,
      link    : iLink,
      target  : iTarget,
      tip     : iTip,
      sstr    : dm_getStatusText(statusStr, iText, iLink, iTip),
      align   : iAlign,
      valign  : 'middle',
      cursor  : itemCursor,
      // Appearance
      itStyle  : dm_getItemStyle(parentM, iParams[6], 1),
      icon     : dm_setPathPrefix([dm_getParam(iParams[2],''),dm_getParam(iParams[3],'')], parentM.pPrefix_img),
      iconW    : (parentSm.level)?iconWidth:iconTopWidth,
      iconH    : (parentSm.level)?iconHeight:iconTopHeight,
      icState  : 0,
      arrowW   : arrowWidth,
      arrowH   : arrowHeight,
      // Additional
      isDisabled   : (iTarget=='_')?1:0,                          // target='_' - item is disabled
      isPressed    : 0,                                           // item is pressed (user clicked on the item)
      isHighlighted: 0,                                           // to save a navigation path
      isVisible    : 1,
      isDeleted    : 0,
      nextRow      : onNextRow,
      
      // .js filename, AJAX: submenu data are placed within another .js file on server
      ajax : iAJAX
  };

  curMenu.itInd = itInd;
  curMenu.itVar = smVar.i[itInd];
  curMenu.smVar = parentSm;
}


//##############################################################################
// HTML FUNCTIONS
//##############################################################################

// Additional DX filters
var dm_filters = ['Blinds','Checkerboard','GradientWipe','Inset','Iris','Pixelate','RadialWipe','RandomBars',
                  'RandomDissolve','Slide','Spiral','Stretch','Strips','Wheel','Zigzag'];


function dm_getAdditionalFilterHTML(fInd, fDur) {
  return (b_VER<5.5) ? '' : 'progid:DXImageTransform.Microsoft.'+dm_filters[fInd-25]+'('+transOptions+',duration='+fDur+') ';
}

function dm_getFilterHTML(smVar)
{
  var sf = '';
  with (smVar)
      if (b_IE5 && b_IEPC)
      {
          sf = 'filter:';
          if (effect)
          {
              var dur = duration/1000;
              if (effect==24) sf += "blendTrans(Duration="+dur+") ";
              else
                  sf += (effect<24) ? "revealTrans(Transition="+effect+",Duration="+dur+") " : dm_getAdditionalFilterHTML(effect, dur);
          }
          if (opacity!=100) sf += "alpha(opacity="+opacity+") ";
          if (shadowLen)    sf += "shadow(color="+shadowColor+",direction=135,strength="+shadowLen+")";
      }
      else
          if (b_NS || b_MZ)
          {
        		  var o = opacity/100;
		          if (opacity!=100) sf = '-moz-opacity:'+o;
	        }
	
  return sf;
}


function dm_openDivSimple(id, styleText, events) {
  return '<DIV id="'+id+'" '+events+' style="'+styleText+'">';
}

function dm_closeDiv() {
  return '</DIV>';
}


function dm_openTableWithClass(id, clN, spac, padd, events) {
   return '<Table id="'+id+'" '+events+' class="'+clN+'" border=0 cellspacing='+spac+' cellpadding='+padd+'>';
}

function dm_openTableSimple(id, spac, padd, styleText, events, add) {
   return '<Table id="'+id+'" '+events+' cellspacing='+spac+' cellpadding='+padd+' '+add+' style="'+styleText+'" border=0>';
}

function dm_closeTable() {
  return '</Table>';
}

function dm_openTr(id)
{
  return '<tr id="'+id+'">';
}

function dm_closeTr() {
  return '</tr>';
}

function dm_openTdSimple(id, styleText, add)
{
  return '<td id="'+id+'" '+add+' style="'+styleText+'">';
}

function dm_closeTd() {
  return '</td>';
}


function dm_openImg(id, url, w, h, add) {
  return '<img id="'+id+'" src="'+url+'" '+(w ? 'width='+w : '') + (h ? ' height='+h : '') +' '+add+' border=0>';
}


function dm_holdSubmenu(smID)
{
  with (moveRec)
      if (smID)
      {
          prepareSmID = smID;
          smVar = dm_getVarByID(smID);
          clearTimeout(dm_menu[smVar.mInd].hideAllTimer);
      }
      else
      {
          if (smVar)
              with (dm_menu[smVar.mInd])
              {
                  clearTimeout(hideAllTimer);
                  hideAllTimer = setTimeout("dm_hideMenu('"+m[0].shownChildID+"');window.status='';", smHidePause);
              }
          prepareSmID = '';
      }
}


function dm_openSeparator(menu, img, w, h) {
  return dm_openImg('', dm_setPathPrefix(img, menu.pPrefix_img), (w?w:"100%"), (h?h:"1"), '');
}


function dm_openItemArrow(itVar)
{
  var s='', smVar=dm_menu[itVar.mInd].m[itVar.smInd];
  
  with (itVar)
  {
      var arrImg = smInd ? itStyle.arrowSub[0] : itStyle.arrowMain[0];
      if (arrImg)
          s = dm_openTdSimple(itVar.id+'tdA', 'padding:'+smVar.smStyle.itPadding, '')+
              dm_openImg(id+'arr', arrImg, arrowW, arrowH, '')+
              dm_closeTd();
  }
  return s;
}


function dm_scrollSubmenu(e, smID)
{
  var smVar = dm_getVarByID(smID);
  if (!smVar.sEnabled || smVar.shownChildID) return;
  
  var smWH = dm_getObjectSize(smVar.sObj);
  var ex, ey;
  
  if (b_IEComp)
  {
      var cs = dm_getClientSize(dm_menu[smVar.mInd]);                         // get page scrolling values
      ex = e.x+cs[0];
      ey = e.y+cs[1];
  }
  else
  {
      ex = e.pageX;
      ey = e.pageY;
  }


  var dx = smWH[2]*0.1;
  var dy = smWH[3]*0.1;
  var px = (ex - smWH[0]-dx)/(smWH[2]-dx*2);
  var py = (ey - smWH[1]-dy)/(smWH[3]-dy*2);

  with (smVar.sObj)
  {
      if (b_OP) style.top = smVar.sY - py*(smWH[3]*0.5) + 'px';
      else
      {
          scrollLeft = px*(scrollWidth  - smWH[2]);
          scrollTop  = py*(scrollHeight - smWH[3]);
      }
  }
}


// Movable menu HTML -----------------------------------------------------------
function dm_addCloseBtn(menu, smVar){
  return dm_openImg('', dm_setPathPrefix(closeBtn, menu.pPrefix_img), closeBtnW, closeBtnH, 'title="Close the sumbenu" onClick="dm_deMoveSubmenu(\''+smVar.id+'\')" style="cursor:'+((b_IE && b_VER<6)?'hand':'pointer')+';"')
}


function dm_openMoveSpacer(menu, smVar)
{
  if (dm_menu[smVar.mInd].isCrossFrame) return '';
  return '<td id="'+smVar.id+'m" NOWRAP align=right style="width:'+(smVar.isHoriz?moveWidth+dUnits:'100%')+';height:'+moveHeight+dUnits+';cursor:'+moveCursor+';padding:0px;"'+
              'bgcolor='+moveColor+' background="'+dm_setPathPrefix(moveImage, menu.pPrefix_img)+'" '+
              'onMouseDown="dm_startMoving(event,\''+smVar.id+'\')" onMouseUp="dm_stopMoving()"'+
              'onMouseOver="dm_holdSubmenu(\''+smVar.id+'\')" onMouseOut="dm_holdSubmenu(\'\')">'+

              (!smVar.ind ? dm_openImg('', blankImage, 1, moveHeight, '') : dm_addCloseBtn(menu, smVar)) +

              (smVar.isHoriz?'<br>'+dm_openImg('','',moveWidth,'1',''):'')+
          '</td>'+(smVar.isHoriz?'':'</TR><TR>');
}


function dm_deMoveSubmenu(smID)
{
  with (dm_getVarByID(smID))
  {
      isMoved = 0;
      moveRec.prepareSmID = '';
      moveRec.smVar = null;
  }
  dm_hideMenu(smID);
}
// End of movable menu ---------------------------------------------------------


//##############################################################################
// BASIC FUNCTIONS
//##############################################################################


function dm_getItemLevel(itInd)
// Returns level of item and removes '|' symbols from item text
{
  var lvl=0;
  while (menuItems[itInd][0].charAt(lvl)=='|') lvl++;                                       // nesting of item
  if (lvl>0) menuItems[itInd][0] = menuItems[itInd][0].sb(lvl, menuItems[itInd][0].ln());   // remove ||| from item text
  return lvl;
}


function dm_parseItemsData()
// Parses menu items: creates submenu and item objects
{
    var pl=-1;                                        // previous item level
    var cl=0;                                         // current item level

    for (var i=0; (i<menuItems.ln() && typeof(menuItems[i])!=_un); i++)
    {
        cl = dm_getItemLevel(i);

        if (pl<cl)                                                            // Create submenu
            with (curMenu)
            {
                dm_createSubmenuParams(dm_menu[ind],        // menu object
                                       smVar,               // parent submenu
                                       itVar,               // parent item
                                       menuItems[i][7]);    // style index

                itInd = 0;
                itVar = null;
            }

        if (pl>cl)                                                            // Return to previous submenu level
            with (curMenu)
            {
                while (dm_menu[ind].m[smInd].level>cl) smInd--;
                smVar = dm_menu[ind].m[smInd];
            }
        pl = cl;

        curMenu.itInd = curMenu.smVar.i.ln();                                 // set current item index
        dm_createItemParams(dm_menu[curMenu.ind],    // menu object
                            curMenu.smVar,           // parent submenu
                            curMenu.itInd,           // current item index
                            menuItems[i],            // item params
                            statusString);           // status string text

    }

    // Link submenus with root items
    var rooti;
    with (curMenu)
        for (var i=1; i<dm_menu[ind].m.ln(); i++)                             // run submenus excluding top menu
        {
        	  rooti = dm_getVarByID(dm_menu[ind].m[i].rootItemID);
            rooti.childID = rooti.ajax ? '_' : rooti.childID = dm_menu[ind].m[i].id;  // assign child submenu
        }
}


function dm_createPopupMenu()
{
 // increase items level
 for (var i=0; i<menuItems.ln() && typeof(menuItems[i])!=_un; i++) menuItems[i][0] = '|' + menuItems[i][0];

 // add new root item
 var newItem = [['']];
 menuItems = newItem.concat(menuItems);
}


function dm_init()
// Creates the menu
{
    if (b_NS4) return dm_init4();
    dm_checkGlobalParams();                                                   // check and correct users' parameters


    //#### Install additional .js modules ######################################
    // Install module for cross-frame support
    if (cfEnabled) dm_addScript('dmenu_cf', 0);


    // Install module for floatable/movable menu support
    if (dmObjectsCheck || assignFloating || assignMoving)
    {
        dm_addScript('dmenu_add', 0);
        dmObjectsCheck = 1;    // Enable objects intersection check, because these functions are placed within the same dmenu_add.js file
    }

    // Install the module for popup-menu support
    if (popupMode)
    {
        dm_addScript('dmenu_popup', 0);
        dm_createPopupMenu();              // modify items for the popup mode
    }


    // Install the module for keystrokes support
    if (keystrokes) dm_addScript('dmenu_key', 0);


    // Install the module for external functions
    if (dynamic) dm_addScript('dmenu_dyn', 0);


    // Install the module for AJAX support
    if (dmAJAX) dm_addScript('dmenu_ajax', 0);


    // Install the module for images caching
    //if (dmCacheImages) dm_addScript('dmenu_cache', 0);


    // Check if other menu engine from another frame writes submenus into the same subframe, and set current menu index.
    // Otherwise set additional variable in subframe (current menu index).
    if (cfEnabled)
    {
        var frm = parent.frames[cfSFrameInd];
        if (typeof(frm.dm_crossMenuInd)==_un) frm.dm_crossMenuInd = curMenu.ind;
        else
            curMenu.ind = frm.dm_crossMenuInd+1;
    }


    // If it's the first menu on the page -> attach new onload event
    if (!curMenu.ind) dm_setOnLoad();

    var menu = dm_createMenuParams(curMenu.ind);                              // create common params of the menu
    dm_parseItemsData();                                                      // parse menuItems
    dm_createMenu(menu);                                                      // create the menu
    

    // Create separate focus <div> element here for each new menu.
    // It allows to place focus div correctly when the menu is placed within relative/absolute positioned object
    d_o.write('<div id="dmFDIV'+menu.ind+'" style="z-index:999999;border:dotted 1px #000000;display:none;position:absolute;font:normal 1px;">&nbsp;</div>');


    // Show IFRAME under top-menu
    if (!menu.isCrossFrame && menu.absPos) dm_showIFrame(dm_gE(menu.m[0].id));


    // Set default pressed item ------------------------------------------------
    if (menu.toggleMode>=0)                                                   // toggle mode is on -> highlight top-menu item
        if (cfType==1 || cfType==3)
        {
            toggleRec.pressedSelf = 1;                                        // menu calls dm_ext_setPressedItem() itself, not user
            dm_ext_setPressedItem(menu.ind, menu.curPressedSm, menu.curPressedIt, 0);
        }

    curMenu.ind++;
    curMenu.curPressedIt = -1;

}//end dm_init()



function dm_checkCursor(cur)
{
  return (b_IE && b_VER<6)  ?  (cur=='pointer')?'hand':cur  :  (cur=='hand')?'pointer':cur;
}


function dm_getAddDivHTML(mInd, smInd)
// Creates HTML code for additional <DIV> object
{
  return '<div id="dmD'+mInd+'m'+smInd+'"></div>';
}


function dm_createMenu(menu)
{
    //var menu = dm_menu[ind];
    var s='',ss='';
    var pos    = menu.absPos    ? 'absolute' : 'static';
    var vis    = menu.isVisible ? 'visible'  : 'hidden';

    // Create HTML code
    for (var smInd=0; smInd<menu.m.ln(); smInd++)                             // run submenus
    {
        s += dm_createSubmenuHTML(menu,
                                  menu.m[smInd],
                                  pos,
                                  vis,
                                  dmZOrder,
                                  0);

        // Always write HTML for top menu
        if (!smInd || dm_writeAll) d_o.write(s);

        if (!dm_writeAll) break;

        s   = '';
        pos = 'absolute';
        vis = 'hidden';
    }// for (submenus)


    // Create additional <div>s.
    // They will be used for creating submenus on the fly.
    // Without such <div>s Netscape 6 creates submenu in incorrect places with artifacts,
    //         other browsers (such as IE, Firefox) resets overflow coords of scrollable submenus if body.innerHTML is used.
    s = '';
    if (!dm_writeAll || dmAJAX)
    {
        var cnt = dmAJAX ? dmAJAXCount+1 : menu.m.ln();
        for (var i=1; i<cnt; i++) s += dm_getAddDivHTML(menu.ind, i);
        d_o.write(s);
    }
}


function dm_createSubmenuHTML(menu, smVar, pos, vis, zOrder, onFly)
// Creates submenu HTML code
{
  var s = '';
  var smInd = smVar.ind;

  var colInd = -1;
  var addRow = 0;
  var frame  = (smInd && menu.isCrossFrame && cfType==1) ? 'parent.frames['+menu.cfMFInd+'].' : '';
  var noScroll = ((b_NS && b_VER<7) || b_OP || b_IEMAC || !smSmartScroll);
  var NS6 = (b_NS && b_VER<7);
  var smBack;


  // Don't use display property for submenus, excluding Opera 6- (it can't change display on the fly)
  var disp = (smVar.ind && !(b_OP && b_VER<7)) ? 'display:none;' : '';


  // Create IFRAME for submenu.
  // Used on non-SSL (HTTPS) websites and on PC IE6+ only
  if (!useHTTPS && b_IEPC && b_IE6)
      s = '<iframe id="'+smVar.id+'frame" frameBorder=no dm=1 style="visibility:hidden;position:absolute;filter:alpha(opacity=0)"></iframe>';


  with (smVar)
  with (smStyle)
  {
      smBack = 'background-color:'+backColor+';'+(backImage? 'background-image:url('+backImage+');background-repeat:'+backRepeat+';' : '');

      var h = ind ? (smStyle.smH ? 'height:'+smStyle.smH+';' : '') : '';
      var w = 'width:' + (smInd ? (smStyle.smW ? smStyle.smW : '1px') : mainWidth) + ';';
      var flt = (!smInd && shadowTop) || smInd;

      var divStyle = h+w+'position:'+(pos?pos:'absolute')+';left:'+left+';'+'top:'+top+';'+
                     (NS6 ? smBack : '')+disp+';visibility:'+(vis?vis:'hidden')+';z-index:'+zOrder+';'+
                     (flt ? dm_getFilterHTML(smVar)+';' : '');

      if (shadowLen && flt) divStyle += 'padding:0px '+shadowLen+' '+shadowLen+' 0px 0px;';
      if (b_NS && b_VER<7) divStyle += 'background-color:'+backColor+';';
  }


  // Write submenu DIV: for NS6 & OP5-6 & IEMAC-> create another events - submenus use scroll-bars for scrolling (NS6) and moved on mousemove event (OP5-6)
  s += dm_openDivSimple(smVar.id, divStyle,
                        (noScroll?'onMouseOver="'+frame+'dm_holdSubmenu(\''+smVar.id+'\')" onMouseOut="'+frame+'dm_holdSubmenu(\'\')"':'onMouseMove="'+frame+'dm_scrollSubmenu(event,\''+smVar.id+'\')"'));



  // Create submenu table ------------------------------------------------
  if (menu.isCSSMode) s += dm_openTableWithClass(smVar.id+'tbl', smVar.smStyle.cssClass, smVar.smStyle.itSpacing, 0, '');
  else
      with (smVar.smStyle)
      {
          var tblStyle = 'padding:0px;width:100%;'+(!NS6 ? smBack : '')+
                         'border-style:'+brdStyle+';border-width:'+brdWidth+dUnits+';border-color:'+brdColor; // do not collapse border parameters within 'border:' one. In other case border can't accept multiple colors.
          s += dm_openTableSimple(smVar.id+'tbl', smVar.smStyle.itSpacing, 0, tblStyle, '', '');
      }


  // Create move spacer --------------------------------------------------
  if (smVar.moving) s += dm_openMoveSpacer(menu, smVar);


  var ss, disp;
  colInd = -1;
  addRow = 1;

  // RUN SUBMENU ITEMS ===================================================
  for (var iInd=0; iInd<smVar.i.ln(); iInd++)
  {
      // It's necessary to define this additional string variable ss
      // because IE has low speed during loading of big menus
      ss = '';
      var itVar = smVar.i[iInd];

      // Create columns --------------------------------------------------
      if (smVar.smStyle.columnsCnt>1)
      {
          colInd++;
          if (colInd==smVar.smStyle.columnsCnt)
          {
              colInd = 0;
              addRow = 1;
          }
          if (colInd>0) addRow = 0;
      }


      // Create item <TR> element.
      // It's necessary assign TR's ID attribure for vertical submenus when using dynamic functions (changeItemVisibility and deleteItem).
      // If the script won't hide these <TR> elements, additional space will be created when several items will be deleted
      if (!iInd) ss += dm_openTr((smVar.isHoriz ? '' : itVar.id+'R'));
      else
          if (addRow && (!smVar.isHoriz || itVar.nextRow)) ss += dm_closeTr()+dm_openTr(itVar.id+'R');

      // Check if item was deleted before submenu object was created on the page
      disp = (itVar.isDeleted || !itVar.isVisible) ? ';display:none' : '';

      ss += dm_openTdSimple(itVar.id+'td', 'padding:0px'+disp, '') +
            dm_createItemTable(menu, smVar, itVar, frame) +
            dm_closeTd();
            
      s += ss;
  }

  s += dm_closeTr()+dm_closeTable() + dm_closeDiv();
  
  smVar.smHTML = s;                                                           // save HTML code for the submenu
  dmZOrder += 1;                                                              // increase z-index

  return s;
}


function dm_createItemTable(menu, smVar, itVar, frame)
// Creates item table (menu item object)
{
  var ss = '';

  // Create events ---------------------------------------------------
  var events = 'onMouseOver="'+frame+'dm_over(event,\''+itVar.id+'tbl\')" '+
               'onMouseOut="'+frame+'dm_out(event,\''+itVar.id+'tbl\')" '+
               'onClick="'+frame+'dm_click(event,\''+itVar.id+'tbl\');"';

  if (menu.isCSSMode) ss += dm_openTableWithClass(itVar.id+'tbl', itVar.itStyle.cssClass[0], 0, 0, 'title="'+itVar.tip+'" '+events);
  else
  {
      with (smVar) var h = ind ? '' : (mainHeight ? 'height:'+mainHeight+';' : '');
      
      with (itVar.itStyle)
          var tblStyle = h+'padding:0px;width:'+itWidth+';cursor:'+dm_checkCursor(itVar.cursor)+
                         ';background-color:'+backColor[0]+';' + (backImage[0]? 'background-image:url('+backImage[0]+');' : '') +
                         'border-color:'+brdColor[0]+';border-style:'+brdStyle[0]+';border-width:'+brdWidth+dUnits+';';
      ss += dm_openTableSimple(itVar.id+'tbl', 0, 0, tblStyle, events, 'title="'+itVar.tip+'"')+dm_openTr();
  }


  // Define if CSS style or standard menu parameters will be used for item
  var textStyle ='', textCSS='';
  with (itVar.itStyle)
      if (menu.isCSSMode) textCSS   = 'class="'+cssClassText[0]+'"';
      else                textStyle = 'padding:'+smVar.smStyle.itPadding+';text-align:'+itVar.align+';font:'+fntStyle+';color:'+(itVar.isDisabled?menu.fntColorDisabled:fntColor[0])+'; text-decoration:'+fntDecor[0]+';';


  // Create item cells =========================================================
  if (!itVar.text)                                                            // item is image-based
  {
        ss += dm_openTdSimple(itVar.id+'tdT', '', textCSS) +
              dm_openImg(itVar.id+'img', itVar.icon[0], '', '', 'alt="'+itVar.tip+'"') +
              dm_closeTd();
  }
  else
    if (itVar.text=='-')                                                      // item is separator
    {
        with (menu)
        {
            ss += dm_openTdSimple(itVar.id+'tdT', 'text-align:'+separatorAlignment+(sepPadding? ';padding:'+sepPadding : ''), textCSS);

            if (itVar.smInd>0) ss += dm_openSeparator(menu, sepImg,  sepW,  sepH);
            else               ss += dm_openSeparator(menu, sepVImg, sepVW, sepVH);

            ss += dm_closeTd();
        }
    }
    else
    {
        // Create item arrow-image -------------------------------------
       // if (menu.smView>=2 && itVar.childID) ss += dm_openItemArrow(itVar, 0);

        // Create item icon --------------------------------------------
        if (itVar.icon[0]) ss += dm_openTdSimple(itVar.id+'tdIc', 'padding:'+smVar.smStyle.itPadding, '') +
                                 dm_openImg(itVar.id+'ic', itVar.icon[0], itVar.iconW, itVar.iconH, '')+
                                 dm_closeTd();


        // Create item text --------------------------------------------
        if (itVar.text)
            ss += dm_openTdSimple(itVar.id+'tdT', 'width:100%;'+textStyle, (noWrap ? ' NOWRAP ':'')+textCSS)+
                  itVar.text+
                  dm_closeTd();


        // Create item arrow-image -------------------------------------
        if (/*menu.smView<2 && */itVar.childID) ss += dm_openItemArrow(itVar, 0);
    }

  return ss+dm_closeTr('')+dm_closeTable();
}


//##############################################################################
// ITEMS FUNCTIONS
//##############################################################################


function dm_changeItemStyle(it, over)
// Changes item appearance
{
  over = it.isHighlighted ? 1 : over;
  if (b_NS4) return dm_changeItemStyle4(it, over);
  var itObj = dm_getObjectByID(it.id+'tbl');
  if (!itObj) return;


  // Image-based item, change image only
  if (!it.text)
  {
      dm_getObjectByID(it.id+'img').src = it.icon[over];
      return;
  }

  
  with (it.itStyle)
  {
      if (dm_menu[it.mInd].isCSSMode) itObj.className = cssClass[over];
      else
      {
          var is = itObj.style;
          is.borderWidth = brdWidth;
          if (backColor[over]) is.backgroundColor = backColor[over];
          if (brdColor[over])  is.borderColor     = brdColor[over];
          if (brdStyle[over])  is.borderStyle     = brdStyle[over];
          if (backImage[over]) is.backgroundImage = 'url('+backImage[over]+')';
      }

      var textObj=dm_getObjectByID(it.id+'tdT');

      if (textObj)
      {
          if (dm_menu[it.mInd].isCSSMode) textObj.className = cssClassText[over];
          else
              with (textObj.style)
              {
                  if (it.isDisabled) color = dm_menu[it.mInd].fntColorDisabled;
                  else
                      if (fntColor[over]) color = fntColor[over];
                  if (fntDecor[over]) textDecoration = fntDecor[over];
              }
      }
  }

  with (it)
  {
      if (icon[over])
          with (dm_getObjectByID(id+'ic'))
              if (icState!=over)                      // check if icon has necessary image src already - to avoid clock-cursor showing in IE
              {
                  src = icon[over];
                  icState = over;
              }

      var ao = dm_getObjectByID(id+'arr');
      if (ao)
      {
          var arr = smInd ? itStyle.arrowSub[over] : itStyle.arrowMain[over];
          if (childID && arr) ao.src = arr;
      }
  }
}


var _d_rID='';

function dm_over(e, id)
// Items' mouse over event
{
    var itVar = dm_getVarByID(id);
    var menu  = dm_menu[itVar.mInd];

    // Keystrokes are enabled --------------------------------------------------
    if (keystrokes)
    {
        if (keyMode.isEnabled) dm_disableKeyMode(menu.ind, 0);
        
        if (!menu.isPopup)
        {
          /*  keyMode.menu  = menu;
            keyMode.itVar = itVar;
            with (keyMode)
            {
              //  isEnabled = 1;
                rsmVar = menu.m[0];
                ritVar = rsmVar.i[0];
                smVar  = menu.m[itVar.smInd];
            }
          */
          _dmKSInd = menu.ind;
        }
    }


    // Change status bar text
    window.status = itVar.sstr;                                               // it's necessary to specify window object for Mozilla browsers

    // Check if item should change its appearance
    with (itVar) if (!isDisabled && text!='-' && !isPressed) dm_changeItemStyle(itVar, 1);

    // Check if user should click on item to show submenu
    if (menu.smShowClick && !menu.smShowClicked && !itVar.smInd) return;      // if the item is top-menu item and showByClick-mode is enabled -> return


    var itObj = dm_getObjectByID(id);
    if (b_IE && e.fromElement && itObj.contains(e.fromElement)) return;       // eliminate flickering

    var smVar = menu.m[itVar.smInd];
    _d_rID = smVar.rootItemID;


    // Timers ------------------------------------------------------------------
    if (menu.hideAllTimer)
    {
        clearTimeout(menu.hideAllTimer);    menu.hideAllTimer = null;
    }
    if (smVar.showTimer)
    {
        clearTimeout(smVar.showTimer);      smVar.showTimer = null;
    }
    //--------------------------------------------------------------------------

    with (itVar) var showSmID = (!isDisabled && childID) ? childID : '';
    with (smVar) var hideSmID = (shownChildID && shownChildID!=itVar.childID) ? shownChildID : '';


    if (menu.isCrossFrame)
    {
        if (typeof(dmCF)==_un) return;
        if (cfType==1 && !dm_isFrameAccessible(smVar.id, menu.cfSFInd)) hideSmID = '';     // if subframe is NOT accessible -> do not hide submenu therein
    }

    smVar.showTimer = setTimeout('dm_waitForSubmenu("'+hideSmID+'","'+showSmID+'","'+itVar.id+'")', smShowPause);
}


function dm_waitForSubmenu(hideSmID, showSmID, parentID)
{
  dm_hideMenu(hideSmID);
  dm_showMenu(showSmID, parentID);
}



function dm_out(e, id)
// Items' mouse over event
{
    var itObj = dm_getObjectByID(id);
    if (b_IE && e.toElement && itObj.contains(e.toElement)) return;       // eliminate flickering

    var itVar  = dm_getVarByID(id);
    var menu   = dm_menu[itVar.mInd];


    var smRVar = menu.m[0]                                                // get the top-menu var
    var smVar  = menu.m[itVar.smInd];

    if (smRVar.shownChildID)
        if (_d_rID!=itVar.id && !(menu.smShowClick && !menu.smShowClicked))
            menu.hideAllTimer = setTimeout("dm_hideMenu('"+smRVar.shownChildID+"');window.status='';", smHidePause);

    if (smVar.showTimer)
    {
       clearTimeout(smVar.showTimer);    smVar.showTimer = null;
    }

    if (itVar.isDisabled) return;
    if (itVar.text!='-' && !itVar.isPressed) dm_changeItemStyle(itVar, 0);
}


function dm_click(e, id)
// Items' mouse click event
{
    var itVar = dm_getVarByID(id);
    if (itVar.isDisabled || itVar.text=='-') return;
    var menu  = dm_menu[itVar.mInd];

    // showByClick-mode is enabled ---------------------------------------------
    if (!itVar.smInd && menu.smShowClick && !menu.smShowClicked && itVar.childID)
    {
        menu.smShowClicked = 1;
        dm_over(e, id);
        return;
    }
    //--------------------------------------------------------------------------

    if (itVar.link!='' && menu.toggleMode>-2 && !itVar.isPressed) dm_ext_setPressedItem(menu.ind, itVar.smInd, itVar.ind, true);  // toggle mode is on, set pressed item
    if (itVar.isDisabled || !itVar.link) return;

    var smRVar = menu.m[0];                                       // get the top-menu var
    if (menu.shownChildID) dm_hideMenu(menu.shownChildID);


    if (menu.hideAllTimer)
    {
        clearTimeout(menu.hideAllTimer);   menu.hideAllTimer = null;
    }

    dm_openItemLink(menu, itVar);
}


function dm_openItemLink(menu, itVar)
{
  if (itVar.isDisabled || !itVar.link) return;
  with (itVar)
  {
      if (!link) return;

      // Hide all submenus on item click
      if (menu.smHideClick)
      {
          moveRec.prepareSmID = '';                       // clear captured submenu ID
          dm_hideMenu(menu.m[0].shownChildID);            // hide submenu
      }

      // execute JavaScript
 	    if (link.toLowerCase().io('javascript:')==0) eval(link.sb(11, link.ln()));
	    else
      {
          if (!target || target=='_self')
          {
              var win = (menu.isCrossFrame && (cfType==1 || cfType==3)) ? parent.frames[menu.cfSFInd] : window;
              win.location.href = link;
          }
          else
              open(link, target);
      }
  }
}



//##############################################################################
// SUBMENU FUNCTIONS
//##############################################################################

function dm_showIFrame(smObj)
// Shows IFRAME object under the submenu
{
  if (!useHTTPS && b_IEPC && b_IE6)
      with (dm_getObjectByID(smObj.id+'frame').style)
      {
          left   = smObj.style.left;
          top    = smObj.style.top;
          width  = smObj.offsetWidth  + 'px';
          height = smObj.offsetHeight + 'px';
          visibility = 'visible';
      }
}


function dm_writeSubmenuHTML(smVar)
// Check for submenu object on page and writes submenus' HTML if it doesn't exist (fast speed for IE, other browsers work with large menus well)
{
  var smObj = dm_gE(smVar.id);
  if (smObj) return smObj;

  var m=dm_menu[smVar.mInd];

  // Create submenu html code if dynamic writting in enabled or AJAX is enabled
  if (!smVar.smHTML) dm_createSubmenuHTML(m, smVar, '', '', dmZOrder, 1);

  // Use insertAdjacentHTML for Opera. It allows to place submenus correctly
  // when the menu is placed within object with relative position.
  // Note: Opera always uses dm_writeAll=0 - always creates submenu dynamically.
  // Use the same method in MAC IE, otherwise it positions submenu incorrectly
  if (b_OP || b_IEMAC) docElement.insertAdjacentHTML('beforeEnd', smVar.smHTML);
  else
      // Insert submenu code within special <div>s that were created earlier.
      // It allows to avoid damage of page styles in Netscape 6
      // and it also allows correctly create submenus when browser uses smart submenu scrolling,
      // because using body.innerHTML resets divs' overflow coords for scrollable submenus.
        dm_gE('dmD'+m.ind+'m'+smVar.ind).innerHTML = smVar.smHTML;

  return dm_gE(smVar.id);
}


function dm_showMenu(id, parentID)
// Shows specified submenu according to root item position and cross-frame mode
{
    if (!id) return;
    if (!docElement) docElement = dm_getDocElement(d_o);
    if (b_NS4) return dm_showMenu4(id);


    // Start downloading submenu data from server and quit the function
    if (id=='_') return dm_downloadSubmenu(parentID);


    var smVar = dm_getVarByID(id);
    var menu  = dm_menu[smVar.mInd];
    var smObj = null;
    var canFilter = (b_IEPC && b_VER>=5.5 && smVar.duration)?1:0;


    // Hide submenus for all menus on the page excluding current menu
    for (var i=0; i<dm_menu.ln(); i++) if (dm_menu[i] && i!=menu.ind) dm_hideSubmenus(i);


    // CREATE SUBMENU AND GET SUBMENU OBJECT ===================================
    if (menu.isCrossFrame)                                                    // Crossframe mode
    {
        if (!(smObj=dm_writeCrossSubmenuHTML(menu, smVar, id))) return;
    }
    else
        if (!(smObj=dm_writeSubmenuHTML(smVar))) return;
    //==========================================================================



    if (typeof(smObj.style.display)!=_un) smObj.style.display = 'block';      // define display property before determine the submenu position and sizes
    var smXY  = dm_getSubmenuXY(smVar);
    var itVar = dm_getVarByID(smVar.rootItemID);

    // SET SUBMENU COORDINATES =================================================
    if (menu.isCrossFrame && cfType==1 && smVar.level==1)                     // Crossframe mode, first-level submenus
        smXY = dm_setCrossSubmenuPos(menu, smVar, smObj, smXY);
    else              // No crossframe mode OR crossframe mode is on and subframe contains page from alien domain
        if (!(smVar.level==1 && menu.isPopup))                // do not set top-level submenu coords in popup mode - to avoid submenu showing in incorrect place in FF/MZ
        {
            var u = (b_OP && b_VER<6) ? '' : 'px';
            with (smObj.style)
            {
                left = smXY[0] + u;
                top  = smXY[1] + u;
            }

            // Frame resizing ------------------------------------------------------
            if (cfType==3 && b_IEPC && b_VER>=5) dm_frameResize(menu, id);
        }
    //==========================================================================


    // Highlight selected item
    menu.m[itVar.smInd].shownChildID = id;
    itVar.isHighlighted = menu.saveNavigation;

    with (smObj.style)
    {
        width  = smXY[2] + 'px';
        height = smXY[3] + 'px';

        // Set submenu scrolling parameters
        with (smVar)
        {
            sX = smXY[0];
            sY = smXY[1];
            sEnabled = 1;
            sObj = smObj;
        }

        // Set submenu's container (div) overflow property
        if (smXY[4])
        {
            if (b_IEMAC)
            {
                height = smXY[3]-20 + 'px';                                   // decrease submenu size for MAC IE for bottom scrollbar
                overflow = 'auto';
            }
            else
            {
                if ((b_NS && b_VER<7) || b_OP) overflow = 'auto';
                else
                {
                   if (smSmartScroll) overflow = 'hidden';
                   else
                      if (b_IE6)
                      {
                          overflow  = 'visible';
                          overflowY = 'scroll';
                      }
                      else
                          overflow  = 'auto';
                }

                // Increase submenu width for right scrollbar
                width = smObj.offsetWidth + (b_OP ? 17 : b_SAF ? 15 : 0) + 'px';
            }

            smObj.scrollTop  = 0;
            smObj.scrollLeft = 0;
        }
        else
        {
            overflow  = 'visible';
            smVar.sEnabled = (b_OP && smXY[4]);
        }

        dm_showIFrame(smObj);

        // Show submenu (using transitional effect in IE)
        if (visibility!='visible')
        {
            if (canFilter) dm_startFilter(smObj, smVar.duration);
            visibility = 'visible';
            if (canFilter) fl.play();
        }
    }


    // Check objects intersection
    if (dmObjectsCheck) dm_checkSubmenuIntersection(smVar, smXY);
}


function dm_startFilter(smObj, dur)
{
  with (fl=smObj.filters[0])
  {
      enabled = 1;
      if (status!=0) stop();
      duration = dur/1000;
      apply();
  }
}

function dm_dehighlightRootItem(menu, smVar)
{
  if (menu.saveNavigation)
  {
      var ritVar = dm_getVarByID(smVar.rootItemID);

      // Mark item as not highlighted
      ritVar.isHighlighted = 0;

      // Clear shown child value for parent submenu
      menu.m[ritVar.smInd].shownChildID  = '';
      
      // Change item appearance
      if (!ritVar.isPressed) dm_changeItemStyle(ritVar, 0);
  }
}

function dm_hideMenu(id)
{
    if (!id) return;
    if (b_NS4) return dm_hideMenu4(id);

    var smObj = dm_getObjectByID(id);
    if (!smObj) return;

    var smVar = dm_getVarByID(id);
    var menu  = dm_menu[smVar.mInd];


    if (smVar.isMoved && !moveRec.isMoving)
    {
        with (smObj.style)
        {
            left = smVar.left + 'px';
            top  = smVar.top  + 'px';
        }
        dm_showIFrame(smObj);
    }


    // Hide all visible submenus
    if (smVar.shownChildID) dm_hideMenu(smVar.shownChildID);
    smVar.shownChildID = '';
    
    // Dehighlight root item
    dm_dehighlightRootItem(menu, smVar);


    if (smVar.showTimer)
    {
        clearTimeout(smVar.showTimer);   smVar.showTimer = null;
    }


    // Hide submenu
    if (!smVar.isMoved && moveRec.prepareSmID!=smVar.id)
    {
        with (smObj.style)
        {
            //if (typeof(display)!=_un) display = 'none';
            var canFilter = (b_IEPC && b_VER>=5.5 && smVar.duration2) ? 1:0
            if (canFilter) dm_startFilter(smObj, smVar.duration2);

            visibility = 'hidden';

            if (canFilter) fl.play();
        }
        
        if (b_IEPC && b_IE6 && !useHTTPS) dm_getObjectByID(id+'frame').style.visibility = 'hidden';  // Hide IFRAME on IE for PC
    }


    // Restore frame size for cross-frame mode
    if (smVar.level==1 && cfType==3 && oldFsetSizes)
    {
        with (parent.document.getElementById(menu.cfFSID))
              if (menu.cfOrient) cols = oldFsetSizes;
              else               rows = oldFsetSizes;
        oldFsetSizes = null;                                                    // clear saved sizes for frames
    }


    // Show submenus on click: if all submenus were hidden -> enable "need-to-click"
    if (menu.smShowClick && menu.hideAllTimer) menu.smShowClicked = 0;


    // Show hidden objects on page
    if (dmObjectsCheck) dm_showIntersectedObjects(smVar);

    //if (keyMode.isEnabled && smVar.level==1) dm_disableKeyMode(menu.ind, 0);
}


function dm_correctSubmenuCoord(xy, wh, docXY, docWH, limY)
// Checks document bounds and correct submenu position
{
  if (xy+wh > docWH && (limY ? docWH-xy<limY : 1)) xy = docWH - wh;
  if (xy    < docXY) xy = docXY;
  return xy;
}


function dm_getSubmenuXY(smVar)
// Returns submenu coords and dimensions: [x, y, width, height, resize]
{
    var menu     = dm_menu[smVar.mInd];
    var smObj    = dm_getObjectByID(smVar.id);

    var smSize = b_NS4 ? dm_getObjectSize(smObj, 0) : dm_getObjectSize(dm_getObjectByID(smObj.id+'tbl'));

    var ritVar   = dm_getVarByID(smVar.rootItemID);
    var rsmVar   = menu.m[ritVar.smInd];

    var ritObj   = dm_getObjectByID(ritVar.id+(b_NS4?'':'tbl'));
    var ritSize  = dm_getObjectSize(ritObj);
    var inDIV    = ritSize[4];
    var rsmObj   = dm_getObjectByID(rsmVar.id);


    var docSize  = dm_getClientSize(menu);
    var x=0, y=0, w=0, h=0, resize=0;

    switch (menu.smView)
    {
        case 1: case 3: y = ritSize[1] + ((rsmVar.ind || !rsmVar.isHoriz)?ritSize[3]:0) - smSize[3]  - smVar.offy;
        break;
        case 0: case 2: y = ritSize[1] + (rsmVar.isHoriz?ritSize[3]:0) + smVar.offy;
        break;
    }
    
    if (rsmVar.isHoriz)
        x = (menu.smAlign=='right')  ?  ritSize[0]+ritSize[2]-smSize[2]-smVar.offx  :  (menu.smAlign=='center')  ?  ritSize[0]+(ritSize[2]-smSize[2])/2  :  ritSize[0]+smVar.offx;
    else
        x = (menu.smView<2)  ?  ritSize[0]+ritSize[2]+smVar.offx  :  ritSize[0]-(rsmVar.isHoriz ? 0 : smSize[2])-smVar.offx;

    // When the menu isn't placed within object with relative/absolute position,
    // correct submenu position on IE MAC using body's margin attributes
    // Do NOT combine the following expressions into with(docElement) statement, because Safari can't detect body's margin attributes
    if (!inDIV && (b_IEMAC || (b_SAF && smVar.level>1)))
    {
        x += b_SAF ? -dm_getParam(parseInt(docElement.marginWidth), 0)  : parseInt(docElement.leftMargin);
        y += b_SAF ? -dm_getParam(parseInt(docElement.marginHeight), 0) : parseInt(docElement.topMargin);
    }
    
    // Correct submenu position for Opera 9
    if (b_OP && b_VER>=9 && smVar.level>1)
    {
        x -= d_o.body.leftMargin;
        y -= d_o.body.topMargin;
    }


    docSize[2] += docSize[0];
    docSize[3] += docSize[1];


    // Set submenu size
    with (smVar.smStyle)
    {
        w = (smW ? parseInt(smW) : smSize[2]) + smVar.shadowLen;
        h = (smH ? parseInt(smH) : smSize[3]) + smVar.shadowLen;
    }

    // Correct submenu position ------------------------------------------------
  if (!inDIV && !(dmRTL && b_IE))                                                       // if submenu isn't placed within object with relative/absolute position
    if (!menu.isCrossFrame || (smVar.level>1 && cfType!=3))
    {
        // Correct submenu position according to scrolling of parent submenu
        if (typeof(rsmObj.scrollLeft)!=_un)
        {
            x -= rsmObj.scrollLeft;
            y -= rsmObj.scrollTop;
        }

        // Check document bounds and correct submenu position
        x = dm_correctSubmenuCoord(x, w, docSize[0], docSize[2], 0);
        y = dm_correctSubmenuCoord(y, h, docSize[1], docSize[3], 200);

        // Check document bounds once again and set new submenu size
        if (x+w > docSize[2]) w = docSize[2]-x;
        if (y+h > docSize[3]) h = docSize[3]-y;

        // Check if submenu must be scrollable
        resize = (w<smSize[2] || h<smSize[3]);


        // Check size for Netscape 6 and correct submenu position and dimensions
        if (b_NS6)
        {
            if (resize) w += 14;
            if (rsmVar.sEnabled) x+= 14;
        }
    }

    return[x,y,w,h,resize];
}


function dm_hideSubmenus(mInd)
// Hides all submenus for specified menu
{
    clearInterval(dm_menu[mInd].hideAllTimer);
    dm_hideMenu(dm_menu[mInd].m[0].shownChildID);
}



//##############################################################################
// EXTERNAL FUNCTIONS
//##############################################################################

function dm_ext_setPressedItem(mInd, smInd, itInd, recursion)
// Sets current pressed item
{
  if (b_NS4) return;
  var menu = dm_menu[mInd];

  // If function doesn't call itself and pressed item exists
  with (menu)
  {
      if (!toggleRec.pressedSelf && menu.curPressedIt!=-1)
      {
          toggleRec.pressedSelf = 1;
          dm_ext_setPressedItem(mInd, curPressedSm, curPressedIt, recursion); // unpress pressed item
          if (curPressedSm==smInd && curPressedIt==itInd)
          {
              curPressedSm = 0;
              curPressedIt = -1;
              return;
          }
      }

      if (!toggleRec.pressedSelf)                                             // if func doesn't call itself -> set new pressed indexes
      {
          curPressedSm = smInd;
          curPressedIt = itInd;
      }
      else
          toggleRec.pressedSelf = 0;
  }

  var itVar = dm_getVarByID('dm'+mInd+'m'+smInd+'i'+itInd);
  with (toggleRec)
  {
      if (!changeStyleOnly) itVar.isPressed = !itVar.isPressed;
      changeStyleOnly = 0;
  }


  dm_changeItemStyle(itVar, (itVar.isPressed?1:0));


  // If recursion is enabled and submenu isn't a root menu
  if (recursion && smInd>0)
  {
      var smVar = menu.m[smInd];
      var ritVar;
      for (var j=smVar.level; j>0; j--)
      {
          ritVar = dm_getVarByID(smVar.rootItemID)
          dm_changeItemStyle(ritVar, (itVar.isPressed?1:0));
          ritVar.isPressed = itVar.isPressed;
          smVar = menu.m[ritVar.smInd];                                       // get next parent submenu
      }
  }
}

