//
// La forma de uso es:
//  crearBanner(nombre_del_banner, posicion_x, posicion_y, tamaño_x, tamaño_y,
//		html_banner_1, html_banner_2, ... html_banner_n);
// Después (una vez que la página ya ha cargado):
//  mostrarBanner(nombre_del_banner, tiempo_entre_desplazamientos,
//                tiempo_entre_banners, pixels_de_desplazamiento);
// Los tiempos van en milisegundos.
//
function crearBanner(nombre, posx, posy, tamx, tamy)
{
  if (document.all) {
    document.writeln("<div id=\"banner" + nombre + "\" style=\"position:absolute" +
		     "; left:" + posx +
		     "; top:" + posy +
		     "; width:" + tamx +
		     "; height:" + tamy +
		     "; clip:rect(0 " + tamx + " " + tamy + " 0)" +
		     "; visibility:hidden" +
		     ";\">");
  } else if (document.layers) {
    document.writeln("<layer name=\"banner" + nombre + "\"" +
		     " left=" + posx +
		     " top=" + posy +
		     " width=" + tamx +
		     " height=" + tamy +
		     " clip=\"" + tamx + ", " + tamy + "\"" +
		     " visibility=\"hidden\"" +
		     ">");
  }
  var i;

  for (i=5, j=0; i < arguments.length; i+=4, ++j) {
    var id = nombre + (j);
    if (document.all) {
      document.writeln("<div id=\"banner" + id + "\" style=\"position:absolute" +
		       "; left:0" +
		       "; top:" + tamy +
		       "; width:" + tamx +
		       "; height:" + tamy +
		       "; clip:rect(0 " + tamx + " " + tamy + " 0)" +
		       ";\">");
    } else if (document.layers) {
      document.writeln("<layer name=\"banner" + id + "\"" +
		       " left=0" +
		       " top=" + tamy +
		       " width=" + tamx +
		       " height=" + tamy +
		       " clip=\"" + tamx + ", " + tamy + "\"" +
		       ">");
    }

  ///////////////////////////////////////////////////////////////////////////////////
  document.writeln('  <table width="170" border="0" cellspacing="0" cellpadding="0" align="right">  ');
  document.writeln('    <tr>  ');
  document.writeln('      <td width="1">&nbsp;</td>  ');
  document.writeln('       <td width="169">');
  document.writeln('          ');
  document.writeln('          ' + arguments[(4*j + 5)]);
  document.writeln('          ');
  document.writeln('      </td>  ');
  document.writeln('    </tr>  ');

  document.writeln('    <tr>  ');
  document.writeln('      <td width="169" colspan="2">  ');
  document.writeln('        <span class="titularPeqBan">  ');
  document.writeln('          <a href="'+ arguments[(4*j + 8)] +'" class="rotativo" target="_top">   ');
  document.writeln('          ' + arguments[(4*j + 6)]);
  document.writeln('          </a>  ');
  document.writeln('        </span>  ');
  document.writeln('      </td>  ');
  document.writeln('    </tr>  ');

  document.writeln('    <tr>  ');
  document.writeln('      <td width="1">&nbsp;</td>  ');
  document.writeln('      <td width="169">  ');
  document.writeln('        <p class="C3Ban">  ');
  document.writeln('          ' + arguments[(4*j + 7)]);
  document.writeln('        </p>  ');
  document.writeln('      </td>  ');
  document.writeln('    </tr></table>  ');
    //////////////////////////////////////////////////////////////////////////////////////

    if (document.all) {
      document.writeln("</div>");
    } else if (document.layers) {
      document.writeln("</layer>");
    }
  }
  if (document.all) {
    document.writeln("</div>");
  } else if (document.layers) {
    document.writeln("</layer>");
  }
}

function getBannerLayer(n)
{
  var coll;
  var styleObj;

  if (document.layers) {
    coll = "";
    styleObj = "";
  } else if (document.all) {
    coll = "all.";
    styleObj = ".style";
  }
  return eval("document." + coll + "banner" + n + styleObj);
}

function scrollBanner(nombre)
{
  var a;
  var b;
  var l = getBannerLayer(nombre);
  var nb = l.banneractivo + 1;
  var posY;
  if (document.layers) {
    a = l.document.layers[l.banneractivo];
    if (!a) {
      mostrarBanner(nombre, l.tscroll, l.tmostrar, l.pscroll);
      return;
    }
    if (nb >= l.document.layers.length) {
      nb = 0;
    }
    b = l.document.layers[nb];
    b.top -= l.pscroll;
    a.top -= l.pscroll;
    posY = b.top;
  } else if (document.all) {
    a = getBannerLayer(nombre + l.banneractivo);
    if (eval("document.all.banner" + nombre + (l.banneractivo + 1))) {
      b = getBannerLayer(nombre + (l.banneractivo + 1));
    } else {
      b = getBannerLayer(nombre + "1");
      nb = 1;
    }
    b.pixelTop -= l.pscroll;
    a.pixelTop -= l.pscroll;
    posY = b.pixelTop;
  }
  var tiempo;
  var altura;
  if (document.all) {
    altura = l.pixelHeight;
  } else if (document.layers) {
    altura = l.clip.height;
  }
  if (posY <= 0) {
    if (document.layers) {
      a.top = altura;
    } else if (document.all) {
      a.pixelTop = altura;
    }
    tiempo = l.tmostrar;
    l.banneractivo = nb;
  } else {
    tiempo = l.tscroll;
  }
  setTimeout("scrollBanner(\"" + nombre + "\");", tiempo);
}

function mostrarBanner(nombre, tscroll, tmostrar, pscroll)
{
  var l;
  var a;
  l = getBannerLayer(nombre);
  if (document.layers) {
    a = l.document.layers[0];
  } else if (document.all) {
    a = getBannerLayer(nombre + "0");
  }
  a.top = 0;
  l.banneractivo = 0;
  l.tscroll = tscroll;
  l.tmostrar = tmostrar;
  l.pscroll = pscroll;
  l.visibility = "inherit";

  setTimeout("scrollBanner(\"" + nombre + "\");", tscroll);
}
