// Funciones para la barra supervi
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var agt = navigator.userAgent.toLowerCase();
var isOperaSpy = (agt.indexOf("opera") != -1) ? 1 : 0;

/// the following browser detection code is not currently used, but
/// appears to be working:
//
//
/// If (isMozSpy == 1), assume it's one of:
///  - Mozilla;
///  - Opera 5, set to be identified as 'Mozilla X',
///    with X one of (5.0; 4.76; 3.0).
//
/// If (isOpera5IE5Spy == 1), then assume browser is Opera set to
/// identify as 'MSIE 5' although it does not support all properties of it
//



function scrollSpy(theFunction) {


  var NameOfThisSpy = generateSpyInternalName();
  
  eval('window.' + NameOfThisSpy + ' = this;'); // window.RANDOMNAME = <this_spy>
  eval('this.name = "' + NameOfThisSpy + '";'); // <this_spy>.name = "RANDOMNAME"

  this.changeFunction = theFunction;
  this.intervalTime = 200;   // by default 200 milliseconds
  this.enabled = 0;
  this.monitor = monitorScrolling;

  this.getWindowYOffset = getWindowYOffsetSpy;
  this.prevWindowYOffset = 0;

 /// public interface:  

  this.start = startSpy;
  this.stop = stopSpy;
  this.isRunning = isRunningSpy;
  
  this.getIntervalTime = getIntervalTimeSpy;
  this.setIntervalTime = setIntervalTimeSpy;

 /////
}



function startSpy() {
  if (!this.enabled) { // not already running?

    var cmdstring = 'window.' + this.name + '.monitor()';
    
    if (!isOperaSpy)
      this.interval = window.setInterval( cmdstring, this.intervalTime );
    else // work around bug
      this.interval = window.setTimeout( cmdstring, this.intervalTime );

    this.enabled = 1;
  }
}

function stopSpy() {
  if (this.enabled) { // really running?
    window.clearInterval(this.interval);
    this.enabled = 0;
  }
}

function isRunningSpy() {
  return this.enabled;
}

    

function getIntervalTimeSpy() {
  return this.intervalTime;
}

function setIntervalTimeSpy(newValue) {
  var wasRunning = (this.enabled) ? 1 : 0;
  this.stop();
  this.intervalTime = newValue;
  if (wasRunning)
    this.start();
}



function getWindowYOffsetSpy() {

  if ( window.pageYOffset || window.pageYOffset == 0 )
    return window.pageYOffset;

  if ( document.body ) {
    if ( document.body.scrollTop || document.body.scrollTop == 0 ) {

      if ( document.documentElement ) {
        if ( document.documentElement.scrollTop || document.documentElement.scrollTop == 0 ) {
          // IE 6 uses document.documentElement.scrollTop instead of
          // document.body.scrollTop. Has to do with viewpoints -
          // see some w3 spec ;-)
          return document.body.scrollTop + document.documentElement.scrollTop;
        }

      } else {
        return document.body.scrollTop;
      }
    }
  }
}
  
function monitorScrolling() {

  var newWinYOffset = getWindowYOffsetSpy();
  var Scrolled = (newWinYOffset != this.prevWindowYOffset);

  this.prevWindowYOffset = newWinYOffset;

  if (Scrolled)
    eval( 'this.changeFunction(' + newWinYOffset + ')' );

  if (isOperaSpy) {  // work around bug
    var cmdstring = 'window.' + this.name + '.monitor()';
    this.interval = window.setTimeout( cmdstring, this.intervalTime);
  }
    
}



function generateSpyInternalName() {
  var now = new Date();
  var rand = Math.floor(  1000000 * Math.random(now.getTime())  );
  return ('spy' + rand + 's');
}

function setTop(layer, t) {
  layer.style.top=t;
}

function update(scrollPos) {
  thediv1 = document.getElementById('menu1');
  thediv2 = document.getElementById('menu2');
  thediv3 = document.getElementById('menu3');
  thediv4 = document.getElementById('menu4');
  thediv6 = document.getElementById('menu6');
  setTop(thediv1, scrollPos);
  setTop(thediv2, scrollPos);
  setTop(thediv3, scrollPos);
  setTop(thediv4, scrollPos);
  setTop(thediv6, scrollPos);
}

var S;

function initSpy() {
  S = new scrollSpy(update);
  S.start();
} 


window.onload=initSpy;
window.onload();
