var items = new Array();

   entry(1, 30, "",       "comunicacion.html");
   entry(1, 30, "",       "producciones.html");
   entry(1, 30, "",       "ediciones.html");

//====================================================================================================

var DOM = document.getElementById;
var IE4 = document.all;
var NN4 = document.layers;
var MAC = (navigator.userAgent.indexOf('Mac') != -1) ? true : false;

function MENU() {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------

  this.floatMenu = false;                    // floating menu (true or false)*
  this.fadeInSpeed = 30;                    // fade-in speed (0 - 30; 0 = no fading)
  this.fadeOutSpeed = 30;                   // fade-out speed (0 - 30; 0 = no fading)
  this.fadeOutDelay = 500;                  // fade-out delay (1/1000 seconds)

  // main menu configuration:

  this.mainTop = 110;                       // top position (pixels)
  this.mainLeft = 50;                       // left position (pixels)
  this.mainWidth = 200;                     // width (pixels)
  this.mainBGColor = "";            // background color OR background image
  this.mainBorderWidth = 0;                 // border width (pixels)
  this.mainArrows = true;                   // show sub menu arrows (true or false)
  this.mainOpacity = 40;                   // opacity (0 - 100)**

  this.mainItemColor = " ";           // item color
  this.mainItemHilight = " ";         // item hilight color
  this.mainItemFont = "Arial, Helvetica";   // font family (CSS-spec)
  this.mainItemFontColor = "grey";         // font color
  this.mainItemFontSize = 18;               // font size (pixels)
  this.mainItemAlign = "left";            // text align (left / center / right)
  this.mainItemPadding = 0;                 // text padding (pixels)
  this.mainItemSpacer = 15;                 // space between items (pixels)
  this.mainItem3D = 2;                      // 3D border (pixels); NN4: not supported

  // sub menu(s) configuration: (((no hay submenues en este menu)))

  this.subWidth = 100;                      // width (pixels)
  this.subBGColor = "#406080";              // background color OR background image
  this.subBorderWidth = 1;                  // border width (pixels)
  this.subArrows = true;                    // show sub menu arrows (true or false)
  this.subOpacity = 90;                     // opacity (0 - 100)**
  this.subOffsetLeft = 10;                  // left offset (pixels)

  this.subItemColor = "#E0F0FF";            // item color
  this.subItemHilight = "#C0D8F0";          // item hilight color
  this.subItemFont = "Arial, Helvetica";    // font family (CSS-spec)
  this.subItemFontColor = "#204060";        // font color
  this.subItemFontSize = 12;                // font size (pixels)
  this.subItemAlign = "left";               // text align (left / center / right)
  this.subItemPadding = 4;                  // text padding (pixels)
  this.subItemSpacer = 1;                   // space between items (pixels)
  this.subItem3D = 0;                       // 3D border (pixels); NN4: not supported

// *  With Safari 1 (Mac OS X) performance was poor, i.e. floating speed was slow. With IE 5 (Mac OS X)
//    floating didn't work properly.
//
// ** Opacity was successfully tested only on Windows XP with IE 6, NN 7 and Firefox 1; NN 7 showed
//    different results, though. It seems that other browsers and systems do not support this feature,
//    i.e. opacity will always be 100 percent.

//----------------------------------------------------------------------------------------------------
// Functions
//----------------------------------------------------------------------------------------------------

  if(NN4 && !MAC) this.subItemFontSize++;

  this.mOver = false;
  this.startY = this.iv = this.timer = 0;
  this.sections = new Array();

  this.getObj = function(id, cont) {
    var obj;
    if(DOM) obj = document.getElementById(id).style;
    else if(IE4) obj = document.all[id].style;
    else if(NN4) obj = cont ? document.layers[cont].document.layers[id] : document.layers[id];
    return obj;
  }

  this.getScrTop = function() {
    var scrTop = 0;
    if(document.body && document.body.scrollTop) scrTop = document.body.scrollTop;
    else if(window.pageYOffset) scrTop = window.pageYOffset;
    return scrTop;
  }

  this.setOpacity = function(nr, opacity) {
    if(!NN4) {
      var m = 'menu' + nr;
      var obj = 0;
      if(DOM) obj = document.getElementById(m);
      else if(IE4) obj = document.all[m];
      if(obj) {
        obj.style.filter = 'alpha(opacity=' + opacity + ')';
        obj.style.mozOpacity = '.1';
        if(obj.filters) obj.filters.alpha.opacity = opacity;
        if(!IE4 && obj.style.setProperty) obj.style.setProperty('-moz-opacity', opacity / 100, '');
      }
    }
  }

  this.fadeIn = function(nr) {
    if(this.sections[nr].active) {
      var maxOp = (items[this.sections[nr].nr].level < 2) ? this.mainOpacity : this.subOpacity;
      if(this.fadeInSpeed && this.sections[nr].opacity < maxOp) {
        this.sections[nr].opacity += this.fadeInSpeed;
        if(this.sections[nr].opacity > maxOp) this.sections[nr].opacity = maxOp;
        this.setOpacity(nr, this.sections[nr].opacity);
        if(this.sections[nr].timer) clearTimeout(this.sections[nr].timer);
        this.sections[nr].timer = setTimeout('mObj.fadeIn(' + nr + ')', 1);
      }
      else {
        this.sections[nr].opacity = maxOp;
        this.setOpacity(nr, maxOp);
      }
    }
  }

  this.fadeOut = function(nr) {
    if(this.fadeOutSpeed && this.sections[nr].opacity > 0) {
      this.sections[nr].opacity -= this.fadeOutSpeed;
      if(this.sections[nr].opacity < 0) this.sections[nr].opacity = 0;
      this.setOpacity(nr, this.sections[nr].opacity);
      if(this.sections[nr].timer) clearTimeout(this.sections[nr].timer);
      this.sections[nr].timer = setTimeout('mObj.fadeOut(' + nr + ')', 1);
    }
    else {
      var obj = this.getObj('menu' + nr);
      obj.visibility = NN4 ? 'hide' : 'hidden';
      this.sections[nr].opacity = 0;
    }
  }

  this.showMenu = function(nr) {
    var obj = this.getObj('menu' + nr);
    if(!this.sections[nr].active) {
      if(this.floatMenu) this.sections[nr].y = this.getScrTop() + this.sections[nr].topY;
      if(IE4) obj.pixelTop = this.sections[nr].y;
      else obj.top = this.sections[nr].y + (DOM ? 'px' : '');
      obj.visibility = NN4 ? 'show' : 'visible';
      this.sections[nr].active = true;
      this.fadeIn(nr);
    }
  }

  this.hideMenu = function(nr) {
    var obj = this.getObj('menu' + nr);
    if(this.sections[nr].active) {
      this.sections[nr].active = false;
      this.fadeOut(nr);
    }
  }

  this.hilight = function(mNr, item, color) {
    var obj = this.getObj('item' + item, 'menu' + mNr);
    if(NN4) obj.bgColor = color;
    else obj.backgroundColor = color;
    if(color == this.subItemColor || color == this.mainItemColor) this.mOver = false;
    else this.mOver = true;
  }

  this.getMenu = function(item, mNr) {
    if(this.sections[mNr].active) {
      for(var i = mNr+1; i < this.sections.length; i++) {
        if(this.sections[i].nr == item) {
          if(!this.sections[i].active) this.showMenu(i);
        }
        else if(this.sections[i].active) this.hideMenu(i);
      }
    }
  }

  this.hideSubs = function(start) {
    if(!this.mOver) for(var i = start; i < this.sections.length; i++) {
      if(this.sections[i].active) this.hideMenu(i);
    }
    this.timer = 0;
  }

  this.jumpURL = function(url) {
    if(url) document.location.href = url;
  }

  this.checkIt = function() {
    var active = false;
    var i;
    if(this.floatMenu) for(i = 0; i < this.sections.length; i++) {
      if(this.sections[i].active) this.floatIt(i, this.sections[i].topY);
    }
    if(!this.mOver && !this.timer) {
      for(i = 0; i < this.sections.length && !active; i++) {
        if(this.sections[i].active) active = true;
      }
      if(active) {
        if(this.fadeOutDelay) this.timer = setTimeout('mObj.hideSubs(1)', this.fadeOutDelay);
        else this.hideSubs(1);
      }
    }
  }

  this.floatIt = function(nr, topY) {
    var obj = this.getObj('menu' + nr);
    if(obj.visibility == 'visible' || obj.visibility == 'show') {
      var scrTop = this.getScrTop() + topY;
      var elmTop = IE4 ? obj.pixelTop : parseInt(obj.top);
      if(elmTop != scrTop) {
        this.startY = scrTop;
        this.smoothIt(obj, nr);
      }
    }
  }

  this.smoothIt = function(obj, nr) {
    if(this.startY != this.sections[nr].y) {
      var percent = .1 * (this.startY - this.sections[nr].y);
      if(percent > 0) percent = Math.ceil(percent);
      else percent = Math.floor(percent);
      this.sections[nr].y += percent;
      if(IE4) obj.pixelTop = this.sections[nr].y;
      else if(NN4 || DOM) obj.top = this.sections[nr].y + (DOM ? 'px' : '');
    }
  }

  this.buildItems = function(section, menuNr) {
    var arrows, link, img, color, itemColor, itemHilight, itemAlign;
    var width, border, spacer, itemPadding, item3D, topY, clsItem, j;

    for(var i = 0; i < items.length; i++) {
      if(items[i].parent == section) {
        if(items[i].level < 2) {
          width = this.mainWidth;
          border = this.mainBorderWidth;
          color = this.mainBGColor;
          spacer = this.mainItemSpacer;
          arrows = this.mainArrows;
          itemColor = this.mainItemColor;
          itemHilight = this.mainItemHilight;
          itemAlign = this.mainItemAlign;
          itemPadding = this.mainItemPadding;
          item3D = this.mainItem3D;
          clsItem = 'clsMainItem';
        }
        else {
          width = this.subWidth;
          border = this.subBorderWidth;
          color = this.subBGColor;
          spacer = this.subItemSpacer;
          arrows = this.subArrows;
          itemColor = this.subItemColor;
          itemHilight = this.subItemHilight;
          itemAlign = this.subItemAlign;
          itemPadding = this.subItemPadding;
          item3D = this.subItem3D;
          clsItem = 'clsSubItem';
        }
        link = "javascript:mObj.jumpURL('" + (items[i].url ? items[i].url : '') + "')";
        cssBorder = (item3D ? '; border:' + item3D + 'px outset white' : '');
        if(!topY) topY = border;

        if(i+1 < items.length && items[i+1].level > level) img = 'arrow.gif';
        else img = '';

        for(j = 0; j < this.sections.length; j++) {
          if(this.sections[j].nr == i+1) {
            this.sections[j].topY = this.sections[menuNr].topY + topY;
            this.sections[j].y = this.sections[j].topY;
          }
        }

        if(IE4 || DOM) document.write('<div id="item' + i + '" style="position:absolute' +
                                      '; top:' + topY + 'px' +
                                      '; left:' + border + 'px' +
                                      '; width:' + width + 'px' +
                                      '; height:' + items[i].height + 'px' +
                                      (itemColor ? '; background-color:' + itemColor : '') + cssBorder +
                                      '; z-index:1">');
        else if(NN4) document.write('<layer id="item' + i + '"' +
                                    ' top=' + topY +
                                    ' left=' + border +
                                    ' width=' + width +
                                    ' height=' + items[i].height +
                                    (itemColor ? ' bgcolor=' + itemColor : '') +
                                    ' z-index=1>');
        document.write('<table border=0 cellspacing=0 cellpadding=' + itemPadding +
                       ' width=' + width +
                       ' height=' + items[i].height + '><tr><td class="' + clsItem + '"' +
                       ' align="' + itemAlign + '">' + items[i].text + '</td>' +
                       (img ? '<td width=7 align=right><img src="' + img + '" width=7 height=8></td>' : '') +
                       '</tr></table>');
        if(IE4 || DOM) document.write('</div>');
        else if(NN4) document.write('</layer>');

        if(IE4 || DOM) document.write('<div style="position:absolute' +
                                      '; top:' + topY + 'px' +
                                      '; left:' + border + 'px' +
                                      '; z-index:2">');
        else if(NN4) document.write('<layer' +
                                    ' top=' + topY +
                                    ' left=' + border +
                                    ' z-index=2>');
        document.write('<a href="' + link + '" ' +
                       'onMouseOver="mObj.hilight(' + menuNr + ', ' + i + ', \'' + itemHilight + '\'); ' +
                       'mObj.getMenu(' + (i+1) + ', ' + menuNr + ')" ' +
                       'onMouseOut="mObj.hilight(' + menuNr + ', ' + i + ', \'' + itemColor + '\')" ' +
                       (items[i].onClick ? 'onClick="' + items[i].onClick + '" ' : '') +
                       'onFocus="if(this.blur) this.blur()">' +
                       '<img src="blank.gif" border=0 width=' + (width+item3D*2) +
                       ' height=' + (items[i].height+item3D*2) + '></a>');
        if(IE4 || DOM) document.write('</div>');
        else if(NN4) document.write('</layer>');

        topY += items[i].height + spacer + item3D;
      }
    }
  }

  this.buildSections = function() {
    document.write('<style> ' +
                   '.clsMainItem { color:' + this.mainItemFontColor +
                   '; font-family:' + this.mainItemFont +
                   '; font-size:' + this.mainItemFontSize + 'px; } ' +
                   '.clsSubItem { color:' + this.subItemFontColor +
                   '; font-family:' + this.subItemFont +
                   '; font-size:' + this.subItemFontSize + 'px; } ' +
                   '</style>');

    var width = border = color = item3D = spacer = left = 0;
    var height = level = section = j = 0;
    var bgImg = '';

    for(var i = 0; i < items.length; i++) {
      if(!i || items[i].level > items[i-1].level) {
        this.sections[this.sections.length] = new makeSection(i, items[i].level, this.mainTop);
      }
    }

    for(i = 0; i < this.sections.length; i++) {
      section = this.sections[i].nr;
      level = this.sections[i].level;
      if(level < 2) {
        width = this.mainWidth;
        border = this.mainBorderWidth;
        color = this.mainBGColor;
        item3D = this.mainItem3D;
        spacer = this.mainItemSpacer;
        left = this.mainLeft;
      }
      else {
        width = this.subWidth;
        border = this.subBorderWidth;
        color = this.subBGColor;
        item3D = this.subItem3D;
        spacer = this.subItemSpacer;
        left = this.mainLeft + this.mainWidth - this.subOffsetLeft + ((this.mainBorderWidth+this.mainItem3D)*2) + (level-2) * (width+border+item3D*2-this.subOffsetLeft);
      }
      if(color.search(/\.(jpg|jpeg|jpe|gif|png)$/i) != -1) {
        bgImg = color;
        color = '';
      }
      else bgImg = 'blank.gif';

      for(j = height = 0; j < items.length; j++) {
        if(items[j].parent == items[section].parent) height += (items[j].height + spacer + item3D);
      }
      height -= spacer;

      this.sections[i].width = width + (border + item3D) * 2;
      this.sections[i].height = height + border*2 + item3D;

      if(IE4 || DOM) document.write('<div id="menu' + i + '" style="position:absolute' +
                                    '; top:' + this.sections[i].topY + 'px' +
                                    '; left:' + left + 'px' +
                                    '; width:' + this.sections[i].width + 'px' +
                                    '; height:' + this.sections[i].height + 'px' +
                                    (color ? '; background-color:' + color : '') +
                                    '; z-index:' + i +
                                    '; visibility:hidden">');
      else if(NN4) document.write('<layer id="menu' + i + '"' +
                                  ' top=' + this.sections[i].topY +
                                  ' left=' + left +
                                  ' width=' + this.sections[i].width +
                                  ' height=' + this.sections[i].height +
                                  (color ? ' bgcolor=' + color : '') +
                                  ' z-index=' + i +
                                  ' visibility="hide">');

      document.write('<a href="#" onMouseOver="mObj.mOver=true" onMouseOut="mObj.mOver=false">' +
                     '<img src="' + bgImg + '" border=0 width=' + this.sections[i].width +
                     ' height=' + this.sections[i].height + '></a>');

      this.buildItems(section-1, i);

      if(IE4 || DOM) document.write('</div>');
      else if(NN4) document.write('</layer>');

      if(this.mainOpacity && level < 2) this.setOpacity(i, this.mainOpacity);
      else if(this.subOpacity && level > 1) this.setOpacity(i, this.subOpacity);
    }
  }
  this.buildSections();
  this.showMenu(0);
}

//------------------------------------------------------------------------
// Arguments: position level 1, [position level 2], ... [position level n]
// Example:   jumpTo(1, 3, 2, 1) ==> this jumps to menu item 1.3.2.1
//
function jumpTo() {
  var pos, aktPos;
  var item = 0;
  var level = 1;
  for(i = 0; i < jumpTo.arguments.length; i++, level++) {
    pos = jumpTo.arguments[i];
    for(aktPos = 0; item < items.length && aktPos < pos; item++) {
      if(items[item].level == level) aktPos++;
    }
  }
  if(item) {
    item--;
    if(items[item].onClick) eval(items[item].onClick);
    mObj.jumpURL(items[item].url);
  }
}
//------------------------------------------------------------------------
//
function entry(level, height, text, url, onClick) {
  var i = items.length;
  items[i] = new makeItem(i, level, height, text, url, onClick);
}

function makeItem(nr, level, height, text, url, onClick) {
  this.level = level;
  this.height = height;
  this.text = text;
  this.url = url;
  this.onClick = onClick;
  this.parent = -1;

  var parent = nr - 1;
  if(parent >= 0) {
    if(level == items[parent].level + 1) this.parent = parent;
    else if(level == items[parent].level) this.parent = items[parent].parent;
    else if(level < items[parent].level) {
      for(var i = parent; i >= 0; i--) {
        if(items[i].level == level) {
          this.parent = items[i].parent;
          break;
        }
      }
    }
  }
}

function makeSection(nr, level, topY) {
  this.nr = nr;
  this.level = level;
  this.topY = topY;
  this.active = false;
  this.y = topY;
  this.width = 0;
  this.height = 0;
  this.timer = 0;
  this.opacity = 0;
}

var mObj = new MENU();

window.onload = function() {
  if(mObj) {
    if(mObj.iv) clearInterval(mObj.iv);
    mObj.iv = setInterval('mObj.checkIt()', 1);
  }
}

//----------------------------------------------------------------------------------------------------

