//******************************************************************************
//     Apycom Deluxe Tab v1.0
//     www.deluxe-tabs.com
//     Copyright (c) 2006, by Deluxe-Menu.com
//
//******************************************************************************

var isIE  = 0;
var isIE5 = 0;
var isNS  = 0;
var isNS4 = 0;
var isOP  = 0;
var isOP7 = 0;
var isMZ  = 0;
var isVER = 0;
var isDOM = 0;
var isMAC = 0;
var isIEComp = 0;                               // IE compatible (such as all IE and Opera 7)

var bmenuInd = 0;                               // n of tabs menu on page
var dtabs_tabs = [];                              // tabs object
var _Tab = 0;
var bmoveFlag=false;

var dtabs_bisLoaded  = 0;                        // is menu loaded
var bloadFunc = null;

var s="";                                       // HTML menu code
var smHTML="";                                  // HTML submenus code
var zind=2000;                                  // layers' z-index

// Document object variable depending on <DOCTYPE> (detects in apys' onLoad event)
// Using as document.body object.
var docElement;
//-------------

dtabs_bBrowser();

function dtabs_bBrowser() { // Detects browsers' name & version
    var a = navigator.userAgent;
    var n = navigator.appName;
    var v = navigator.appVersion;
    isMAC = v.indexOf("Mac") >= 0;
    isDOM = document.getElementById?1:0;

    // --- Safari detect ---//
    var ist = (parseInt(navigator.productSub) >= 20020000) && (navigator.vendor.indexOf("Apple Computer") != -1);
    if (ist && navigator.product == "Gecko")
    {
      isNS  = 1;
      isVER = 6;
      return;
    }
    // ---------------------//

    // --- Konqueror detect ---//
    if (n.toLowerCase()=="konqueror")
    {
      isMZ  = 1;
      isVER = 1.6;
      return;
    }

        if (a.indexOf("Opera")>=0)
    {
    	isOP = 1;
    	isVER = parseFloat(a.substring(a.indexOf("Opera")+6,a.length));
    }
    else
      if (n.toLowerCase()=="netscape")
      {
      	if (a.indexOf("rv:") != -1 && a.indexOf("Gecko") != -1 && a.indexOf("Netscape")==-1)
       {
         isMZ  = 1;
         isVER = parseFloat(a.substring(a.indexOf("rv:")+3,a.length));
        }
      	else
        {
          isNS = 1;
	  if (a.indexOf("Gecko") != -1 && a.indexOf("Netscape") > a.indexOf("Gecko"))
          {
	    if (a.indexOf("Netscape6") > -1) isVER = parseFloat (a.substring(a.indexOf("Netscape")+10,a.length));
	    else
              if (a.indexOf("Netscape") > -1) isVER = parseFloat (a.substring(a.indexOf("Netscape")+9,a.length));
          }
          else
            isVER = parseFloat (v);
        }	
      }
      else
        if (document.all?1:0)
        {
          isIE  = 1;
          isVER = parseFloat (a.substring(a.indexOf("MSIE ")+5,a.length));
        }
    isNS4 = isNS && isVER<6;
    isIE5 = isIE && isVER>=5;
    isOP7 = isOP && isVER>=7;
    isIEComp = isIE || isOP7;
}


function dtabs_bgetPageScroll() {
  var sx = isIEComp?docElement.scrollLeft:pageXOffset;
  var sy = isIEComp?docElement.scrollTop:pageYOffset;
  return [sx,sy]
}

function dtabs_bgetObjectStyleXY(obj) {
  with (obj) return [(isNS4)?left:parseInt(style.left), (isNS4)?top:parseInt(style.top)];
}

function dtabs_bsetObjectStyleXY(obj, nx, ny) {
  with (obj){ 
  if (isNS4) {
      left = nx;
      top  = ny;
    }
    else {
      style.left = nx;
      style.top  = ny;
    }
  }
}

function dtabs_bScrollWindow() { // Assign to scroll page event (for floatable menu)
 if (bmoveFlag) return;
 for (var j=0; j<dtabs_tabs.length; ++j)
   if (dtabs_tabs[j].floating && dtabs_tabs[j].abspos)
   {
      var mnu = dtabs_bgetObjectByID ("dtabs_b" + j + "div");
      var mnuXY   = dtabs_bgetObjectStyleXY(mnu);                // get current coords from object.style
      var pageOff = dtabs_bgetPageScroll();                      // get page scroll offset
      var l = pageOff[0] + dtabs_tabs[j].left;                  // calculate absolute menu coords
      var t = pageOff[1] + dtabs_tabs[j].top;                   // ---

      if (mnuXY[0]!=l || mnuXY[1]!=t)                          // if coords must be changed
      {
        var dx = (l - mnuXY[0])/dtabs_tabs[j].iterations;       // calculate delta coords
        var dy = (t - mnuXY[1])/dtabs_tabs[j].iterations;       // ---

        if (dx>-1 && dx<0) dx = -1;                                  // check if |delta-coord x|<1 -> correct to 1/-1
        else if (dx>0 && dx<1) dx = 1;                               // ---
        if (dy>-1 && dy<0) dy = -1;                                  // ---
        else if (dy>0 && dy<1) dy = 1;                               // ---
        dtabs_bsetObjectStyleXY(mnu, mnuXY[0] + ((mnuXY[0]!=l)?dx:0), mnuXY[1] + ((mnuXY[1]!=t)?dy:0));
       }
   }
}

function dtabs_type() {

  if (tabMode!=0) _Tab = 1;
}

function dtabs_bload() {
  // Detect document object according to <DOCTYPE> specification
  docElement = (document.compatMode=="CSS1Compat" && !isMZ)?document.documentElement:document.body;

  //===== Initialize floatable menu ==========================================
  if (!isNS4 && !(isOP && isVER<6))                     // cancel floatable mode for Opera 5: links don't work if enabled
    for (var j=0; j<dtabs_tabs.length; ++j)
      if (dtabs_tabs[j].floating && dtabs_tabs[j].abspos)
      {
        window.setInterval ("dtabs_bScrollWindow()", 20);
        break;
      }
  //==========================================================================

  //===== Set objects visibility for Tabs menu =============================================
 if (!_Tab)
  {
    for (var i=0; i<dtabs_tabs.length; i++)
       for (var j=0; j<dtabs_tabs[i].tabs.length; j++)
          dtabs_bsetObjectVisibility(dtabs_bgetObjectByID(dtabs_tabs[i].tabs[j].link), (dtabs_tabs[i].selectedItem==j), false);
  //==========================================================================

  //===== Set objects transition filter ========================================

    if (isIE5 && !isMAC)
     {
      for (var i=0; i<dtabs_tabs.length; i++)
        for (var j=0; j<dtabs_tabs[i].tabs.length; j++)
         if (dtabs_tabs[i].eff != -1 && dtabs_tabs[i].dur>0)
          {
           var obj = dtabs_bgetObjectByID(dtabs_tabs[i].tabs[j].link);
           if (obj)
            obj.style.filter = dtabs_bsetFilter(dtabs_tabs[i]);
          }
     }
  }
  //==========================================================================
  
  dtabs_bisLoaded = 1;	                               // all data were loaded
  if (bloadFunc) bloadFunc();                          // execute user's onLoad event

}

//------------------------------------------------------------------------------
// Attach own onload event to user defined onload event
// (only if user defined event till this script)
function dtabs_bsetOnLoad() {
  if (window.attachEvent)                                                     // attach onload event if possible
    window.attachEvent("onload", dtabs_bload);
  else                                                                        // or save user onload event into varible
  {
    bloadFunc = (typeof(onload)=='function')?onload:null;                       // remember user's onLoad event one time
    onload = dtabs_bload;                                                         // set own onLoad event one time
  }
}
//------------------------------------------------------------------------------

function dtabs_bGetParam(param, defparam) {
  return (typeof(param) != "undefined" && param)?param:defparam;
}

function dtabs_bcheckGlobalParams() {
  pos = (babsolute)?"absolute":"static";              // menu position
  if (typeof(bmenuHeight) == "undefined") bmenuHeight = 0;
  if (typeof(bseparatorWidth) == "undefined") bseparatorWidth = 10;
  if (bselectedItem<0) bselectedItem = 0;

  if (typeof(btransition) == "undefined") btransition = -1;
  if (typeof(btransDuration) == "undefined") btransDuration = 0;
  if (typeof(btransOptions) == "undefined") btransOptions = "";
}

function dtabs_init() {

    if (!bmenuInd)
      {  dtabs_type();
         dtabs_bsetOnLoad();
      }
      
    dtabs_bcheckGlobalParams();

    dtabs_tabs[bmenuInd] = {                                            // Create treemenu object dtabs_tabs[bmenuInd]
       	tabs         : [],                                            // menu main items
       	id           : "dtabs_b" + bmenuInd,                            // HTML id
       	left         : bleft,
       	top          : btop,
       	floating     : bfloatable,
       	abspos       : babsolute,
       	iterations   : (bfloatIterations<=0)?6:bfloatIterations,
       	width        : bmenuWidth,
      	height       : bmenuHeight,
       	borw         : bmenuBorderWidth,                              // border width
       	borstyle     : bmenuBorderStyle,
       	borc         : bmenuBorderColor,
       	bgc          : bmenuBackColor,                                // menu background color
       	bgimage      : bmenuBackImage,                                // menu background image
        iconalign    : biconAlign,
        orientation  : bmenuOrientation,
        beforeSpace  : bbeforeItemSpace,
        afterSpace   : bafterItemSpace,
        rowSpace     : browSpace,
        selectedItem : bselectedItem,
        dur : btransDuration,
        eff : btransition,
        selectedSmItem : bselectedSmItem,
        smBackColor   : bsmBackColor,
        smBorderColor : bsmBorderColor,
        smBorderStyle : bsmBorderStyle,
        smBorderWidth : bsmBorderWidth,
        smItemSpacing : bsmItemSpacing,
        smItemPadding : bsmItemPadding

    };
    var root = dtabs_tabs[bmenuInd];
    var bitem;
    var bitemID = "";

    //--------------------------------------------------------------------------
    //start parse bmenuItems variable and init items
    //--------------------------------------------------------------------------
    var cl;           // number of "|" in current item (level)

    // Variables for individual styles -----------------------------------------
    var fntColors,
        fntStyles,
        fntDecors,
        bgcs,
        borcs,
        borws,
        borstyles,
        text_,
        iconw_,
        iconh_;
        
    // Save global params ------------------------------------------------------
    //var gfntStyles = bfontStyle;
    var gfntColors = [bfontColor[0],      dtabs_bGetParam (bfontColor[1], ""), dtabs_bGetParam (bfontColor[2], "")];
    var gfntDecors = [dtabs_bGetParam (bfontDecoration[0],  "none"), dtabs_bGetParam (bfontDecoration[1],  "none"), dtabs_bGetParam (bfontDecoration[2],  "none")];
    var gbgcs      = [bitemBackColor[0],  dtabs_bGetParam (bitemBackColor[1],   ""), dtabs_bGetParam (bitemBackColor[2],   "")];
    var gborws     = bitemBorderWidth;
    var gborcs     = [bitemBorderColor[0], dtabs_bGetParam (bitemBorderColor[1],""), dtabs_bGetParam (bitemBorderColor[2], "")];
    var gborstyles = [bitemBorderStyle[0], dtabs_bGetParam (bitemBorderStyle[1],""), dtabs_bGetParam (bitemBorderStyle[2], "")];
    var gbgimages  = [bitemBackImage[0],   dtabs_bGetParam (bitemBackImage[1],  ""), dtabs_bGetParam (bitemBackImage[2],   "")];

    var giconw = biconWidth;
    var giconh = biconHeight;
    var bitemWidth_;
    var bbeforeItemImage_, bafterItemImage_, bgimagesSpec;
    //--------------------------------------------------------------------------
    var singleStyle;      // individual style number
    var rowCnt   = 0;
    var levelCnt = 0;
    var parentItem = -1;
    var target_ = "_self";


    for (var i=0; (i<bmenuItems.length && typeof(bmenuItems[i]) != "undefined"); i++)
    {
        cl=0;
        if (bmenuItems[i][0].charAt(0)=="$")
        {
          bmenuItems[i][0] = bmenuItems[i][0].substring (1, bmenuItems[i][0].length);  // remove '$' from item text
          rowCnt++;   // add tabs row
        }
        while (bmenuItems[i][0].charAt(cl)=="|") cl++;   // "|" - add tabs level
         levelCnt=cl;
         
        if (cl>0)
        {
          bmenuItems[i][0] = bmenuItems[i][0].substring (cl, bmenuItems[i][0].length);  // remove ||| from item text
          parentItem = i-1;   // set previous item as parent
        }
        else
          parentItem = -1;    // there is now parent item for top item
          
        bitemCnt = root.tabs.length;
        
    	//----------------------------------------------------------------------
    	// Get individual styles
    	//----------------------------------------------------------------------
    	  singleStyle = dtabs_bGetParam (bmenuItems[i][6],"");
        sN = (singleStyle)?parseInt(singleStyle):-1;
    	  fntStyles = dtabs_bGetStyleParam ("bfontStyle",       sN, bfontStyle);
    	  fntColors = dtabs_bGetStyleParam ("bfontColor",       sN, gfntColors);
    	  fntDecors = dtabs_bGetStyleParam ("bfontDecoration",  sN, gfntDecors);
        bgcs      = dtabs_bGetStyleParam ("bitemBackColor",   sN, gbgcs);
        borcs     = dtabs_bGetStyleParam ("bitemBorderColor", sN, gborcs);
        borws     = dtabs_bGetStyleParam ("bitemBorderWidth", sN, gborws);
        borstyles = dtabs_bGetStyleParam ("bitemBorderStyle", sN, gborstyles);
        bgimages  = dtabs_bGetStyleParam ("bitemBackImage",   sN, gbgimages);
        bitemWidth_ = dtabs_bGetStyleParam ("bitemWidth",     sN, "");

        iconw_ = dtabs_bGetStyleParam ("biconW", sN, giconw);
        iconh_ = dtabs_bGetStyleParam ("biconH", sN, giconh);
        bbeforeItemImage_ = dtabs_bGetStyleParam ("bbeforeItemImage", sN, bbeforeItemImage);
        bafterItemImage_  = dtabs_bGetStyleParam ("bafterItemImage",  sN, bafterItemImage);
          
        bgimagesSpec = dtabs_bGetStyleParam ("bitemBackImageSpec", sN, "");
    	//----------------------------------------------------------------------
    	
    	  text_   = dtabs_bGetParam (bmenuItems[i][0], "");
  		  target_ = dtabs_bGetParam (bmenuItems[i][6], "_self");
        if (target_=="_self" && bitemTarget!="") target_ = bitemTarget;

    	
          root.tabs[bitemCnt] = {
              row     : rowCnt,                                       // item row
              level   : levelCnt,                                     // item level
              id      : root.id + "i" + bitemCnt,
              oi      : bmenuInd,
              ii      : bitemCnt,
              parentIt : parentItem,
              text    : text_,
              link    : dtabs_bGetParam (bmenuItems[i][1], ""),
              target  : target_,
              tip     : dtabs_bGetParam (bmenuItems[i][5], ""),
              align   : levelCnt?bsmItemAlign:bitemAlign,
              valign  : "middle",
              cursor  : bitemCursor,
              fontc   : fntColors,                                    // item font color
              font    : fntStyles,                                    // item font style string, eg "bold italic 8pt Verdana"
              fontdec : fntDecors,                                    // item font style
              bgc     : bgcs,                                         // item background color
              bgimage : bgimages,                                     // item background image
              bgimager: ["",""],                                      // item background image repeat
              icon    : [dtabs_bGetParam (bmenuItems[i][2],""), dtabs_bGetParam (bmenuItems[i][3],"")], //item icon
              iconw   : iconw_,
              iconh   : iconh_,
              beforeImage  : bbeforeItemImage_,
              beforeImageW : bbeforeItemImageW,
              beforeImageH : bbeforeItemImageH,
              afterImage   : bafterItemImage_,
              afterImageW  : bafterItemImageW,
              afterImageH  : bafterItemImageH,
              borc     : borcs,                                       // item border color
              borw     : borws,
              borstyle : borstyles,                                   // item border style
              space    : bitemSpacing,
              padd     : bitemPadding,
              width    : bitemWidth_,
              visible  : "visible",
              subHTML  : "",
              bgimageSpec : bgimagesSpec
          };
    	
        //if (!root.tabs[bitemCnt].icon[0]) root.tabs[bitemCnt].icon[0] = bblankImage; // if icon is unknown -> set to blank image
    }//for (menuItems)

    //==========================================================================
    // Create HTML
    //==========================================================================
    with (dtabs_tabs[bmenuInd])
    { if (!_Tab)
       { s="";
        s+="<DIV ID='dtabs_b" + bmenuInd + "div'" + (width?" width="+width:"");
        s+=" STYLE='position:"+pos + ";" + "height:"+height+"px;";
        s+="left: "+left+"px;top: "+top+"px;z-index:"+zind+"'>";

        s+="<TABLE height="+height+" BORDER=0 CELLPADDING=0 CELLSPACING="+ rowSpace + (width?" width="+width:"");
        s+=" STYLE='background-color:"+bgc + ";margin:0px; background-Image:url("+bgimage+");";
        s+="border-style:"+borstyle + ";border-width:"+borw + "px;border-color:"+borc + ";'>";
       }
      else
      {   s="";
        s+="<DIV ID='dtabs_b" + bmenuInd + "div'" + (width?" width="+width:"");
        s+=" STYLE='position:"+pos + ";" + "height:"+(height+bsmBorderWidth+1)+"px;";
        s+="left: "+left+"px;top: "+top+"px;z-index:"+zind+"'>";

        s+="<TABLE BORDER=0 CELLPADDING=0 CELLSPACING="+ rowSpace + (width?" width="+width:"");
        s+=" STYLE='height:"+(height+bsmBorderWidth+1)+"px;background-color:"+bgc + ";margin:0px; background-Image:url("+bgimage+");";
        s+="border-style:"+borstyle + ";border-width:"+borw + "px;border-color:"+borc + ";'><TR><TD>";
      }
    }


    // Variables ===============================================================
    var bitem, disp, itemID, eParam;
    var dispNeed = true; //isNS4 || (isOP && isVER<7);
    var bgclr    = "";
    var itext    = "";
    var compInd  = 0;
    var specBack = 0;


    // Functions ===============================================================
    function dtabs_bcreateImage(img, postfixID, w,h)
    {
      if (!img) return "";
      var q="";
      q+="<TD "+itemID+postfixID+"td' width="+w + " height"+h + " NOWRAP STYLE='padding:0px'>";
      q+="<img "+itemID+postfixID+"' src='"+img+"' width="+w + " height="+h + "></TD>";
      return q;
    }

    function dtabs_bcreateBackImage(img, postfixID, w,h)
    {
      if (!img) return "";
      var q="";
      q+="<TD "+itemID+postfixID+"td' NOWRAP STYLE='padding:0px; width:"+w+"px; height:"+h+"px; background-repeat: no-repeat; background-Image:url("+img+")'>";
      q+="<img "+itemID+postfixID+"blank' src='"+bblankImage+"' width="+w + " height="+h + "></TD>";
      return q;
    }

    function dtabs_bcreateIcon(w,h)
    {
      with (bitem)
      {
        if (!icon[0]) return "";
        var q="";
        var iconInd = (compInd?1:0);
        q+=dtabs_bcreateImage((compInd?icon[1]:icon[0]), 'icon', w, h);
      }
      return q;
    }
    
    function dtabs_bcreateSpace(w)
    {
      if (!w) return "";
      return "<TD width="+w+" NOWRAP STYLE='padding:0px; font-size:1px;'>&nbsp;</TD>";
    }
    
    function dtabs_bcreateText()
    {
      with (bitem)
      {
        var q="";
        q+="<TD "+itemID+"text' width=100% NOWRAP ALIGN="+align + " VALIGN=MIDDLE >";
        q+="<FONT "+itemID+"font' STYLE='color:"+fontc[compInd] + ";font:"+(font[compInd]?font[compInd]:font[0]) + ";text-decoration:"+fontdec[compInd]+"'>";
        q+=((isNS4 && link)?"<a href='"+link+"'>"+text+"</a>":text) + "</FONT></TD>";
      }
      return q;
    }

    function dtabs_bcreateBlankImg(w,h) {
      return "<img src='"+bblankImage+"' width="+w+" height="+h+">";
    }


    //--------------------------------------------------------------------------
    //======= Submenu ==========================================================
    function dtabs_bopenSubmenu(id, vis) {
      var displ = ((isOP && isVER<7)?"":"display:" + (vis?"":"none;"));
      var tabs = dtabs_tabs[bmenuInd];
      return "<div "+id+" style='"+(tabs.abspos ? 'position:absolute;left:'+tabs.left+'px;top:'+(tabs.top+tabs.height)+'px;' : '')+"width:"+bmenuWidth+"px; height:"+((isOP&&isVER<6)?"0%;":bsmHeight+"px;") + displ + " visibility:" + (vis?"visible":"hidden") + ";'><TABLE BORDER=0 width="+bmenuWidth+" height="+bsmHeight + " CELLPADDING="+bsmItemPadding+" CELLSPACING="+bsmItemSpacing+" STYLE='margin:0px; border:"+bsmBorderStyle+" "+bsmBorderWidth+"px "+bsmBorderColor+"; border-top:none 0px;"+(!bsmBorderBottomDraw?"border-bottom:none 0px;":"")+" background-color:"+bsmBackColor+";'><TR>";
    }

    function dtabs_bcloseSubmenu() {
      return "</TR></TABLE></div>";
    }
    //======= End of Submenu ===================================================
    //--------------------------------------------------------------------------

    function dtabs_bcreateItem(it)
    {
      var q="";
      if (it.text=="-")  // separator
      {
        if (!it.bgimageSpec)
          q+="<TD "+itemID+"' width="+bseparatorWidth + " style='margin:0px;'>&nbsp;</TD>";
        else
           q+="<TD "+itemID+"' width="+it.width + " style='margin:0px; background-image:url("+it.bgimageSpec[dtabs_bgetBackSpec(bmenuInd, ind, 0)]+");background-color:"+it.bgc[0]+";'>"+dtabs_bcreateBlankImg(it.width,1)+"</TD>";
      }
      else
      {
        // Item Cell -----------------------------------------------------------
        with (it)
        {  q="";
          var h = (smProcess?bsmHeight:dtabs_tabs[bmenuInd].height);
            q+="<TD "+itemID+"' TITLE='"+tip+"' " + (text?(width?"width="+width+"px":""):"width=1") + (text?(h?"height="+h+"px":""):"");
            q+=" STYLE='";
            q+="cursor:"+cursor + "; "+(bgimage[compInd] && !level?"background-Image:url("+bgimage[compInd]+");":"");
            q+="border-style:"+borstyle[compInd] + ";border-width:"+borw + "px;" + (!level?"border-bottom: "+borw+"px none":"") + ";margin:0px; border-color:"+borc[compInd] + ";background-color:"+bgc[compInd] + (isNS4?";'":";display:"+disp+";'");
            q+="onMouseOver='dtabs_bitemChange(this,"+eParam+",1)' onMouseOut='dtabs_bitemChange(this,"+eParam+",0)' onClick='" + (smProcess?"dtabs_bsmClick":"dtabs_bTabClick") + "("+bmenuInd+","+ind+")'>";
        }


        // Item table ----------------------------------------------------------
        with (dtabs_tabs[bmenuInd])
        {
          q+="<TABLE CELLPADDING="+it.padd+" CELLSPACING="+it.space+" BORDER=0 width=100% height=100%><TR>"
          with (it)
          {
            if (text)
            {
              if (level)
                q+=dtabs_bcreateSpace(beforeSpace) + ((iconalign!="right")?dtabs_bcreateIcon(iconw, iconh) + dtabs_bcreateSpace(beforeSpace):"") + dtabs_bcreateText() + ((iconalign=="right")?dtabs_bcreateSpace(afterSpace) + dtabs_bcreateIcon(iconw, iconh):"") + dtabs_bcreateSpace(afterSpace);
              else
                q+=dtabs_bcreateBackImage(beforeImage[compInd], 'bimg', beforeImageW, beforeImageH) + dtabs_bcreateSpace(beforeSpace) + ((iconalign!="right")?dtabs_bcreateIcon(iconw, iconh) + dtabs_bcreateSpace(beforeSpace):"") + dtabs_bcreateText() + ((iconalign=="right")?dtabs_bcreateSpace(afterSpace) + dtabs_bcreateIcon(iconw, iconh):"") + dtabs_bcreateSpace(afterSpace) + dtabs_bcreateBackImage(afterImage[compInd], 'aimg', afterImageW, afterImageH);
            }
            else
              q+=dtabs_bcreateIcon(iconw, iconh);
          }
        }
        q+="</TR></TABLE>";
        // End of Item table ---------------------------------------------------

        q+="</TD>";
        // End of Item Cell ----------------------------------------------------
      }
        return q;
    }

    //==========================================================================
    // RUN ITEMS ARRAY
    //==========================================================================
    var curRow = -1;
    var smProcess  = false;
    var topItemsNames=[];
    var topCnt=-1;

  if (_Tab)
  {
    s+="<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width=100% STYLE='margin:0px;'><TR>";

    for (var ind=0; ind<dtabs_tabs[bmenuInd].tabs.length; ind++)
    {
      bitem  = dtabs_tabs[bmenuInd].tabs[ind];
      itemID = "ID='dtabs_b"+bmenuInd+"i"+ind;
      eParam = bmenuInd + "," + ind;
      disp   = (bitem.visible=="visible" || dispNeed)?"":"none";

      if (!bitem.level)
      {
      }
      else
        if (!smProcess)       // start submenu creation process
        {
          smProcess = true;
          smHTML+=dtabs_bopenSubmenu("ID='dtabs_b"+bmenuInd+"i"+(ind-1)+"sm'", (ind-1==dtabs_tabs[bmenuInd].selectedItem));
          //smHTML+=dtabs_bopenSubmenu("ID='dtabs_b"+bmenuInd+"i"+(ind-1)+"sm'");
        }

      if (smProcess)
      {
        compInd = (dtabs_tabs[bmenuInd].selectedSmItem==ind)?2:0;       // set item state
        smHTML+=dtabs_bcreateItem(bitem);
      }
      else
      {
        compInd = (dtabs_tabs[bmenuInd].selectedItem==ind)?2:0;         // set item state
        s+=dtabs_bcreateItem(bitem);

        topCnt++;
        topItemsNames[topCnt] = ind;
      }

      with (dtabs_tabs[bmenuInd])
      {
        if (smProcess)
          if (ind==tabs.length-1 || tabs[ind+1].level==0) // if end of items or next item level=0 -> stop submenu creation process
          {
            smHTML+=dtabs_bcloseSubmenu();
            smProcess = false;
          }
      }
    }//for
    s+="</TR>";
    
    // Set border between top-menu and submenus ------------
    with (dtabs_tabs[bmenuInd])
    {
      if (smBorderWidth>0)
      {
        s+="<TR>";
        for (var i=0;i<=topCnt;i++)
        {
          //var clr = ((topItemsNames[i]==selectedItem)?tabs[topItemsNames[i]].bgc[2]:smBorderColor);
          var clr = ((topItemsNames[i]==selectedItem)?smBackColor:smBorderColor);
          var brdStyle = smBorderStyle+" "+smBorderWidth+"px "+smBorderColor;
          s+="<TD id='dtabs_b"+bmenuInd+"i"+topItemsNames[i]+"brd' style='padding:0px;font-size:1px;height:"+bsmBorderWidth+"px; border-left:"+brdStyle+";border-right:"+brdStyle+";background-color:"+clr+"'>"+dtabs_bcreateBlankImg(1,1)+"</TD>";
        }
        s+="</TR>";
      }
    }//with
    //------------------------------------------------------
    s+="</TABLE>";
    s+="</TD></TR></TABLE></DIV>";
    document.write(s+smHTML);
    s = "";
    smHTML="";
 }
 else
 {
    for (var ind=0; ind<dtabs_tabs[bmenuInd].tabs.length; ind++)
    {
      bitem  = dtabs_tabs[bmenuInd].tabs[ind];
      itemID = "ID='dtabs_b"+bmenuInd+"i"+ind;
      eParam = bmenuInd + "," + ind;
      disp = (bitem.visible=="visible" || dispNeed)?"":"none";
      compInd = (dtabs_tabs[bmenuInd].selectedItem==ind)?2:0;         // set item state

      // START ROW -------------------------------------------------------------
      if (bitem.row > curRow)
      {
        s+="<TR "+itemID+"tr'><TD>";
        s+="<TABLE BORDER=0 CELLPADDING=0 CELLSPACING="+bitem.space + " width=100% STYLE='margin:0px;'><TR>";
        curRow = bitem.row;
      }
      // End of START ROW ------------------------------------------------------
      

      if (bitem.text=="-")  // separator
      {
        if (!bitem.bgimageSpec)
          s+="<TD "+itemID+"' width="+bseparatorWidth + " style='margin:0px;'>"+dtabs_bcreateBlankImg(bseparatorWidth,1)+"</TD>";
        else
          s+="<TD "+itemID+"' width="+bitem.width + " style='margin:0px; background-image:url("+bitem.bgimageSpec[dtabs_bgetBackSpec(bmenuInd, ind, 0)]+");background-color:"+bitem.bgc[0]+";'>"+dtabs_bcreateBlankImg(bitem.width,1)+"</TD>";
      }
      else
      {
        // Item ----------------------------------------------------------------
        with (bitem)
        {
          s+="<TD "+itemID+"' TITLE='"+tip+"' " + (text?(width?"width="+width+"px":""):"width=1")
            s+=" STYLE='";
            s+="cursor:"+cursor + "; background-Image:url("+bgimage[compInd]+");";
            s+="border-style:"+borstyle[compInd] + ";border-width:"+borw + "px;margin:0px; border-color:"+borc[compInd] + ";background-color:"+bgc[compInd] + (isNS4?";'":";display:"+disp+";'");
            s+="onMouseOver='dtabs_bitemChange(this,"+eParam+",1)' onMouseOut='dtabs_bitemChange(this,"+eParam+",0)' onClick='dtabs_bClick("+bmenuInd+","+ind+")'>";
        }

        // Item table ----------------------------------------------------------
        s+="<TABLE CELLPADDING="+bitem.padd+" CELLSPACING=0 BORDER=0 width=100% height="+dtabs_tabs[bmenuInd].height+"><TR>"
        with (dtabs_tabs[bmenuInd])
        {
          with (bitem)
          {
            if (text)
              s+=dtabs_bcreateBackImage(beforeImage[compInd], 'bimg', beforeImageW, beforeImageH) + dtabs_bcreateSpace(beforeSpace) + ((iconalign!="right")?dtabs_bcreateIcon(iconw, iconh) + dtabs_bcreateSpace(beforeSpace):"") + dtabs_bcreateText() + ((iconalign=="right")?dtabs_bcreateSpace(afterSpace) + dtabs_bcreateIcon(iconw, iconh):"") + dtabs_bcreateSpace(afterSpace) + dtabs_bcreateBackImage(afterImage[compInd], 'aimg', afterImageW, afterImageH);
            else
              s+=dtabs_bcreateIcon(iconw, iconh);
          }
        }
        s+="</TR></TABLE>";
        // End of Item table ---------------------------------------------------

        s+="</TD>";
        // End of Item ---------------------------------------------------------
      }

      // FINISH ROW ------------------------------------------------------------
      if (ind==dtabs_tabs[bmenuInd].tabs.length-1 || dtabs_tabs[bmenuInd].tabs[ind+1].row > curRow)
        s+="</TR></TABLE></TD></TR>";
      // End of FINISH ROW -----------------------------------------------------
    }//for
    s+="</TABLE></DIV>";
    document.write (s);
    s = "";
    
    for (var i=0; i<dtabs_tabs.length; i++)
      dtabs_cacheImages(i);
 }

 //==========================================================================
 // HTML end
 //==========================================================================

  bmenuInd++; //next menu at page
}

var cImages = [];
var cImagesCnt=0;

function dtabs_cacheIArr(arr,excludeInd) {
  for (var i=0; i<arr.length; i++)
    if (i!=excludeInd && arr[i])
    {
      cImagesCnt++;
      cImages[cImagesCnt] = new Image();
      cImages[cImagesCnt].src = arr[i];
    }
}

function dtabs_cacheImages(mInd) {
  var excludeInd=0;
  for (var i=0; i<dtabs_tabs[mInd].tabs.length; i++)
    with (dtabs_tabs[mInd].tabs[i])
    {
      if (dtabs_tabs[mInd].selectedItem == i)
        excludeInd=2;
      else
        excludeInd=0;
      dtabs_cacheIArr(bgimage,excludeInd);
      dtabs_cacheIArr(icon,excludeInd);
      dtabs_cacheIArr(beforeImage,excludeInd);
      dtabs_cacheIArr(afterImage,excludeInd);
      dtabs_cacheIArr(bgimageSpec,excludeInd);
    }
}

//------------------------------------------------------------------------------
// Additional DX filters
var dtabs_bfNames = [
  ['Blinds'],
  ['Checkerboard'],
  ['GradientWipe'],
  ['Inset'],
  ['Iris'],
  ['Pixelate'],
  ['RadialWipe'],
  ['RandomBars'],
  ['RandomDissolve'],
  ['Slide'],
  ['Spiral'],
  ['Stretch'],
  ['Strips'],
  ['Wheel'],
  ['Zigzag']
];

function dtabs_bgetAdditionalFilterHTML(fNum, fDur) {
  if (isVER<5.5) return;
  var sF="progid:DXImageTransform.Microsoft."+dtabs_bfNames[fNum-25] + '(' + btransOptions + ',duration='+fDur + ')';
  return sF;
}

function dtabs_bsetFilter(mn) {
  var sF="";
  if (mn.eff)
    if (mn.eff==24) sF+="blendTrans(Duration="+mn.dur/1000+") ";
    else
      if (mn.eff<24)
        sF+="revealTrans(Transition="+mn.eff+",Duration="+mn.dur/1000+") ";
      else
        sF+=dtabs_bgetAdditionalFilterHTML(mn.eff, mn.dur/1000);
  sF += ";";
  return sF;
}
//------------------------------------------------------------------------------

var dtabs_specInds={"nn":0,"no":1,"ns":2,"on":3,"os":4,"sn":5,"so":6};
var dtabs_overItem=-1;

function dtabs_bgetBackSpec(menuN, itemN) {
  var backInd = 0;
  with (dtabs_tabs[menuN])
  {
    var len  = tabs.length;
    var cL="n",cR="n";
    var iL = (itemN-1<0)?-1:itemN-1;
    var iR = (itemN+1>len-1)?-1:itemN+1;
    if (iL<0 && iR<0) return 0;
    if (iL>=0)
      cL = (selectedItem==iL)?"s":((dtabs_overItem==iL)?"o":"n");
    if (iR>=0)
      cR = (selectedItem==iR)?"s":((dtabs_overItem==iR)?"o":"n");
    backInd = dtabs_specInds[cL+cR];
  }
  return backInd;
}

//==============================================================================
// Item events
//==============================================================================

function dtabs_bsetObjectVisibility(obj, vis, fltPlay) {
  if (!obj) return;
  var fl=null;
  if (fltPlay && vis && isIE && !isMAC) fl = obj.filters[0];

  with (obj.style)
  {
    if (fl && !_Tab)
    {
     if (fl.Status!=0) fl.stop();
      fl.apply();
    }
    visibility = (vis?"visible":"hidden");
    display    = (vis?"":"none");
    if (fl && !_Tab) fl.play();
  }
}
function dtabs_bchangePressedItem(menuN, oldN, newN, isSmItem) {

  with (dtabs_tabs[menuN])       // unpress old presed item and set new selected index
  {
    if (isSmItem) selectedSmItem = -1;
    else          selectedItem   = -1;
    if (tabs[oldN])
      dtabs_bitemChange(dtabs_bgetObjectByID(tabs[oldN].id),  menuN, oldN,  0); // change old pressed item

    if (isSmItem) selectedSmItem = newN;
    else          selectedItem   = newN;
    if (tabs[newN])
      dtabs_bitemChange(dtabs_bgetObjectByID(tabs[newN].id), menuN, newN, 2);   // change new pressed item
  }
}

function dtabs_bexecuteAction(link, target) {
 if (link.toLowerCase().indexOf("javascript")==0)
   eval(link.substring(11, link.length));
 else
   if (link) open(link , target);
   //dtabs_bsetObjectVisibility(dtabs_bgetObjectByID(link), true, true);
}

// Submenus' item click event --------------------------------------------------
function dtabs_bsmClick(menuN, itemN) {
  with (dtabs_tabs[menuN])
  {
    var bitem = tabs[itemN];
    dtabs_bexecuteAction(bitem.link , bitem. target);

    if (selectedSmItem == itemN) return;   // this item is pressed -> do nothing
    var oldSelected = selectedSmItem;      // remember pressed item in submenu
  }

  dtabs_bchangePressedItem(menuN, oldSelected, bitem.ii, true);

  //with (bitem)
    //dtabs_bsetObjectVisibility(dtabs_bgetObjectByID(dtabs_tabs[menuN].tabs[oldSelected].link), false, true);
}
// End of Submenus' item click event
//------------------------------------------------------------------------------

function dtabs_bshowSubmenu(menuN, oldN, newN) {
  with (dtabs_tabs[menuN])
  {
    if (oldN!=-1)
    {
      var sm=dtabs_bgetObjectByID(tabs[oldN].id+'sm');
      dtabs_bsetObjectVisibility(sm, false, false);
    }

    if (newN==-1) return;
    sm=dtabs_bgetObjectByID(tabs[newN].id+'sm');
    if (!sm) return;

    dtabs_bsetObjectVisibility(sm, true, false);
  }
}



function dtabs_bClick(menuN, itemN) {
  if (dtabs_tabs[menuN].selectedItem == itemN) return;
  var bitem = dtabs_tabs[menuN].tabs[itemN];
  var oldSelected= dtabs_tabs[menuN].selectedItem;  // remember pressed item

  with (dtabs_tabs[menuN])       // unpress old presed item and set new selected index
  {
    selectedItem = -1;
    dtabs_bitemChange(dtabs_bgetObjectByID(tabs[oldSelected].id),  menuN, oldSelected,  0); // change old presed item
    selectedItem = bitem.ii;   // set new pressed item
    dtabs_bitemChange(dtabs_bgetObjectByID(tabs[selectedItem].id), menuN, selectedItem, 2); // change new presed item
  }

  with (bitem)
  {
    dtabs_bsetObjectVisibility(dtabs_bgetObjectByID(dtabs_tabs[menuN].tabs[oldSelected].link), false, true);
    if (link.toLowerCase().indexOf("javascript")==0)
      eval(link.substring(11, link.length));
    else
      dtabs_bsetObjectVisibility(dtabs_bgetObjectByID(link), true, true);
  }
}


function dtabs_bTabClick(menuN, itemN) {
  with (dtabs_tabs[menuN])
  {
    if (selectedItem == itemN) return;
    var bitem = tabs[itemN];
    var oldSelected= selectedItem;  // remember pressed item
  }
  dtabs_bchangePressedItem(menuN, oldSelected, bitem.ii, false);
  dtabs_bshowSubmenu(menuN, oldSelected, bitem.ii);
  with (bitem)
  {
    dtabs_bexecuteAction(link , target);
  }
}


function dtabs_bchangeItemFont(itemVar, fntStyle, state) {
  with (itemVar)
  {
    if (fontc[state] && fntStyle.color != fontc[state])
      fntStyle.color = fontc[state];

    if (font[state] && fntStyle.font != font[state])
      fntStyle.font = font[state];

    if (fontdec[state] && fntStyle.textDecoration != fontdec[state])
      fntStyle.textDecoration = fontdec[state];
  }
}

function dtabs_bsetDecorImage(imgPrefixID, newImg) {
  var img = dtabs_bgetObjectByID(imgPrefixID+'blank');
  if (img && newImg)
  {
    var imgTD = dtabs_bgetObjectByID(imgPrefixID+'td');
     if (imgTD.style.backgroundImage.indexOf(newImg)<0)
      imgTD.style.backgroundImage = "url("+newImg+")";
  }
}

function dtabs_bItemChangeSpec(itVart) {
 if (!itVart || !itVart.bgimageSpec) return;

 var io=dtabs_bgetObjectByID(itVart.id);
 var specInd=dtabs_bgetBackSpec(itVart.oi, itVart.ii);
 if (itVart.bgimageSpec[specInd])
   io.style.backgroundImage = "url("+itVart.bgimageSpec[specInd]+")";
}




function dtabs_bGetStyleParam(pName, styleN, defValue) {                          // extract individual styles from array
  if (styleN==-1) return defValue;
  var stylePrm = [];
  var sp = bstyles[styleN];

  for (var j=0; sp[j].indexOf(pName)<0 && j<sp.length-1; ++j) ;
  if (sp[j].indexOf(pName)<0) return defValue;                                  // if style parameter is absent -> defValue

  var str = sp[j];
  var t = str.split('=');
  if (t.length<2) return defValue;
  stylePrm = t[1].split(',');
  return stylePrm;
}


function dtabs_bitemChange(it, menuN, itemN, state)
{
  if (_Tab)
    with (dtabs_tabs[menuN])
    {
      var bitem = tabs[itemN];
      if ((selectedItem == bitem.ii || selectedSmItem == bitem.ii) && state!=2) return;
    }
  else
  {
    var bitem = dtabs_tabs[menuN].tabs[itemN];
    if (dtabs_tabs[menuN].selectedItem == bitem.ii && state!=2) return;
  }

  if (bitem.text)
    var fnt = dtabs_bgetObjectByID(it.id+"font");

  with (bitem)
  {
     if (_Tab)
     {
       if (bgc[state] && it.style.backgroundColor.indexOf(bgc[state])<0)
         it.style.backgroundColor = bgc[state];
       if (!bitem.level && bgimage[state] && it.style.backgroundImage.indexOf(bgimage[state])<0)
         it.style.backgroundImage = "url("+bgimage[state]+")";
       if (borc[state])     it.style.borderColor     = borc[state];
       if (borstyle[state]) it.style.borderStyle     = borstyle[state];
       if (!level)
         it.style.borderBottom = '0px none';

      if (!bitem.level)
        if (state==2)
        {
          var brd = dtabs_bgetObjectByID(bitem.id+'brd');
          if (brd)
            brd.style.backgroundColor=dtabs_tabs[menuN].smBackColor;
        }
      else
      {
        var brd = dtabs_bgetObjectByID(bitem.id+'brd');
        if (brd)
          brd.style.backgroundColor=dtabs_tabs[menuN].smBorderColor;
      }
    }
    else
    {
      if (bgc[state])      it.style.backgroundColor = bgc[state];
      if (bgimage[state])  it.style.backgroundImage = "url("+bgimage[state]+")";
      if (borc[state])     it.style.borderColor = borc[state];
      if (borstyle[state]) it.style.borderStyle = borstyle[state];
    }

    // Change before and after item images -------------------------------------
    dtabs_bsetDecorImage(id+'bimg', beforeImage[state]);
    dtabs_bsetDecorImage(id+'aimg', afterImage[state]);
    //--------------------------------------------------------------------------

    if (bitem.text)
      dtabs_bchangeItemFont(bitem, fnt.style, state);

    oicon = dtabs_bgetObjectByID(it.id + "icon");
    if (oicon && icon[state])
      oicon.src = icon[state];

    dtabs_overItem = (state==1)?itemN:-1;
    var iL=dtabs_tabs[menuN].tabs[itemN-1];
    var iR=dtabs_tabs[menuN].tabs[itemN+1];
    dtabs_bItemChangeSpec(iL);
    dtabs_bItemChangeSpec(iR);
    }
  }




// *****************************************************************************

function dtabs_bgetObjectByID(id) {
  if (!id)                      return null;
  if (isNS4)                    return document.layers[id];
  if (!document.getElementById) return document.all[id];
  return document.getElementById(id);
}

function dtabs_bgetObjectSize(o) {
  var l=0,t=0,h=0,w=0;
  if (!o) return [l,t,w,h];
  if (isOP && isVER<6)
  {
    h = o.style.pixelHeight;
    w = o.style.pixelWidth;
  }
  else
    if (isNS4)
    {
      h = o.clip.height;
      w = o.clip.width;
    }
    else
    {
      h = o.offsetHeight;
      w = o.offsetWidth;
    }
  while (o)
  {
    l += parseInt (isNS4?o.pageX:o.offsetLeft);
    t += parseInt (isNS4?o.pageY:o.offsetTop);
    o = o.offsetParent;
  }
  return [l,t,w,h];
}
