//==============================================================================
//
//     Copyright (c) 2006, by Deluxe-Menu.com
//     http://deluxe-menu.com
//     Version: 3.2.9
//     Modify date: 10:39 08.09.2008
//
//==============================================================================

Array.prototype.ln=function() {return this.length};
function pI(s) {return parseInt(s)};
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; // z-index of first level menu
var _nos = 0;
dm_getBrowser();



// add default value for non-exist variables
var CompSmScroll = (b_NS && b_VER < 7.2); // crossbrowser compatible smartscroll

// Create defult style for TD elements to avoid overriding by TD{} class
var dmDefStyle='background:transparent;border:none;';


//##############################################################################
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>');
}


// Load module for Netscape 4
if (b_NS4) dm_addScript('dmenu4');


//##############################################################################




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 assignFloating = 0;                          // one or more of menus on the page is floatable
var assignMoving   = 0;                          // one or more of menus on the page is movable
var dm_menu   = [];                              // main menu object
var isLoaded  = 0;                               // menus data are loaded and parsed
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 contains the page from alien domain (PC IE only)
var oldFsetSizes;        // variable to remember frame dimensions in frameset (rows/cols attributes of frameset; when cfType=3)
//##############################################################################




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;
  p_LNX  = (nv.platform.io('Linux') != -1);

  // Safari detect
  if (RegExp(" AppleWebKit/").test(navigator.userAgent))// (pI(nv.productSub)>=20020000) && (nv.vendor.io('Apple Computer') != -1) && (nv.product==gk)
  {
      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))
          {
    	        var d = (a.io(ns+'6')>-1) ? 10 : (a.io(ns)>-1) ? 9 : 0;
              b_VER = pf(a.sb(a.io(ns) + d, a.ln()))
          }
          else
              b_VER = pf(v);


          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;
      b_IEMAC  = b_MAC;
  }
}




//##############################################################################
// GLOBAL PARAMS FUNCTIONS
//##############################################################################


dm_preDefineGlobalParams();


function dm_preDefineGlobalParams()
// Pre-defines global menu variables
{
  window.topSmartScroll   = 0;
  window.separatorPadding = '0px';
  dmCacheImages    = 0;
  
  useHTTPS    = location.protocol=='https:' ? 1 : 0;
  dm_writeAll = 0;
  popupMode = 0;
  
  dmSearch = 0;
  
  beforeItemImage=[];
  afterItemImage=[];
  beforeItemImageW=0;
  afterItemImageW=0;
  beforeItemImageH=0;
  afterItemImageH=0;
  
  useIFRAME=0;
  dmIframeEn=0;
  
  onClickSnd='';
  onOverSnd='';
  subMenuVAlign = '';
  ajaxReload = 0;
  
  floatableDX = 15;
  floatableDY = 15;
  
  itemStyles = [];
  menuStyles = [];
}


// getElementByID
function dm_gE(id){
  if(d_o.getElementById) return d_o.getElementById(id); //DOM1
  if(d_o.all) return d_o.all[id]; //MSIE4
  if(d_o.layers) return d_o.layers[id]; //Netscape 4
  return null // not supported
}


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;
  
  // Correct padding value
  if (typeof(itemPadding)!='string') itemPadding += 'px';

  // Using iframe
  dmIframeEn = useIFRAME||(!useHTTPS && b_IEPC && b_IE6)||(p_LNX && b_MZ && b_VER!=1.6);

  // Filter features
  dm_menu.fltEnabled=(typeof(d_o.body.style.filter)=='string') && (navigator.userAgent.toLowerCase().indexOf("opera") < 0);// fix for mac opera
}


//##############################################################################
// 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 += pI(b_NS4?o.pageX:o.offsetLeft);
	  t += pI(b_NS4?o.pageY:o.offsetTop);
	  o = o.offsetParent;
	  if(o && o.tagName!='HTML' && o.tagName!='BODY'){
		l -= o.scrollLeft;
		t -= o.scrollTop}
  }

  // fix special for opera
  if (b_OP && b_VER>=9){
    l -= d_o.body.leftMargin;
    t -= d_o.body.topMargin};

  return [l, t, wh[0], wh[1], d];
}




function dm_getObjectByID(id)
// Returns object by ID
// do not cash this function becase it wrong work in cross-frame mode in ie and raise permission denied error
{
  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 cfSFInd cfMFInd cfFsetID
  if (itVar.smInd!=0 && menu.isCrossFrame && cfType!=3){
    var obj = dm_getObjectInFrame(id, menu.cfSFInd);
	if (!obj) obj = dm_getObjectInFrame(id, menu.cfMFInd);
	return obj;
  }
  else return 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 || id.indexOf('i')>0)
  {
	ex=regexp_i.exec(id);
	if (!ex || !dm_menu[pI(ex[1])] || !dm_menu[pI(ex[1])].m[pI(ex[2])]) return null;
	return dm_menu[pI(ex[1])].m[pI(ex[2])].i[pI(ex[3])];
  }
  else
  {
	ex = regexp_m.exec(id);
	if (!ex || !dm_menu[pI(ex[1])]) return null;
        return dm_menu[pI(ex[1])].m[pI(ex[2])];
  }
}




//##############################################################################
// DOCUMENT FUNCTIONS
//##############################################################################
function dm_getClientSize(menu)
// Returns document dimensions where submenus are placed: [scrollX, scrollY, width, height]
// this is are visible area
{
    var l=0,t=0,w=0,h=0,pw=0,ph=0, cf=(menu && menu.isCrossFrame && cfType==1), cond=(b_NS || b_MZ || b_OP|| b_SAF);
    var frm = cf ? parent.frames[menu.cfSFInd] : 0;


    if (cond)
    {
        var doc = cf ? frm.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;

		//correct window height and width if scrollbars are visible
		if (b_MZ) {// for FF 
			if (doc.scrollMaxX > 0) h -= dm_menu.getScrlWidth();
			if (doc.scrollMaxY > 0) w -= dm_menu.getScrlWidth();
		}
		else if(!b_SAF){ // safari right calc size
			if(doc.document.width>doc.innerWidth) h-=16;
			if(doc.document.height>doc.innerHeight) w-=16;
		}
    }
    else
    {
        var doc = cf ? dm_getDocElement(frm.document) : docElement;
		if (doc) with (doc)
        {
            l = scrollLeft;
            t = scrollTop;
            w = clientWidth;
            h = clientHeight;
        }
    };
    return [l,t,w,h];
}

/**
 * calc scroller width.
 */
dm_menu.getScrlWidth = function()
{
	if (typeof(scrlWidth)==_un)
	{
		if (!b_MZ)
			this.scrlWidth = (b_NS6? 14: b_IE ? 17 : b_OP? 17: b_SAF? 16 : 17); // for MZ default = 19
		else {
			//this crossplatform code for scroll width 
			// this idea for code geting from http://www.fleegix.org/articles/2006/05/30/getting-the-scrollbar-width-in-pixels
			

			var wnd_doc = document;
			
		    // Outer scrolling div
		    var scr = wnd_doc.createElement('div');
		    scr.style.position = 'absolute';
		    scr.style.top = '-1000px';
		    scr.style.left = '-1000px';
		    scr.style.width = '100px';
		    scr.style.height = '50px';
		    // Start with no scrollbar
		    scr.style.overflow = 'hidden';


		    // Inner content div
		    var inn = wnd_doc.createElement('div');
		    inn.style.width = '100%';
		    inn.style.height = '200px';


		    // Put the inner div in the scrolling div
		    scr.appendChild(inn);
		    wnd_doc.body.appendChild(scr);


		    var wNoScroll = inn.offsetWidth;


		    // Add the scrollbar
		    scr.style.overflow = 'auto';
		    var wScroll = inn.offsetWidth;


		    wnd_doc.body.removeChild(wnd_doc.body.lastChild);


		    this.scrlWidth = (wNoScroll - wScroll);
		}
	};
	return this.scrlWidth;
};


function dm_setOnLoad()
// Assigns onLoad event for document
{
  dm_addEvent(window,'onload', dm_onload);
}

function dm_addEvent(obj,event,func)
// Assigns some event for some object
{
	if(!obj)return;
	event=event.toLowerCase();
	if(obj.attachEvent)obj.attachEvent(event,func);
	else {
		var o=obj[event];
		obj[event]=typeof o=='function' ? function(v){
			try{o(v)}catch(e){}; // run old function. try ... catch construction is needed to fix ie7beta2 bug only. New version of ie7 doesn't have this bug
			func(v)
			} : func;
	}
}

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

  // Enable keyboard support
  if (keystrokes && !b_NS4 && !(b_OP && b_VER<7)) d_o.onkeydown = function (event) { return dm_ext_keystrokes(event) };

  // Set default pressed item ------------------------------------------------
  for(var i=0;i<dm_menu.ln();i++)
  with (dm_menu[i])
	if ((toggleMode>=0)&&(curPressedIt>=0)){                                                // toggle mode is on -> highlight top-menu item
		toggleRec.pressedSelf = 1;                                        // menu calls dm_ext_setPressedItem() itself, not user
		dm_ext_setPressedItem(ind, curPressedSm, curPressedIt, 0);
	}
}



//##############################################################################
// CROSS-FRAME FUNCTIONS
//##############################################################################


function dm_initFrame(fsetID, mFrameInd, sFrameInd, orient)
// Initializes cross-frame mode
{
  if (b_NS4) return dm_init4();                               // there is 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://", 'search:'];


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)
// Checks specified parameter value or returns default value
{
  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
  if (!sp) return defValue;													// if set non-existing style


  // 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].split('=')[0].replace(' ','')==pName) break;


  var val = sp[i].split('=')[1];                                            // get parameters' value
  
  // if values are array -> create the array of values  
  if (val.io(',')>=0){
	var reg="('[^']+')|([^,']+)";// this regexp for string view 'sd','asd,',sas,123
	var res = [];
	while (val){
		var pos=val.search(reg);
		if (pos<0) break;
		var tmp = val.match(reg)[0];
		val=val.sb(pos+tmp.ln(),val.ln());
		if (tmp.sb(0,1)=='\'' && tmp.sb(tmp.ln()-1,tmp.ln())=='\'') tmp=tmp.sb(1,tmp.ln()-1);
		res[res.ln()] = tmp;
	}
	val = res;
	//val = val.split(',');
  }

  return val;
}


function dm_getSubmenuStyle(menu, sInd, is)
// @menu - parent menu object (not submenu), =null if style geting for main submenu
// @sInd - style index
// 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 : pI(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),
	  // sound
	  onClickSnd : dm_getStyleParam('onClickSnd',       sInd, 0, onClickSnd, is),
	  onOverSnd  : dm_getStyleParam('onOverSnd',        sInd, 0, onOverSnd, is),
	  smHidePause: dm_getStyleParam('smHidePause',      sInd, 0, smHidePause, is),
	  horiz      : dm_getStyleParam('smOrientation',    sInd, 0, -1, is)
  };

  return st;
}




function dm_getItemStyle(menu, sInd, is)
// Returns specified item style
// @menu - menu parameters (not submenu)
// @sInd - index 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 bII = is ? dm_getStyleParam('beforeItemImage',  sInd, 1, '', is) : 0;
  var aII = is ? dm_getStyleParam('afterItemImage',  sInd, 1, '', is) : 0;

  var bIIW = is ? dm_getStyleParam('beforeItemImageW',  sInd, 1, 0, is) : 0;
  var aIIW = is ? dm_getStyleParam('afterItemImageW',  sInd, 1, 0, is) : 0;
  var bIIH = is ? dm_getStyleParam('beforeItemImageH',  sInd, 1, 0, is) : 0;
  var aIIH = is ? dm_getStyleParam('afterItemImageH',  sInd, 1, 0, is) : 0;

  var _smShowClick =	!menu?0:dm_getStyleParam('showByClick', sInd, 1, menu.smShowClick, is);

  var st = {
      itWidth    : dm_getStyleParam('itemWidth',        sInd, 1, '100%', is),
      itHeight   : dm_getStyleParam('itemHeight',       sInd, 1, '100%', is),//(b_MAC&&b_IE)?'auto':
      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),
	  backImgB   : bII ? dm_setPathPrefix(bII, pPrefix) : dm_setPathPrefix(beforeItemImage,  pPrefix),
	  backImgA   : aII ? dm_setPathPrefix(aII, pPrefix) : dm_setPathPrefix(afterItemImage,  pPrefix),
	  backImgBW  : bIIW ? bIIW : beforeItemImageW,
	  backImgAW  : aIIW ? aIIW : afterItemImageW,
	  backImgBH  : bIIH ? bIIH : beforeItemImageH,
	  backImgAH  : aIIH ? aIIH : afterItemImageH,
      // CSS
      cssClass     : dm_getStyleParam('CSS',     sInd, 1, cssItem, is),
      cssClassText : dm_getStyleParam('CSSText', sInd, 1, cssItemText, is),
	  smShowClick  : pI(_smShowClick)
  };

  // correct array param if set as not array
  if (typeof(st.fntStyle)=='string') st.fntStyle = [st.fntStyle,st.fntStyle];

  return st;
}


//##############################################################################
// MENU PARAMETERS FUNCTIONS
//##############################################################################


function dm_createMenuParams(curInd)
// Creates menu parameters
{

   	this.m            = [];                     // menu arrays

    this.ind          = curInd;                 // index of the menu
    this.id           = 'dm'+curInd;            // HTML id
    this.hideAllTimer = null;                   // timer to hide all submenus

    this.absPos       = absolutePos;
    this.flt          = floatable;
    this.fltX         = floatableX;
    this.fltY         = floatableY;
    this.fltIter      = floatIterations;
	this.fltDX	     = floatableDX;
	this.fltDY        = floatableDY;

    // Toggle mode
	this.toggleMode   = pressedItem;

    this.curPressedSm = 0;
    this.curPressedIt = (pressedItem>=0) ? pressedItem : -1;
    // Cross-frame mode
    this.isCrossFrame = cfEnabled;
    this.cfMFInd      = cfMFrameInd;
    this.cfSFInd      = cfSFrameInd;
    this.cfOrient     = cfOrientation;          // 0 - top-to-bottom, 1 - left-to-right; 2 - bottom-to-top; 3 - right-to-left.
    this.cfFSID       = cfFsetID;
    // Standard styles
    this.standardSmStyle = dm_getSubmenuStyle(null, 0, 0);
    this.standardItStyle = dm_getItemStyle(null, 0, 0);
    // CSS mode
    this.isCSSMode    = cssStyle;
    // Common
    this.isPopup        = popupMode;            // context menu mode
    this.saveNavigation = saveNavigationPath;   // show highlighted items during a menu nvigation
    this.smShowClick    = showByClick;          // show submenus by mouse click only

	this.smSmartScroll  = (b_IEMAC)?0: (typeof(smSmartScroll)==_un)? 1: smSmartScroll;//(b_NS && b_VER<7) || b_OP || 


    this.isVisible  = (popupMode)?0:1;          // menu is visible
    this.isDisabled = 0;                        // menu is disabled

    // Disabled item params
    this.fntColorDisabled = fontColorDisabled;


    this.smAlign    = subMenuAlign;
    this.smHideClick= smHideOnClick;
    this.cacheImages= dmCacheImages;


    this.sepImg = separatorImage;
    this.sepW   = separatorWidth;
    this.sepH   = separatorHeight;
    this.sepVImg= separatorVImage;
    this.sepVW  = separatorVWidth;
    this.sepVH  = separatorVHeight;
    this.sepPadding = separatorPadding;

    this.pPrefix_img= pathPrefix_img;
  //};*/
    dm_menu[curMenu.ind]  = this;
//  return this; //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;


  // ------- for "no-cash" order when ajax always loading and for all may be good, but not call usualy
  if (parentIt && parentIt.childID && (parentIt.childID!='_')) // if child id already exists then keep it
	curMenu.smInd = dm_getVarByID(parentIt.childID).ind;
  else
  //--------
    curMenu.smInd = menu.m.ln();
  var ii=curMenu.smInd;


  // ------- for "no-cash" order when ajax always loading and for all may be good, but not call usualy
  // destroy old object if exists. This call recreates it with new code
  if (menu.m[ii] && menu.m[ii].sObj)
	menu.m[ii].sObj.parentNode.removeChild(menu.m[ii].sObj);
  // ----------

  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
//	  parentSubMenu: parentSm,								   // 
      shownChildID : '',                                       // current shown submenu ID
      showTimer    : null,                                     // timer for delay the appearance of submenus
	  hideTimer	   : null,									   // timer for delay to hide submenu 
      level        : lvl,                                      // submenu level
      // Positioning only for main menu
      left         : ii ? '-1000px' : posX,
      top          : ii ? '0px'     : posY,
	  // align for submenu relative parent item
	  hAlign	   : (subMenuAlign.io('right')!=-1) ? (-1) : (subMenuAlign.io('center')!=-1) ? 0 : 1,
	  hParent	   : (subMenuAlign.sb(0,1)=='p'),
	  vAlign	   : (subMenuVAlign.io('bottom')!=-1) ? (-1) : (subMenuVAlign.io('center')!=-1) ? 0 : 1,
	  vParent	   : (subMenuVAlign.sb(0,1)=='p'),
      // 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, ''),
      mainHeight   : ii ? 'auto' : dm_getParam(menuHeight, ''),

      // Effects
      opacity      : !ii ? 100 : transparency,					// submenu opacity
      effect       : !ii ? -1 : (transition>=0)? transition: -1,// transition type, if transition isn't >=0 then effects is off 
      duration     : transDuration,								// transition delay (on show)
      duration2    : transDuration2,							// transition delay (on hide)
      // Shadow
  	  shadowColor  : shadowColor,
  	  shadowLen    : (shadowLen && dm_menu.fltEnabled) ? shadowLen : 0, // dm_menu.fltEnabled - fix for ie8
      smHTML       : '',                                       // HTML code of the submenu
      // For submenu scrolling
	  SmartScroll	: ii? parentM.smSmartScroll : topSmartScroll, // smartscroll menu
	  sX			: 0,
      sY			: 0,
      sEnabled		: (!ii && topSmartScroll) ? 1 : 0,			// scrollbar is opened

      sObj			: null,

      // Objects' intersection
      hidObjs       : [],
	  hideOff       : 0, // off hide method, it need for stick menu by dm_ext_setPressedItem
	  
	  cashImage		: function ()
	  { 
		for (var j = 0;j<this.i.ln();j++) this.i[j].cashImage() 
	  }
  };

  //correct parameters (such as isHoriz by style seting)
  with (menu.m[ii])
	if (smStyle.horiz>=0)
		isHoriz = (smStyle.horiz=='1'?1:0);

  // add methods
  menu.m[ii].StartHide = function (time){
    if (this.hideOff) return; // see hideOff for detail
	
	if (this.level == 0) return;
	if (typeof(time)==_un) time = this.smStyle.smHidePause;
	if (!this.hideTimer && time >= 0)
		this.hideTimer = setTimeout("dm_hideMenu('"+this.id+"');window.status=''", time);
  };
  
  menu.m[ii].StopHide = function (){
	if (this.hideTimer) this.hideTimer = clearTimeout(this.hideTimer)
  };
  
  curMenu.smVar = menu.m[ii];
}

function dm_stopTimeOut(smVar)
// stop hide for this and parent submenu
{
	while (smVar) {
		smVar.StopHide();

		if (smVar.rootItemID) smVar = dm_menu[smVar.mInd].m[dm_getVarByID(smVar.rootItemID).smInd];
		else break}
}

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                                                               // set childID to '_' if the item will load submenu data from server
      text    : iText,
      link    : iLink,
      target  : iTarget,
      tip     : iTip,
      sstr    : dm_getStatusText(statusStr, iText, iLink, iTip),
      align   : iAlign,
      valign  : 'middle',
      cursor  : (iLink)? itemCursor: 'default',
      // 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   : (!parentSm.ind || typeof(arrowWidthSub)==_un || !arrowWidthSub)? arrowWidth: arrowWidthSub,
      arrowH   : (!parentSm.ind || typeof(arrowHeightSub)==_un || !arrowHeightSub)? arrowHeight: arrowHeightSub,
      // 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,
	  tblObj		: null,											// table, label,image item tags
	  textObj		: null,
	  imgObj		: null,
	  arrObj		: null,

	  // define Show by Click for specific submenu
      smShowClicked  : 0,

      // .js filename, AJAX: submenu data are placed within another .js file on the server
      ajax : iAJAX,

	  cashImage		: function (){
		this.backImgObj = new dm_imgArray(this.id + 'bi', this.itStyle.backImage);
		this.backImgAObj = new dm_imgArray(this.id + 'bia', this.itStyle.backImgA);
		this.backImgBObj = new dm_imgArray(this.id + 'bib', this.itStyle.backImgB);
		this.iconObj = new dm_imgArray(this.id + 'bii', this.icon);
	  }
  };

  curMenu.itInd = itInd;
  curMenu.itVar = smVar.i[itInd];
  curMenu.smVar = parentSm;

  // type of item: 
  // 0 - item is image-based
  // 1 - item is separator
  // 2 - item copmosite background item
  // 3 - common item or
  // 4 - search bar
  with (smVar.i[itInd]){
	// init item style
	smVar.i[itInd].itemType =	(link.io('search:')==0)? 4:
				(!text)? 0:
				(text=='-')?1:
				((itStyle.backImgB.length>0 && itStyle.backImgB[0]) || (itStyle.backImgA.length>0 && itStyle.backImgA[0]))? 2:3;
  }
};



//##############################################################################
// 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)
{
/*
	"filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100)" for IE 5.5+
	"-khtml-opacity" for Konqueror 3.1, Safari 1.1
	"-moz-opacity" for Mozilla 1.6 and less
	"opacity" for CSS3 - Mozilla 1.7b +, Firefox 0.9 +, Safari 1.2+, Opera 9 
*/
  var sf = '';
  with (smVar)
      if (b_IE5 && b_IEPC)
      {
          if (effect>=0) // effects is off?
          {
              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+")";
		  if (sf) sf = 'filter:' + sf;
      }
      else if ((b_NS || b_MZ) && opacity!=100) sf = '-moz-opacity:'+opacity/100;
	  else if ((b_SAF/* || b_KNQ*/) && opacity!=100) sf = '-khtml-opacity:'+opacity/100+';opacity:'+opacity/100;


  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+(CompSmScroll?'style="position:relative;top:0;left:0;"':'' )+' >'; // style="position:relative;top:0;left:0; - fix smartscroll bug for Netscape 7.1
}


function dm_openTableSimple(id, spac, padd, styleText, events, add) {
   return '<Table id="'+id+'" '+events+' cellspacing='+spac+' cellpadding='+padd+' '+add+' style="'+styleText+(CompSmScroll?';position:relative;top:0;left:0;':'' )+'" border=0>';  // position:relative;top:0;left:0; - fix smartscroll bug for Netscape 7.1
}


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) {
  if (url=='') return ''; // if no src in image then current html page load instead it
  return '<img id="'+id+'" src="'+url+'" '+(w ? 'width='+w : '') + (h ? ' height='+h : '') +' '+add+' border=0>';
}


function dm_mouseSmOut(smID)
{
	// hide all submenus of current menu
	var smVar = dm_getVarByID(smID);
	if (smVar.smStyle.smHidePause<0) return; // do not close

	// find last open submenu in this menu
	while (smVar && smVar.shownChildID) smVar = dm_getVarByID(smVar.shownChildID);

	// close all opened
	var maxTime = smVar.smStyle.smHidePause;
	while (smVar && smVar.level>0 && smVar.smStyle.smHidePause>=0){
		maxTime = Math.max(maxTime, smVar.smStyle.smHidePause);
		smVar.StartHide(maxTime);
			
		smVar = dm_menu[smVar.mInd].m[dm_getVarByID(smVar.rootItemID).smInd];
	}
}


function dm_mouseSmOver(smID)
{
	// clearTimeout for this and all parent submenu
	dm_stopTimeOut(dm_getVarByID(smID));
}


function dm_openSeparator(menu, img, w, h) {
	return dm_openImg('', dm_setPathPrefix(img, menu.pPrefix_img), (w?w:"100%"), (h?h:"1"), 'style="display:block;"');
}




function dm_openItemArrow(itVar, textStyle)
{
  var s='', smVar=dm_menu[itVar.mInd].m[itVar.smInd];
  if (!textStyle) textStyle = '';
  
  with (itVar)
  {
      var arrImg = smInd ? itStyle.arrowSub[0] : itStyle.arrowMain[0];
      if (arrImg)
          s = dm_openTdSimple(itVar.id+'tdA', dmDefStyle + 'padding:'+smVar.smStyle.itPadding + ';' + textStyle, '')+
              dm_openImg(id+'arr', arrImg, arrowW, arrowH, '')+
              dm_closeTd();
  }
  return s;
}


// create item with image
function dm_openItemImage(TDid, TDstyleText, TDadd, IMGid, url, w, h, IMGadd)
{
	if (h == 0) h = '';
	if (w == 0) w = '';
	s = dm_openTdSimple(TDid, TDstyleText, TDadd)+
		dm_openImg(IMGid, url, w, h, IMGadd)+
		dm_closeTd();


	return s;
}



function dm_scrollSubmenu(e, smID)
{
  var smVar = dm_getVarByID(smID);
  if (!smVar.sEnabled ) return; //|| smVar.shownChildID
  
  if (!smVar.sObj) smVar.sObj = dm_getObjectByID(smVar.id);
  if (!smVar.sObj) return;
  
  var smWH = dm_getObjectSize(smVar.sObj);
  
  var ex, ey;

  if (b_IEComp)
  {
      ex = e.clientX;//e.x+cs[0];
      ey = e.clientY;//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);

  dm_setScrollPos(smVar,px,py);
}


function dm_setScrollPos(smVar,px,py){
// set relative srcoll pos

	// trim coordinate
	if (px > 1) px = 1;
	if (px < 0) px = 0;
	if (py > 1) py = 1;
	if (py < 0) py = 0;

	if (!smVar || !smVar.sObj) return;
	var smWH = dm_getObjectSize(smVar.sObj);

	if (CompSmScroll){
		// for Netscape use move table metod
		tblObj = dm_gE(smVar.id+'tbl');
		tblWH = dm_getObjectSize(tblObj);
	
		tblObj.style.left = px*(smWH[2] - tblWH[2]);
		tblObj.style.top = py*(smWH[3] - tblWH[3])}
	else {
		smVar.sObj.scrollLeft = px*(smVar.sObj.scrollWidth  - smWH[2]);
		smVar.sObj.scrollTop  = py*(smVar.sObj.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 valign="top" 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_mouseSmOver(\''+smVar.id+'\')" onMouseOut="dm_mouseSmOut(\''+smVar.id+'\')"

        + (!smVar.ind 
			? dm_openImg('', dm_setPathPrefix(blankImage, menu.pPrefix_img), (smVar.isHoriz?moveWidth:1), (smVar.isHoriz?1:moveHeight), 'style="display:block"')
			: dm_addCloseBtn(menu, smVar))

//        + (smVar.isHoriz?dm_openImg('',dm_setPathPrefix(blankImage, menu.pPrefix_img),moveWidth,'1',''):'')//'<br>'+
		+ '</td>';
}


function dm_deMoveSubmenu(smID)
{
  with (dm_getVarByID(smID))
  {
      isMoved = 0;
      moveRec.prepareSmID = '';
      moveRec.smVar = null;
  }
  dm_hideMenu(smID);
}
// End of movable menu ---------------------------------------------------------


//##############################################################################
// SOUND FUNCTIONS
//##############################################################################

var dm_sound={
	bgHtml: '',
	bgObj: null,
	sndPlaying: ''
};
dm_sound.init = function(smVar) {
	var s = '';
	if (!b_IE) return ' '; // sound effect require setup plugin in firefox
		if (!this.bgHtml) {
			this.bgHtml = '<BGSOUND id="dm_snd" style="visibility:hidden;">';
			s = this.bgHtml}
		s += '<DIV STYLE="position:absolute;">';
		if (smVar.smStyle.onOverSnd)
			s += '<EMBED SRC="'+ smVar.smStyle.onOverSnd +'" AUTOSTART="FALSE" HIDDEN="TRUE">';
		if (smVar.smStyle.onClickSnd)
			s += '<EMBED SRC="'+ smVar.smStyle.onClickSnd +'" AUTOSTART="FALSE" HIDDEN="TRUE"">';
		s +='</DIV>';
	return s;
};
dm_sound.playOver = function(smVar){
	this.startPlay(smVar.smStyle.onOverSnd);
};
dm_sound.playClick= function(smVar){
	this.startPlay(smVar.smStyle.onClickSnd);
};
dm_sound.startPlay= function(snd){
	if (!this.bgHtml || !snd || this.sndPlaying) return; // if no sound effect or no sound or already play
	if (!this.bgObj) this.bgObj = dm_gE('dm_snd');  // cash dm_snd object
	this.sndPlaying = snd;
	this.bgObj.src = snd;
	setTimeout("dm_sound.sndPlaying = '';", 80);
};
var _d_rID='';
var dm_EventPause = {
	val:'',
	timeout: null
};
dm_EventPause.set = function(aVal){
	this.timeout = clearTimeout(this.timeout);
	this.val = aVal;
};
dm_EventPause.clear = function(aVal){
	if (this.val == aVal)
		this.timeout=setTimeout("dm_EventPause.val = '';", 10);
};



//##############################################################################
// 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);
}

var dm_wnd;
var dm_doc;


function dm_init()
// Creates the menu
{
    if (b_NS4) {
		dm_init4();
		return
	};
		
    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);
	
	// Search script
	if (dmSearch) dm_addScript('dmenu_search', 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/window (current menu index).
    dm_wnd = cfEnabled ? parent.frames[cfSFrameInd] : window;// init submenu widow object
   
	if (typeof(dm_wnd.dm_crossMenuInd)==_un)
        dm_wnd.dm_crossMenuInd = curMenu.ind;
    else
    {
        curMenu.ind = dm_wnd.dm_crossMenuInd+1;
        dm_wnd.dm_crossMenuInd++;
    }

    // If it's the first menu on the page -> attach new onload event
    if (!curMenu.ind) dm_setOnLoad();

	
    var menu = new dm_createMenuParams(curMenu.ind);                              // create common params of the menu

	menu.dm_mdoc = cfEnabled ? parent.frames[cfMFrameInd].document : window.document;			  // main menu document element
	menu.dm_sdoc = cfEnabled ? parent.frames[cfSFrameInd].document : window.document;			  // submenus document element

	dm_doc = dm_wnd.document;
    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 Arial;">&nbsp;</div>');

	
	
	// set hide on scroll and on click when hide by click mode enable (smHidePause=-1)
	// this code need basicaly for safari, other browser fire scroll event only if page scrolling
	dm_menu.winParam=dm_getClientSize();
	function hideOnScroll(){
		var newParam=dm_getClientSize();
		if (newParam[0]!=dm_menu.winParam[0] || newParam[1]!=dm_menu.winParam[1])
			dm_hideAll();
		dm_menu.winParam=newParam;
	};
	
	try{
		dm_addEvent(dm_wnd,'onscroll',hideOnScroll);
		dm_addEvent(dm_wnd.document.body,'onclick',dm_hideAll);
		for (var i = 0; i<dm_wnd.frames.length; i++)
			if (dm_wnd.frames[i]){
				var obj = dm_wnd.frames[i];
				dm_addEvent(obj,'onscroll',dm_hideAll);
				dm_addEvent(obj,'onclick',dm_hideAll);// for FF
				if (obj && obj.document && obj.document.body)
					dm_addEvent(obj.document.body,'onclick',dm_hideAll);// for IE
		}
	}catch(e){};


	
	// Create style for special <DIV id="dmlinks"> where menu links are placed (for search engines)
//	if (cfSFrameInd) wnd.document.body.innerHTML += '<style>#dmlinks{display:none}</style>';
	d_o.write('<style>.dmlinks{display:none} #dmlinks{display:none}</style>');

    // Show IFRAME under top-menu
//    if (!menu.isCrossFrame && menu.absPos) dm_showIFrame(dm_gE(menu.m[0].id));


    curMenu.ind++;
    curMenu.curPressedIt = -1;
}//end dm_init()

function dm_getSearchBar(smInd, style){
// Get code for searchbar
	var s= '<span><input onfocus="if(typeof(this.defword)==_un){if(this.value)this.defword=this.value;else this.defword=\'\'};if(typeof(this.oldvalue)==_un)this.oldvalue=\'\';this.value=this.oldvalue" onblur="this.oldvalue=this.value;this.value=this.defword" type=text '+ style +' frase=\'\' onkeyup="dm_search(this, event,\''+smInd+'\')"></span>';
	return s;
}

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)
// create html code for menu
{
    //var menu = dm_menu[ind];
    var s='',ss='';
    var pos    = menu.absPos    ? 'absolute' : (menu.flt?'relative': 'static'); 
    var vis    = menu.isVisible ? 'visible'  : 'hidden';

  	s = dm_openDivSimple('dmD'+menu.ind, '', '');			// add div for place menu content
    // Create HTML code
    for (var smInd=0; smInd<menu.m.ln(); smInd++)			// run submenus
    {
        ss += dm_createSubmenuHTML(menu,
                                  menu.m[smInd],
                                  pos,
                                  vis,
                                  0);

		// Always write HTML for top menu
		if (!smInd || dm_writeAll) s +=ss;
		if (!dm_writeAll) break;

        ss   = '';
        pos = 'absolute';
        vis = 'hidden';
    }// for (submenus)

	s += dm_closeDiv();
	d_o.write(s);


    // Create additional divs.
    // They will be used for creating submenus on the fly.
    // Without such divs 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, 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 = (!smVar.SmartScroll);
  var NS6 = (b_NS && b_VER<7);
  var smBack;
  
  var zOrder = dmZOrder + smVar.level;

  // 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 (dmIframeEn) //if (!useHTTPS && b_IEPC && b_IE6) 
      s = '<iframe id="'+smVar.id+'frame" framespacing =0 border="0" frameBorder=no dm=1 style="visibility:hidden;position:absolute;filter:alpha(opacity=0);height:0px;top:0px;z-index:'+zOrder+';"></iframe>';


  with (smVar)
  with (smStyle)
  {
      smBack = 'background-color:'+backColor+';'+(backImage? 'background-image:url('+backImage+');background-repeat:'+backRepeat+';' : '');


	  var h, w, divW, divH;
	  if (smInd){
		w   = 'width:' + (smW ? smW : '1px') + ';';
		h   = smH ? 'height:'+smH+';' : '';
		divW = w;
		divH = h;
	  }
	  else{	// for first level
		// set minimal menu width if it is not set - this need for noWrap;
		// NS6 and safari not set auto width on whole window
		w  = 'width:'  + (mainWidth?  mainWidth  : ((b_NS && (b_VER<7)) ? 'auto' : '1px')) +';';

		h  = 'height:' + (mainHeight? mainHeight : ((b_NS && (b_VER<7)) ? 'auto' : '1px')) +';'; // in IE code 'isHoriz?'100%'  do not work

		if (topSmartScroll){
			divW = 'width:' + (mainWidth?  mainWidth  : 'auto')+';';
			divH = 'height:' + (mainHeight? mainHeight : 'auto') +';'
		}
		// - for non-smartscroll in case 'w=1px' and 'divW=w' menu has small width in IE7
		// - if set to auto (or ='') and relative position then shadow not display in IE7
		// - if divW=100% or ''  then menu realy width = 100% and in safari show menu  background on hole page
		// - if divW=100% or '' and absolute position then menu covers hole page
		else{
			divW = menu.absPos?'':'width:100%;';
			divH = ''
		}

	  }

	  // border set to outer div if not smartscroll menu, otherwise to inner table
	  var borderStyle = ';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.
	  var innerBorder = ((ind && b_IE && shadowLen) || (!ind && !SmartScroll)); // set inner border

      var of  = (!ind && SmartScroll) ? 'overflow:hidden;' : '';
      var flt = (!smInd && shadowTop) || smInd;


	  // if smartscroll then set size of div - this without fail for ie rtl mode
      var divStyle = (divH+divW)+';position:'+(pos?pos:'absolute')+';left:'+left+';'+'top:'+top+';'+
					 (!innerBorder && !menu.isCSSMode? borderStyle:'')+
                     (NS6 ? smBack : '')+disp+';visibility:'+(vis?vis:'hidden')+';z-index:'+zOrder+';'+
                     (flt ? dm_getFilterHTML(smVar)+';' : '') +
					 of;


      if (shadowLen && flt) divStyle += 'padding:0px '+shadowLen+dUnits+' '+shadowLen+dUnits+' 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)
  // try ...cacth construction need only for fix small bug menu execute while page reload
  s += dm_openDivSimple(smVar.id, divStyle,
						(!innerBorder && menu.isCSSMode?'class="'+smVar.smStyle.cssClass+'" ':'') + 
//                        'onMouseOver="try{'+frame+'dm_mouseSmOver(\''+smVar.id+'\')}catch(e){}" onMouseOut="try{'+frame+'dm_mouseSmOut(\''+smVar.id+'\')}catch(e){}"'+ (noScroll?'':'onMouseMove="'+frame+'dm_scrollSubmenu(event,\''+smVar.id+'\')"')
                        'onMouseOver="'+frame+'dm_mouseSmOver(\''+smVar.id+'\')" onMouseOut="'+frame+'dm_mouseSmOut(\''+smVar.id+'\');return true"'+ (noScroll?'':'onMouseMove="'+frame+'dm_scrollSubmenu(event,\''+smVar.id+'\')"')
					   );


  // Create submenu table ------------------------------------------------
  if (menu.isCSSMode) s += dm_openTableWithClass(smVar.id+'tbl', (innerBorder? smVar.smStyle.cssClass:''), smVar.smStyle.itSpacing, 0, '');
  else
      with (smVar.smStyle)
      {
          var tblStyle = 'padding:0px;margin:0px;'+(!NS6 ? smBack : '') + //width:100%;
						 (innerBorder? borderStyle:'') + ';' +
						 w + h; // set menu table size equal div size
          s += dm_openTableSimple(smVar.id+'tbl', smVar.smStyle.itSpacing, 0, tblStyle, '', '');
      }


  var ss, disp;
  colInd = -1;
  addRow = 1;

  smVar.cashImage();
  

  // 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){
	    // Create first <tr> and move spacer if need
		if (smVar.isHoriz) {
			ss += dm_openTr('');

			if (smVar.moving) // Create move spacer
				ss += dm_openMoveSpacer(menu, smVar)// <td>..</td>
		}
		else{
			if (smVar.moving) // Create move spacer 
				ss += dm_openTr('')
					+ dm_openMoveSpacer(menu, smVar)// <td>..</td>
					+ dm_closeTr();

			ss += dm_openTr(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', dmDefStyle + 'padding:0px;'+disp, '') +
            dm_createItemTable(menu, smVar, itVar, frame) +
            dm_closeTd();
            
      s += ss;
  }


  s += dm_closeTr()+dm_closeTable() + dm_closeDiv();
  
  // create sound object
  if (!smVar.ind) s+=dm_sound.init(smVar);

  smVar.smHTML = s;                                                           // save HTML code for the submenu
  

  return s;
}

// create array of item for preload images
// 1. create HTML code for request image
// 2. return image
var dm_allImage=[]; // registred image object
function dm_imgArray(id,links){
	this.id = id;
	this.links = [];

	// init object param - add links
	this.add = function(links){
		for (var i=0; i < links.ln();i++)
			// create images objects
			if (links[i] && !dm_allImage[links[i]]){
				var img = new Image();
				img.onload = function(){this.dm_ready=1};
				img.src = links[i];
				dm_allImage[links[i]] = img}
		this.links = this.links.concat(links);
	};

	// get image src property
	this.getImg = function(ind){
		var img;
		if ((this.links.ln() <= ind) || !this.links[ind]) img = 0;
		else
			img = dm_allImage[this.links[ind]];

		if (img && (img.dm_ready==1 || (b_MAC&&b_SAF))) return this.links[ind];
		else{
			if (this.links[0]) return this.links[0];
			return ''}};

	// get string for background
	this.getBg = function(ind,lbl){
		var txt = this.getImg(ind);
		if (txt) txt = (lbl?'background-image:':'') + 'url(' + txt + ')' + (lbl?';':'');
		return txt};

	if (links) this.add(links);
//	return this;
}


function dm_createItemTable(menu, smVar, itVar, frame)
// Creates item table (menu item object)
// parse itVar and create item object
{
  var ss = '';

  // Create events ---------------------------------------------------
  // try ...cacth construction need only for fix small bug menu execute while page reload
  var events = 'onMouseOver="'+frame+'dm_over(event,\''+itVar.id+'tbl\');return true" '+
               'onMouseOut="'+frame+ 'dm_out(event,\''+itVar.id+'tbl\')" ';
/*  var events = 'onMouseOver="try{'+frame+'dm_over(event,\''+itVar.id+'tbl\')}catch(e){}" '+
               'onMouseOut="try{'+frame+ 'dm_out(event,\''+itVar.id+'tbl\')}catch(e){}" ';*/
  events += '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 (itVar.itStyle)
          var tblStyle = 'height:'+itHeight +';padding:0px;margin:0px;width:'+itWidth+';cursor:'+dm_checkCursor(itVar.cursor) +
                         ';background-color:'+backColor[0]+';' + 
						 ((itVar.itemType!=2)? itVar.backImgObj.getBg(0,true):'') +
                         '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[0]+';color:'+(itVar.isDisabled?menu.fntColorDisabled:fntColor[0])+'; text-decoration:'+fntDecor[0]+';';


  // Create item cells =========================================================
  if (itVar.itemType==0)														// item is image-based
  {
        ss += dm_openTdSimple(itVar.id+'tdT', (textCSS?'':dmDefStyle), textCSS) +
              dm_openImg(itVar.id+'img', itVar.iconObj.getImg(0), '', '', 'alt="'+itVar.tip+'"') +
              dm_closeTd();
  }
  else
    if (itVar.itemType==1)														// item is separator
    {
        with (menu)
        {
            ss += dm_openTdSimple(itVar.id+'tdT', (textCSS?'':dmDefStyle) + '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 left part backgroundImage -------------------------------------
		var itemBackComposit = '';
		if (itVar.itemType == 2)
			with (itVar.itStyle){
				if (itVar.backImgBObj.getImg(0))
					ss += dm_openItemImage(itVar.id+'tdLImg', (textCSS?'':dmDefStyle), textCSS, itVar.id+'limg', itVar.backImgBObj.getImg(0), backImgBW, backImgBH, '');

				itemBackComposit = itVar.backImgObj.getBg(0,true);
			}

		// arrow located here for RTL mode
		if (dmRTL && itVar.childID) ss += dm_openItemArrow(itVar, 0);


        // Create item icon --------------------------------------------
        if (itVar.iconObj.getImg(0)) ss += dm_openTdSimple(itVar.id+'tdIc', dmDefStyle + 'padding:'+smVar.smStyle.itPadding +';' + itemBackComposit, '') +
                                 dm_openImg(itVar.id+'ic', itVar.iconObj.getImg(0), itVar.iconW, itVar.iconH, '')+
                                 dm_closeTd();

        // Create item text --------------------------------------------
        if (itVar.text||itVar.itemType==4)
            ss += dm_openTdSimple(itVar.id+'tdT', (textCSS?'':dmDefStyle) + 'width:100%;'+textStyle + itemBackComposit, (noWrap ? ' NOWRAP ':'')+textCSS)+
                  itVar.text+ (itVar.itemType==4? dm_getSearchBar('dm'+itVar.mInd+'m'+itVar.smInd, itVar.link.sb(7,itVar.link.ln())) :'') +
                  dm_closeTd();


        // Create item arrow-image -------------------------------------
		// arrow located here for non-RTL mode
        if (!dmRTL && itVar.childID) ss += dm_openItemArrow(itVar, itemBackComposit);


        // Create item right part backgroundImage-------------------------------------
		with (itVar.itStyle)
			if ((itVar.itemType == 2) && (itVar.backImgAObj.getImg(0))){
				ss += dm_openItemImage(itVar.id+'tdRImg', (textCSS?'':dmDefStyle), textCSS, itVar.id+'rimg', itVar.backImgAObj.getImg(0), backImgAW, backImgAH, '');
				}

    }

  return ss+dm_closeTr('')+dm_closeTable();
}




//##############################################################################
// ITEMS FUNCTIONS
//##############################################################################
function dm_changeItemStyle(it, over)
// Changes item appearance
{
  if (!dm_getObjectByID) return; // this need for small bug menu execute while page reload
  over = it.isHighlighted ? 1 : over; 
  if (b_NS4) {
	dm_changeItemStyle4(it, over);
	return 
  };

  var itObj = dm_getObjectByID(it.id+'tbl');
  if (!itObj) return;

  // Image-based item, change image only
  if (it.itemType == 0)
  {
		var e=dm_getObjectByID(it.id+'img');
		if (e) e.src = it.iconObj.getImg(over);
      return;
  }

 
  with (it.itStyle)
  {
      if (dm_menu[it.mInd].isCSSMode) itObj.className = cssClass[over];
      else
      {
          var is = itObj.style;
		  if (brdWidth) is.borderWidth = brdWidth+dUnits;
          if (backColor[over]) is.backgroundColor = backColor[over];
          if (brdColor[over])  is.borderColor     = brdColor[over];
          if (brdStyle[over])  is.borderStyle     = brdStyle[over];

		  if (it.itemType!=2) is.backgroundImage = it.backImgObj.getBg(over,false);

		  // change background image for composite background image
		  // backImage backImgB backImgA backImgBW backImgAW
		  if ((it.itemType==2) && itObj.rows[0])
			with (itObj.rows[0]){
				if(cells[0].childNodes[0]) cells[0].childNodes[0].src = it.backImgBObj.getImg(over);
				for (var i = 1; i < cells.length - 1; i++)
					cells[i].style.backgroundImage = it.backImgObj.getBg(over,false);
				cells[cells.length - 1].childNodes[0].src = it.backImgAObj.getImg(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 (fntStyle[over]) font = fntStyle[over];
                  if (fntDecor[over]) textDecoration = fntDecor[over];
              }
      }
  }

  with (it)
  {
      if (it.iconObj.getImg(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 = it.iconObj.getImg(over);
                  icState = over;
              }


	  var ao = dm_getObjectByID(it.id+'arr');
      if (ao)
      {
          var arr = smInd ? itStyle.arrowSub[over] : itStyle.arrowMain[over];
          if (childID && arr) ao.src = arr;
      }
  }
};


function dm_over(e, id)
// Items' mouse over event
// e  - event
// id - item id
{
    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)
        {
          _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){// if not disable and not spacer and not pressed
			  isHighlighted = 1;
              dm_changeItemStyle(itVar, 1);

			  }


    // Check if user should click on item to show submenu
    var smVar = menu.m[itVar.smInd];

	// start sound
    if (id!=dm_EventPause.val && !itVar.isDisabled && itVar.text!='-') dm_sound.playOver(smVar);
    dm_EventPause.set(id);
    
    // out from previous item - write for safari, it do not generate out event for item which out by smartscroll
	// this code must be before clear out timer. it required  for  Safari on Mac and Konqueror only, but it is useful for other browsers too.
//	if (b_MAC && b_SAF)
	if (smVar.selected && smVar.selected != id)	dm_out(e, smVar.selected);
	smVar.selected = id;

	// Clear hide timers 
	// if item is parent of current visible menu then clearTimeout for submenu of curent item
	// this code need before handle smShowClick parameter in other case menu hide while mouse over by it
	if (itVar.childID && (itVar.childID == smVar.shownChildID)){
		var smChild = dm_getVarByID(itVar.childID);
		if (smChild){
			obj = menu.m[smChild.ind];
			if (obj) obj.StopHide()}}

    var itObj = dm_getObjectByID(id);
    if (b_IE && e.fromElement && itObj.contains(e.fromElement)) return;       // eliminate flickering

	// clear show timers
	// this code must be after "eliminate flickering" otherwise menu not show at all
    if (smVar.showTimer){
        clearTimeout(smVar.showTimer);
		smVar.showTimer = null}

	if (itVar.itStyle.smShowClick && !itVar.smShowClicked) return;      // if the item is top-menu item and showByClick-mode is enabled -> return
		itVar.smShowClicked = 0;


    _d_rID = smVar.rootItemID;

    with (itVar) var showSmID = (!isDisabled && childID) ? childID : '';
    with (smVar) var hideSmID = (shownChildID && shownChildID!=itVar.childID) ? shownChildID : '';




	// ----- this code for always loading ajax submenu - "no-cash" order - do not remove
	if (itVar.ajax && ajaxReload){
		if ((smVar.shownChildID!='') && (smVar.shownChildID != showSmID)) dm_hideMenu(smVar.shownChildID);
		showSmID ='_';
	}
	//------

    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 out event
{
	// clear time out for sound
	dm_EventPause.clear(id);
	
    var itVar  = dm_getVarByID(id);		// specified item

	if (b_IE){
		var itObj = dm_getObjectByID(id);	

		if (!itObj) return;
		if (b_IE && e.toElement && itObj && itObj.contains(e.toElement)) return;       // eliminate flickering
	}


    var menu   = dm_menu[itVar.mInd];									  // menu which contents this item


    var smVar  = menu.m[itVar.smInd]; // submenu of specified item

    // without fail hide submenu of this item, if smHidePause - not mean hide by click
    if (smVar.level > 0) smVar.StartHide();

    if (smVar.showTimer)
    {
       clearTimeout(smVar.showTimer);    smVar.showTimer = null;
    }


    // delete highlighting
	with (itVar)
    {
        if (isDisabled || (text=='-') || isPressed) return;
		if (menu.saveNavigation && itVar.childID && (smVar.shownChildID == itVar.childID))// keep highlighting if submenu is open
			return;
		isHighlighted = 0;
		dm_changeItemStyle(itVar, 0);
    }
	
	if (smVar.selected==id) smVar.selected=0;
}


var dm_menuClicked = -1; // this need for hide by click
function dm_click(e, id)
// Items' mouse click event
{
    var itVar = dm_getVarByID(id);

	// menu clicked for hideByClick and not close 
	dm_menuClicked = itVar.mInd;
	setTimeout("dm_menuClicked = -1", '50');
	
    if (itVar.isDisabled || itVar.text=='-') return;
    var menu  = dm_menu[itVar.mInd];
	var smVar = menu.m[itVar.smInd];

	dm_sound.playClick(smVar);

    // showByClick-mode is enabled ---------------------------------------------
	// 13:30 21.03.2008 add itVar.childID - for open link if no childID
	if (itVar.childID && itVar.itStyle.smShowClick && !itVar.smShowClicked)
	{
		itVar.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);

    dm_openItemLink(menu, itVar);
}


function dm_openItemLink(menu, itVar)
{
  if (itVar.isDisabled || !itVar.link) return;
  with (itVar)
  {
      if (!link||link.toLowerCase().io('search:')==0) 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 JavaScriptq
 	    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;
			  try{ win.location.href = link }catch(e){}
          }
          else
              open(link, target);
      }
  }
}




//##############################################################################
// SUBMENU FUNCTIONS
//##############################################################################


function dm_showIFrame(smObj)
// Shows IFRAME object under the submenu
{
  if (dmIframeEn)
      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, '', '', 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 submenus dynamically.
  // Use the same method in MAC IE, otherwise it positions submenus incorrectly
  if (b_OP || b_IEMAC) docElement.insertAdjacentHTML('beforeEnd', smVar.smHTML);
  else{
		// Insert submenu code within special divs 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.
		var cont = dm_gE('dmD'+m.ind);
		var obj = d_o.createElement('DIV');
        obj.innerHTML = smVar.smHTML;
		cont.appendChild(obj);
	};


  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) {
		dm_showMenu4(id);
		return
	};

    // Start downloading submenu data from server and quit the function
    if (id=='_') {
		dm_downloadSubmenu(parentID);
		return
	};


    var smVar = dm_getVarByID(id);
    var menu  = dm_menu[smVar.mInd];
	
    var smObj = null;


    // 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)
	{
		if (!(smObj=dm_writeCrossSubmenuHTML(menu, smVar, id))) return;
	}
	else
		if (!(smObj=dm_writeSubmenuHTML(smVar))) return;
    //--------------------------------------------------------------------------


	// fix scrollLeft scrollTop document bug for rtl mode
	if (dmRTL && b_IE){
		smObj.style.left = '0';
		smObj.style.top = '0';}

	// Define display property before determine submenu's position and sizes
    if (typeof(smObj.style.display)!=_un) smObj.style.display = 'block';
    var smXY  = dm_getSubmenuXY(smVar);
	if (!smXY) return;														 // this need for small bug menu execute while page reload
    var itVar = dm_getVarByID(smVar.rootItemID);


    //--------------------------------------------------------------------------
    // SET SUBMENU COORDINATES
    //--------------------------------------------------------------------------
        // No crossframe mode OR crossframe mode is on and subframe contains page from alien domain.
        // Do not set top-level submenu coords in popup mode - to avoid submenu showing in incorrect place in FF/MZ.
        if (!(smVar.level==1 && menu.isPopup))
        {
            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];
            sObj = smObj;
        }


        // Set submenu's container (div) overflow property
        if (smXY[4])
        {
			smVar.sEnabled = 1;
            if (b_IEMAC)
            {
                overflow = 'auto';
            }
            else
            {
                   if (smVar.SmartScroll) overflow = 'hidden';
                   else
                      if (b_IE6)
                      {
                          overflow  = 'visible';
						  if (smVar.isHoriz) overflowX = 'scroll';
						  else  overflowY = 'scroll';
                      }
                      else
                          overflow  = 'auto';
            }
			dm_setScrollPos(smVar,0,0)
        }
        else
        {
            overflow  = 'visible';
			if (b_IE6){
				overflowX = '';
				overflowY = ''}
			dm_setScrollPos(smVar,0,0);
			smVar.sEnabled = 0;
        }


        dm_showIFrame(smObj);


        // Show submenu (using transitional effect in IE)
        if (visibility!='visible')
        {
			var fl = dm_startFilter(smObj, smVar.duration);
            visibility = 'visible';
			display = '';
            if (fl) fl.play();
        }
    }


    // Check objects intersection
    if (dmObjectsCheck) dm_checkSubmenuIntersection(smVar, smXY);
}



// start filter object
function dm_startFilter(smObj, dur)
{
	if (smObj.filters && smObj.filters[0])
		with (smObj.filters[0])
		{
			enabled = 1;
			if (status!=0) stop();
			duration = dur/1000;
			apply();
			return smObj.filters[0]
		}
	else return;
}


function dm_dehighlightRootItem(menu, smVar)
{
  if (menu.saveNavigation)
  {
      var ritVar = dm_getVarByID(smVar.rootItemID);
	  if (!ritVar) return -1;

	  if (menu.isPopup && menu.m[ritVar.smInd].level==0) return;

      // 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)
// hide menu and its submenu
{
    if (!id) return;
    if (b_NS4) return dm_hideMenu4(id);

    var smVar = dm_getVarByID(id);
	var smObj = dm_getObjectByID(id);

    if (!smObj) return;

    var menu  = dm_menu[smVar.mInd];

	// on hide posibility
	smVar.hideOff = 0;
	
    if (smVar.isMoved && !moveRec.isMoving)
    {
        with (smObj.style)
        {
            left = smVar.left + 'px';
            top  = smVar.top  + 'px';
        }
        dm_showIFrame(smObj);
    }

    // Hide visible child-submenus (recursive)
	dm_hideMenu(smVar.shownChildID);
    smVar.shownChildID = '';


    // Dehighlight root item
    dm_dehighlightRootItem(menu, smVar);


    if (smVar.showTimer)//????
    {
        clearTimeout(smVar.showTimer);   smVar.showTimer = null;
    }
	smVar.StopHide();


    // Hide submenu
    if (!smVar.isMoved && moveRec.prepareSmID!=smVar.id)
    {
        with (smObj.style)
        {
            //if (typeof(display)!=_un) display = 'none';
            var fl = dm_startFilter(smObj, smVar.duration2);

            visibility = 'hidden';
			display = 'none';

            if (fl) fl.play();
        }
        
        if (dmIframeEn)
			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 hidden objects on page
    if (dmObjectsCheck) dm_showIntersectedObjects(smVar);
	if (typeof(onHideEvent)!=_un && onHideEvent) eval(onHideEvent+'("'+ smVar.id +'")');
}


function dm_getSubmenuXY(smVar)
// Returns submenu coords and dimensions: [x, y, width, height, resize]
{
    var menu     = dm_menu[smVar.mInd];				// selected submenu
    var smObj    = dm_getObjectByID(smVar.id);		// object of selected menu

	// this feature need for calc offset between style coordinates and fact calced offset... coordinates to set it
	smObj.style.left = '0';
	smObj.style.top = '0';
	var smOffset = dm_getObjectSize(smObj);

    var smSize   = b_NS4 ? dm_getObjectSize(smObj, 0) : dm_getObjectSize(dm_getObjectByID(smObj.id+'tbl'));

    var ritVar   = dm_getVarByID(smVar.rootItemID);	// parent(root) item of selected menu
    var rsmVar   = menu.m[ritVar.smInd];			// root submenu
    var rsmObj   = dm_getObjectByID(rsmVar.id);		// parent submenu
	if (!rsmObj) return;							// this need for small bug menu execute while page reload
	var rsmSize  = b_NS4 ? dm_getObjectSize(rsmObj, 0) : dm_getObjectSize(dm_getObjectByID(rsmObj.id+'tbl'));

    var ritObj   = dm_getObjectByID(ritVar.id+(b_NS4?'':'tbl'));
    var ritSize  = dm_getObjectSize(ritObj);		// size of parent item
	if (menu.isCrossFrame && cfType==1 && smVar.level==1)
		ritSize  = dm_getCrossItemPosSize(smVar,ritObj);

	// if submenu aligned relative parent menu, but no item
	if (smVar.hParent){
		ritSize[0]=rsmSize[0];
		ritSize[2]=rsmSize[2]}
	if (smVar.vParent){
		ritSize[1]=rsmSize[1];
		ritSize[3]=rsmSize[3]}

	// add offsets
	ritSize[0]-=smVar.offx;
	ritSize[1]-=smVar.offy;
	ritSize[2]+=2*smVar.offx;
	ritSize[3]+=2*smVar.offy;

    var inDIV    = ritSize[4];
	var scrollbarW = dm_menu.getScrlWidth();//may by cross-browser scroller width

    var docSize = dm_getClientSize(menu);			// available size of document
    var x=0, y=0, w=0, h=0, resize=0;

    // Set submenu size beforehand
    with (smVar.smStyle)
    {
        w = (smW ? pI(smW) : smSize[2]) + smVar.shadowLen;
        h = (smH ? pI(smH) : smSize[3]) + smVar.shadowLen;
    }

	// increase parent size for previous scrollbar
	if (!inDIV && !(dmRTL && b_IE)&& (!menu.isCrossFrame || (smVar.level>1)) && rsmVar.sEnabled && !smVar.SmartScroll) {
		if (rsmVar.isHoriz)	ritSize[3] += scrollbarW;
		else 				ritSize[2] += scrollbarW;}


	// 1. calc scrolled coordinate (basicaly Y)  --------
	var tmpXY = dm_CalcMenuPos(
							!smVar.isHoriz ? docSize[1]: docSize[0],
							!smVar.isHoriz ? docSize[3]: docSize[2],
							!smVar.isHoriz ? ritSize[1]: ritSize[0],
							!smVar.isHoriz ? ritSize[3]: ritSize[2],
							!smVar.isHoriz ? h: w,
							
							!smVar.isHoriz ? rsmVar.vAlign: rsmVar.hAlign,
							!smVar.isHoriz ? !rsmVar.isHoriz: rsmVar.isHoriz);
	if (smVar.isHoriz){
		x = tmpXY.xy;
		smVar.hAlign = tmpXY.align;
		
		resize = (smSize[2] + smVar.shadowLen != tmpXY.size);
		w = tmpXY.size;}
	else{
		y = tmpXY.xy;
		smVar.vAlign = tmpXY.align;
		
		resize = (smSize[3] + smVar.shadowLen != tmpXY.size);
		h = tmpXY.size;}


	// 2b. correct menu size down (non-scroll coordinate) to  menu scrollbar, if not smartscroll and not scroll bar allready enable (release in parent function)
	if (resize && !smVar.SmartScroll){
		if (smVar.isHoriz)//for FF, Netscape, Opera 6 
			h += scrollbarW;
		else
			w += scrollbarW	}


	// 3. calc non-scrolled coordinate (basicaly X) -----------
	var tmpXY = dm_CalcMenuPos(
							smVar.isHoriz ? docSize[1]: docSize[0],
							smVar.isHoriz ? docSize[3]: docSize[2],
							smVar.isHoriz ? ritSize[1]: ritSize[0],
							smVar.isHoriz ? ritSize[3]: ritSize[2],
							smVar.isHoriz ? h: w,
							
							smVar.isHoriz ? rsmVar.vAlign: rsmVar.hAlign,
							smVar.isHoriz ? !rsmVar.isHoriz: rsmVar.isHoriz);
	if (smVar.isHoriz){
		y = tmpXY.xy;
		smVar.vAlign = tmpXY.align;
		}
	else{
		x = tmpXY.xy;
		smVar.hAlign = tmpXY.align;
		}


	// 4. corect position ------------------
    // 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(pI(docElement.marginWidth), 0)  : pI(docElement.leftMargin);
        y += b_SAF ? -dm_getParam(pI(docElement.marginHeight), 0) : pI(docElement.topMargin);
    }

	x -= smOffset[0];// this feature apply offset between style coordinates and fact calced offset... coordinates to set it
	y -= smOffset[1];
	
    return [x,y,w,h,resize];
}



function dm_CalcMenuPos(screenXY, screenSize, parentXY, parentSize, size, align, oHoriz, space)
// calc menu pos for one coordinate 
// use size of menu, parent object and screen, menu direction and parent menu orientation
// screenSize - size of screen
// parentXY, parentSize - position and size of parent menu
// size - size of selected menu
// align = +1(right, bottom), 0(center), -1(left, top)  - direction of menu
// oHoriz  = 0(vertical), 1(horizontal) - orientation of parent menu
// space - gap to border of browser view port 
{
	var xy = parentXY;
	var newSize = size;
	var newAlign = align;
	if(typeof(space)==_un) space = 15; // space to document borders
	
	if ((align == 0) && (!oHoriz)) align = 1; //center may be only for horizontal orientation
	
	if (!oHoriz) {// VERTICAL
		// |------<-------->(---------------)<----------->------|
		// check the place for the future menu and correct orientation
		if	(((newAlign >= 0) && (parentXY + parentSize + size > screenSize + screenXY - space)) // don't go in screen from the algin
							|| ((newAlign < 0) && (parentXY - size < space))){
			// correct direction about most of place
			if (parentXY - screenXY > screenSize + screenXY  - (parentXY + parentSize)) newAlign = -1; else newAlign = 1;
		}
		// set coordinate and size
		if (newAlign >= 0){
			xy = parentXY + parentSize;
			if (screenSize + screenXY - space - xy < newSize) newSize = screenSize + screenXY  - space - xy;
		}
		else {
			xy = parentXY - newSize;
			if (xy - screenXY < space){
				xy = space + screenXY;
				newSize = parentXY - space - screenXY;
			}
		}
	}
	else {
		// |--------------(---------------)-----------------|
		// |------<----------------------->-----------------|
		// |--------------<-------------------------->------|
		// if menu not go in screen with spaces
		if (newSize > screenSize - 2*space) {
			xy = screenXY + space;
			newSize = screenSize - 2*space;
			//if menu go in screen without spaces
			/*if (newSize < screenSize) xy += (screenSize - newSize)/2; // centered
			else newSize = screenSize; // resize*/
		}
		else{
			// calc
			xy = parentXY + parentSize/2 - newSize/2 + newAlign * (newSize/2 - parentSize/2);


			// correct
			if (xy < space + screenXY){
				newAlign = 1;
				xy = space + screenXY;
			}
			if (xy + size > screenSize  + screenXY - space){
				newAlign = -1;
				xy -= xy + newSize - (screenSize  + screenXY - space);
			}
		}
	}


	return {xy: xy, size: newSize, align: newAlign}
}




function dm_hideSubmenus(mInd)
// Hides all submenus for specified menu
{
    dm_hideMenu(dm_menu[mInd].m[0].shownChildID);
}


function dm_hideAll(){
// hide all opened menu except dm_menuClicked
	for (var i=0; i<dm_menu.ln(); i++)
		if (dm_menu[i] && dm_menu[i].m[0].shownChildID && dm_menuClicked != i){

		// find in this menu last open submenu whith  pause = -1
		var smVar = dm_getVarByID(dm_menu[i].m[0].shownChildID);
		while (smVar && smVar.smStyle.smHidePause >= 0)
			smVar = dm_getVarByID(smVar.shownChildID);
			
		if (smVar) dm_hideMenu(dm_menu[i].m[0].shownChildID);
	}
}



//##############################################################################
// EXTERNAL FUNCTIONS
//##############################################################################

// Sets current pressed item
// @mInd - menu index
// @smInd - submenu index
// @itInd - item index
// @recursion - recusive press all parent items
// @parentOpen - open all submenu for show selected item
function dm_ext_setPressedItem(mInd, smInd, itInd, recursion, parentOpen)
{
  if (b_NS4) return;
  var menu = dm_menu[mInd];

  with (menu)
  {
      // unpress pressed item if function doesn't call itself and pressed item exists 
      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 func doesn't call itself -> set new pressed indexes
      if (!toggleRec.pressedSelf)
      {
          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;
  }


  if (!itVar.isPressed) itVar.isHighlighted = 0;
  dm_changeItemStyle(itVar, (itVar.isPressed?1:0));


	// get all parent item
	var parentItems = [];
	var smVar = menu.m[smInd];
    for (var j=smVar.level; j>0; j--)
    {
		parentItems[parentItems.length] = dm_getVarByID(smVar.rootItemID);
		smVar = menu.m[parentItems[parentItems.length-1].smInd];                        // get next parent submenu
	}
  
	// If recursion is enabled and submenu isn't a root menu
	if (recursion && smInd>0)
		for (var i = 0; i < parentItems.length; i++){
			dm_changeItemStyle(parentItems[i], (itVar.isPressed?1:0));
			parentItems[i].isPressed = itVar.isPressed
		}
  
	// open pressed submenus
	if ((typeof parentOpen) != 'undefined' && parentOpen)
		for (var i = parentItems.length - 1; i >= 0; i--){
			dm_showMenu(parentItems[i].childID, parentItems[i].id);
			dm_getVarByID(parentItems[i].childID).hideOff = 1; // off hide posibility
		}
}

