 /*---------------------------------------
  Name/Created by:
  dropdown menu 0.53 beta by András Héger

  Supported browsers:
  tested on firefox 2.0.0.12 & IE 6.0 & Opera

  Working:
  meuitems uses DOM & div capabilities to positioning - center pos is also works.
  apperiance settins over CSS.

  Usage:
  Make a container in your page, give it an id and give this id to the menu as parent...

  New features:
  Link display in statusbar
  The "currently selected" status on main menuitems -> 3 statuses : over, out, currently selected.

  In progress:
  -php generated text bg mode on main menu items for antialiased captions


  In later version:

  - place menu into a class & function.arguments[n] modell -> for optional parameters
  - support item icons
  - submenu sign (arrow blips if there is an available submenu...)
  - support disabled item
  - html tag configurable menu (<ol>/<li> hierarchy )
  - delayed submenu container hiding (setInterval/setTimeout) !!!

  Bugfixes:
  -ver 0.52 : Works under Opera

  ---------------------------------------*/
   var g_timer;
   var g_obj;
   var g_root;

   function AddMainMenuItem(a_id,a_caption, a_link, a_selected)
   {
     p = document.getElementById(prnt);
     d = document.createElement('div');

     d.id             = a_id;
     d.style.position = 'relative';
     //d.style.backgroundColor = 'red';
     d.style.zIndex = mnu_initial_zindex;
     mnu_initial_zindex++;
     //d.className = 'm_pos';

     d.style.width      = mnu_width;
     d.style.top        = mnu_top;
     d.style.left       = mnu_left;
     d.style.height     = mnu_height;
     d.style.marginRight= mnu_spacing;

     //d.style.border     ='1px solid #ff0000';
     d.style.cssFloat   = 'left';   // netscape &más w3c  browsers -hez
     d.style.styleFloat = 'left'; // IE & vidéke...
     // d kiterjesztése
     d.aLink = a_link;

     d.onmouseover = function()
     {
       //clearTimeout(g_timer);

       g_root = this;

       sub_menu_node = this.firstChild.nextSibling;
       if  (sub_menu_node != null)
         sub_menu_node.style.display = '';



       if (a_selected)
       {

         if (imageBgCaptionMode)
         {
           this.firstChild.firstChild.className = this.id +'_sel';
         }
         else
         {
           this.firstChild.firstChild.className = 'm_sel';
         }

       }
       else
       {
         if (imageBgCaptionMode)
         {
           this.firstChild.firstChild.className = this.id + '_over';
         }
         else
         {
           this.firstChild.firstChild.className = 'm_over';
         }
       }

     }

     d.onmouseout = function()
     {
       sub_menu_node = this.firstChild.nextSibling;
       if  (sub_menu_node != null)

        // g_obj   = sub_menu_node;
         //g_timer = setTimeout('HideObject(g_obj)',hide_delay);
         sub_menu_node.style.display = 'none';
         //HideObject(sub_menu_node);

       if (a_selected)
       {
         if (imageBgCaptionMode)
         {
           this.firstChild.firstChild.className = this.id + '_sel'
         }
         else
         {
           this.firstChild.firstChild.className = 'm_sel';
         }
       }
       else
       {
         if (imageBgCaptionMode)
         {
           this.firstChild.firstChild.className = this.id + '_out';
         }
         else
         {
           this.firstChild.firstChild.className = 'm_out';
         }
       }

     }

    d.onclick = function()
    {
      if (this.aLink !='' && this.aLink != '#' && !a_selected)
      {
        document.location.href = this.aLink;
      }
    }

     s = document.createElement('div');
     s.style.width = mnu_width;

     if (s.style.height != '')
       d.style.height   = s.style.height;

     s.style.overflow = 'hidden';

     if (a_selected)
     {
       s.style.cursor   = 'default';
     }
     else
     {
       s.style.cursor   = 'pointer';
     }


     s.onmouseover = function()
     {
       window.status = this.firstChild.innerHTML + '(' + this.parentNode.aLink + ')';
     }

     c = document.createElement('div');
     if (imageBgCaptionMode)
     {
       c.innerHTML      = '&nbsp;';
     }
     else
     {
       c.innerHTML      = a_caption;
     }
     if (a_selected)
     {
       if (imageBgCaptionMode)
       {
          c.className     = d.id + '_sel';
       }
       else
       {
          c.className     = 'm_sel';
       }
     }
     else
     {
       if (imageBgCaptionMode)
       {
          c.className     = d.id + '_out';
       }
       else
       {
          c.className     = 'm_out';
       }
     }

     s.appendChild(c);
     d.appendChild(s);
     p.appendChild(d);
     isFristSub = true;

   }

  function AddSubmenu(a_id, a_parent, a_width)
  {

     d = document.createElement('div');
     d.id = a_id;
     d.className = 's_container';
     d.style.border = sub_border;
     d.style.width = a_width;
     d.style.position = 'absolute';
     d.style.display = 'none';

     d.style.zIndex = sub_initial_zindex;
     sub_initial_zindex++;

     if (isFristSub == true)
     {
       p = document.getElementById(a_parent);
       p_width = p.style.width;
       p_height =  p.style.height;

       a_border_width = GetBorderSize(sub_border);

       a_top = parseInt(p_height) - a_border_width + sub_top_offset;
       d.style.top = a_top + 'px';


       a_width =  parseInt(p_width) - (a_border_width * 2);
       d.style.width = a_width + 'px';

       d.style.left = '0px';
     }
     else
     {

       a_border_width = GetBorderSize(sub_border);
       d.style.top = (0-a_border_width ) + 'px';   // <- pozició korrekció a border vastagság függvényében...

       p = document.getElementById(a_parent + '_dummycaption');

       if (p.style.width != '')
       {
         d.style.left = p.style.width;
       }
       else
       {
         d.style.left = '100px';
       }
     }


     t = document.createElement('table');
     t.id = a_id + '_table';
     t.style.width = '100%';

     d.onmouseover = function()
     {

        //this.style.display = '';

        //window.status = this.id;  <--emiatt kétszer beüt

        //g_obj   = this.parentNode;
     }


     d.onmouseout = function()
     {
        //alert(this.id)
        //g_timer = setTimeout('HideObject(g_obj)',hide_delay);

        //this.style.display = 'none';  <--emiatt kétszer beüt

        //alert(g_root.id + '/' + g_obj.id);
        //if (g_root == g_obj)
       // window.status = g_root.id;


     }

     d.appendChild(t);
     p.appendChild(d);

     isFristSub = false;
  }

  function AddSubmenuItem(a_id, a_parent,a_caption, a_link ,n)
  {
    p = document.getElementById(a_parent);
    t = document.getElementById(a_parent + '_table');
    t.cellPadding = 0;
    t.cellSpacing = 0;

    r = t.insertRow(n);
    c = r.insertCell(0);
    c.id = a_id;


    w = p.style.width;
    // a felirat dummy konténere, pozicionálja az almenüt
    d = document.createElement('div');
    d.style.position = 'relative';
    d.style.width = w;
    d.id = a_id + '_dummycaption';
    d.className = 's_out';
    
    // a div property-k kiterjesztése
    d.aLink = a_link;

    // a felirat divje, overflow-val
    s = document.createElement('div');
    //s.style.width = w;
    s.className = 's_text_position';
    s.style.overflow = 'hidden';
    s.style.textAlign = 'left';
    //s.style.cursor = 'pointer';
    s.innerHTML = a_caption;


    d.appendChild(s);
    c.appendChild(d);
    
    s.onmouseover = function()
    {
      window.status = this.innerHTML + '(' + this.parentNode.aLink + ')';
    }

    d.onmouseover = function()
    {
       sub_menu_node = this.firstChild.nextSibling;
       
       //clearTimeout(g_timer);
       //g_obj   = sub_menu_node;
       if  (sub_menu_node != null)
       {
        //g_timer = setTimeout('ShowObject(g_obj)',hide_delay);
        sub_menu_node.style.display = '';
       }
       
       this.className = 's_over';

       if ( (this.aLink !='') && (this.aLink != '#') )
       {
         this.style.cursor = 'pointer';
       }
       else
       {
         this.style.cursor = 'default';
       }


    }

    d.onmouseout = function()
    {

       sub_menu_node = this.firstChild.nextSibling;
       if  (sub_menu_node != null)
       {
         //g_obj   = sub_menu_node;
         //g_timer = setTimeout('HideObject(g_obj)',hide_delay);
         sub_menu_node.style.display = 'none';
        
       }
       this.className = 's_out';

    }
    
    d.onclick = function()
    {
      if (this.aLink !='' && this.aLink != '#')
      {
        document.location.href = this.aLink;
      }
    }

  }

   function HideObject(a_obj)
   {
     a_obj.style.display = 'none';
   }
   
   function ShowObject(a_obj)
   {
     a_obj.style.display = '';
   }

   function GetBorderSize(a_border)
  {

    if (a_border != '')
    {
       
      bElements = a_border.split(' ');
      
      i= 0;
      w = 0;
      while ( !isNaN(parseInt(bElements[i])) && (i<bElements.length) )
      {

         w = parseInt(bElements[i]);
         i++;
      }

      if (!isNaN(w))
      {
        return w;
      }
      else
      {
        return false;
      }

    }
    else
    {
      return false;
    }

  }

