var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;

var interval = 20;
var increment = 1;
var pause = 5000;
var leftPadding = 3;
var topPadding = 2;
var curr = 0;
var stop = 0;
var timeNoticias = setTimeout("", 0);
var timeNovidades = setTimeout("", 0);

var NoticiasLeft = 221;
var NoticiasTop = 121;
var NoticiasWidth = 400;
var NoticiasHeight = 70;

var NovidadesLeft = 221;
var NovidadesTop = 229;
var NovidadesWidth = 400;
var NovidadesHeight = 70;

onload = start;

function makeCamIE(tipo,qt) {		// cria camadas no iexplorer
  var text = '<DIV ID="'+tipo+'" STYLE="position:absolute;z-index:1000">';
  for (var i = 0; i < qt ; i++) {
    text += '<DIV ID="' + tipo + i + '" STYLE="position:absolute;z-index:1001"></DIV>';
  }
  text += '</DIV>';
  // coloca o codigo antes do fim do documento
  document.body.insertAdjacentHTML("BeforeEnd", text);
  // propriedades do pai
  with (eval(tipo+".style")) {
    eval("width = "+tipo+"Width");
    eval("height = "+tipo+"Height");
    eval('clip = "rect(0 " + ' + tipo + 'Width + " " + ' + tipo + 'Height + " 0)"');
    eval("pixelLeft = "+tipo+"Left");
    eval("pixelTop = "+tipo+"Top");
    visibility = "visible";
  }
  // propriedades dos filhos
  for (i = 0; i < qt; i++) {
    with (eval(tipo + i + ".style")) {
      visibility = "visible";
      pixelLeft = leftPadding;
      eval("pixelTop = "+tipo+"Height + topPadding");
      eval("width = "+tipo+"Width - 2*leftPadding");
      eval("height = "+tipo+"Height - 2*topPadding");
    }
  }
  fillBanner(tipo,qt);
}

function makeCamNS(tipo,qt) {		// cria camadas no netscape
  // cria camada pai
  eval(tipo + " = new Layer("+tipo+"Width)");
  // propriedades da camada pai
  with (eval(tipo)) {
    eval("clip.right = "+tipo+"Width");
    eval("clip.bottom = "+tipo+"Height");
    eval("left = "+tipo+"Left");
    eval("top = "+tipo+"Top");
    visibility = "show";
    zIndex = 1000;
  }
  // cria camadas filho
  for (var i = 0; i < qt; i++) {
    newcam = tipo +i;
    eval(newcam+'=new Layer('+tipo+'Width - leftPadding, '+tipo+')');
    // propriedades da camada filho
    with(eval(newcam)) {
      visibility = "show";
      left = leftPadding;
      eval("top = topPadding +"+tipo+"Height");
      eval("clip.right = "+tipo+"Width - 2*leftPadding");
      eval("clip.bottom = "+tipo+"Height - 2*topPadding");
      zIndex = 1001
    }
  }
  fillBanner(tipo,qt);
}

function fillBanner(tipo,qt) {		// escreve mensagens nas camadas filho
  if (NS4) {
    for (var i = 0; i < qt; i++) {
      eval("cam = "+ tipo + i);
      eval("cam.document.write(ar"+tipo+"[i])");
      cam.document.close();
    }
  } else {
    for (var i = 0; i < qt; i++) {
      eval("cam = "+tipo + i);;
      eval(tipo + i + ".innerHTML = ar" + tipo + "[i]");
    }
  }
}

function nextMsg(tipo) {		// continua o processo com a proxima camada
  eval("var fromInd = curr"+tipo);
  eval("curr"+tipo+" = (fromInd == ar"+tipo+".length - 1) ? 0 : fromInd + 1");
  eval("scrollBanner(fromInd, curr"+tipo+",tipo)");
}

function scrollBanner(from, to, tipo) {	// rotaciona as camadas
  camto = (NS4) ? tipo+to+".top" : tipo+to+".style.pixelTop";
  camfrom = (NS4) ? tipo+from+".top" : tipo+from+".style.pixelTop";
  if(eval(camto+"> topPadding")){
    eval(camfrom + "-= increment");
    eval(camto+"-= increment");
    eval('time'+tipo+' = setTimeout("scrollBanner(\''+from+'\',\''+to+'\',\''+tipo+'\')", interval)');
  }
  else{
    eval(camfrom+"= topPadding +"+tipo+"Height");
    if(!stop)
      eval('time'+tipo+' = setTimeout("nextMsg(\''+tipo+'\')", pause)');
  }
}

function start() {	// inicia o processo
  loaded=1;
  if (NS4){
    makeCamNS("Noticias",arNoticias.length)
    makeCamNS("Novidades",arNovidades.length)
  }
  else{
    makeCamIE("Noticias",arNoticias.length)
    makeCamIE("Novidades",arNovidades.length)
  }
  if(NS4){
	Noticias0.top=topPadding;
	Novidades0.top=topPadding;
  }
  else{
	Noticias0.style.top=topPadding;
	Novidades0.style.top=topPadding;
  }
  currNoticias = 0;
  currNovidades = 0;
  timeNoticias = setTimeout("nextMsg('Noticias')", pause);
  timeNovidades = setTimeout("nextMsg('Novidades')", pause);
}
