/** ----------------------------------------------------------------------------
Sistema para rotar artículos dentro de un DIV
  v1.1 2007/04/10 - CVI   - Sistema desarrollado para lanacion2007
  v1.2 2007/04/17 - CVI   - Se agrega soporte para Recortes... :S
  v2.0 2007/05/23 - CVI   - Soporte para rotar automático, en fase beta.
---------------------------------------------------------------------------- **/
var objlist = new Array();

//------------------------------------------------
function bloque(id_div, id_btn, maximo, loop) {

  this.LOOP = loop;
  this.id_div = id_div;
  this.id_btn = id_btn;
  this.maximo = maximo;
  this.maximo_loop;

  this.titu_list = new Array();
  this.baj_list = new Array();
  this.file_list = new Array();
  this.img_list = new Array();
  this.wimg_list = new Array();
  this.himg_list = new Array();
  this.secc_list = new Array();
  this.aut_list = new Array();
  this.tipo_list = new Array();
  this.ts_list = new Array();
  this.stars_list = new Array();

  this.actual_titu_list = new Array();
  this.actual_baj_list = new Array();
  this.actual_file_list = new Array();
  this.actual_img_list = new Array();
  this.actual_wimg_list = new Array();
  this.actual_himg_list = new Array();
  this.actual_secc_list =  new Array();
  this.actual_aut_list = new Array();
  this.actual_tipo_list = new Array();
  this.actual_ts_list = new Array();
  this.actual_stars_list = new Array();

  this.total = 0;
  this.actual = 0;

//  Funciones y Metodos para este objeto
  this.addBloque = addBloque;
  this.moveDiv = moveDiv;
  this.setNewArray = setNewArray;
  this.showLayer = showLayer;
  this.getDiv = getDiv;
  this.setStars = setStars;
};

//------------------------------------------------
function initLayer() {
  for(i=0 ; i<objlist.length ; i++) {
    objlist[i].setNewArray();
    objlist[i].showLayer();
  };
};

//------------------------------------------------
function addBloque(titu,baj,fil,img,wimg,himg,secc,aut,tipo,ts) {
  this.titu_list[this.total] = titu;
  this.baj_list[this.total] = baj;
  this.file_list[this.total] = fil;
  this.img_list[this.total] = img;
  this.wimg_list[this.total] = wimg;
  this.himg_list[this.total] = himg;
  this.secc_list[this.total] = secc;
  this.aut_list[this.total] = aut;
  this.tipo_list[this.total] = tipo;
  this.ts_list[this.total] = ts;
  this.stars_list[this.total] = '';
  this.total++;
};

//------------------------------------------------
function setStars(stars) {
  this.stars_list[this.total-1] = stars;
};

//------------------------------------------------
function moveDiv( dir ) {
  if(this.LOOP) {
    if(dir == '+') {
      this.actual++;
      if(this.actual >= this.total) {this.actual=0;}
    } else if(dir == '-') {
      this.actual--;
      if(this.actual < 0 ) {this.actual=this.total-1;}
    } else {
      return;
    };
  } else {
    if(dir == '+') {
      this.actual++;
      if( (this.maximo - 1 + this.actual) >= this.total) {this.actual--;}
    } else if(dir == '-') {
      this.actual--;
      if(this.actual < 0 ) {this.actual=0;}
    } else {
      return;
    };
  };
  this.setNewArray();
  this.showLayer();

  // Para habilitar los recortes dentro del DIV         CVI - 2007/04/17
  inicio_Recortes();
//  setTimeout("inicio_Recortes()", 500);
//  setTimeout("setRecortesVisibility()", 2000);
};

//------------------------------------------------
function setNewArray() {

  var j = 0;
  var actual_child = this.actual;
  if( this.total > this.maximo ) {
    this.maximo_loop = this.maximo;
  } else {
    this.maximo_loop = this.total;
    var div = eval("document.getElementById('"+this.id_btn+"')");
    if(div) {
      div.style.display = 'none';
    };
  };

  while( j < this.maximo_loop ) {
    if(actual_child >= this.total) { actual_child = 0 };
    if(actual_child < 0) { actual_child = (this.total-1)};
    this.actual_titu_list[j] = this.titu_list[actual_child];
    this.actual_baj_list[j] = this.baj_list[actual_child];
    this.actual_file_list[j] = this.file_list[actual_child];
    this.actual_img_list[j] = this.img_list[actual_child];
    this.actual_wimg_list[j] = this.wimg_list[actual_child];
    this.actual_himg_list[j] = this.himg_list[actual_child];
    this.actual_secc_list[j] = this.secc_list[actual_child];
    this.actual_aut_list[j] = this.aut_list[actual_child];
    this.actual_tipo_list[j] = this.tipo_list[actual_child];
    this.actual_ts_list[j] = this.ts_list[actual_child];
    this.actual_stars_list[j] = this.stars_list[actual_child];
    actual_child++;
    j++;
  };
};

//------------------------------------------------
function showLayer() {

  var div = eval("document.getElementById('"+this.id_div+"')");
  var innerdata = '';
  for(j=0 ; j < this.maximo_loop ; j++) {
    innerdata += getDiv( this, j )
  };
  div.innerHTML = innerdata;
};

//------------------------------------------------
function getDiv( obj, g ) {

  var str = '';
  var tipo = obj.actual_tipo_list[g];

  if(tipo == 'tbanner') {
// ------------------------ BANNER
    str += '<div class="'+obj.id_div+'_inner">\n';
    str += '<table width="100%" border="0" cellspacing="2" cellpadding="2" class="rotar_banner">';
    str += '<tr>';
    str += '  <td align="center">';
    str += '    <a href="'+obj.actual_file_list[g]+'" target="'+obj.actual_baj_list[g]+'">';
    str += '      <img src="'+obj.actual_img_list[g]+'" width="'+obj.actual_wimg_list[g]+'" height="'+obj.actual_himg_list[g]+'" alt="'+obj.actual_titu_list[g]+'" border="0" class="'+obj.id_div+'_img"/></a>\n';
    str += '  </td>';
    str += '</tr>';
    str += '</table>';
    str += '</div>\n';
    str += '<div class="destacados_separador"></div>\n';
  } else if(tipo == 'tgaleria') {
// ------------------------ GALERIA
    str += '<div class="'+obj.id_div+'_inner">\n';
    str += '<a href="'+obj.actual_file_list[g]+'">';
    str += '<img src="'+obj.actual_img_list[g]+'" width="'+obj.actual_wimg_list[g]+'" height="'+obj.actual_himg_list[g]+'" border="0" class="'+obj.id_div+'_img"></a>\n';
    str += '</div>\n';
    str += '<div class="destacados_separador"></div>\n';
  } else if(tipo == 'thumor') {
// ------------------------ HUMOR MICO
    if( document.getElementById('autor_humor') ) {
      var img=document.getElementById('autor_humor');
      if(obj.actual_aut_list[g]) {
        img.src='/prontus_noticias_v2/imag/site/'+obj.actual_aut_list[g]+'.gif';
      };
    };
    str += '<div class="'+obj.id_div+'_inner">\n';
    str += '<a href="'+obj.actual_file_list[g]+'">';
    str += '<img src="'+obj.actual_img_list[g]+'" width="'+obj.actual_wimg_list[g]+'" height="'+obj.actual_himg_list[g]+'" alt="'+obj.actual_aut_list[g]+'" border="0" class="'+obj.id_div+'_img"/></a>\n';
    str += '</div>\n';
  } else if(tipo == 'tcine') {
// ------------------------ CINE
    str += '<div class="'+obj.id_div+'_inner">\n';
    str += '<table width="98%" border="0" cellspacing="0" cellpadding="0">\n';
    str += '<tr>\n';
    if(obj.actual_wimg_list[g]!='' && obj.actual_wimg_list[g]!=null && obj.actual_wimg_list[g]!=undefined) {
      str += '<td width="150" valign="top" align="center">\n';
      str += '<img src="'+obj.actual_img_list[g]+'" width="'+obj.actual_wimg_list[g]+'" height="'+obj.actual_himg_list[g]+'" alt="'+obj.actual_titu_list[g]+'" hspace="2" class="'+obj.id_div+'_img"/></td></tr>';
    };
    str += '<tr><td>\n';
    for(h=0; h<obj.actual_stars_list[g]; h++) {
      str += '<img src="/prontus_noticias_v2/imag/site/estrella_cine.gif" width="14" height="14" />\n';
    };
    str += '</td></tr>\n';
    str += '<tr>\n';
    str += '<td><a href="'+obj.actual_file_list[g]+'" class="tit_rojo">'+obj.actual_titu_list[g]+'</a><br />\n';
    str += '<a href="'+obj.actual_file_list[g]+' <img src="/prontus_noticias_v2/imag/site/ir_negro.gif" width="9" height="7" hspace="4" border="0" /></a>\n';
    if (BROWSER_VALIDO_REC) {
      str += '<div class="r" id="rec'+obj.actual_ts_list[g]+'"><a href="javascript:void(0);" ><img src="/prontus_noticias_v2/imag/recortes/carpeta_gris.gif" width="11" height="9" alt="tijera" border="0" title="Agregar este artículo a tus recortes" /></a></div>\n';
    };
    str += '</td>\n';
    str += '</tr>\n';
    str += '</table>\n';
    str += '</div>\n';
  } else {
// ------------------------ OTROS
    str += '<div class="'+obj.id_div+'_inner">\n';
    str += '<table width="96%" align="center" border="0" cellspacing="2" cellpadding="2"  class="rotar_general'+obj.actual_secc_list[g]+'">';
    if(obj.actual_secc_list[g]!='' && obj.actual_secc_list[g]!=null && obj.actual_secc_list[g]!=undefined) {
      str += '<tr>';
      str += '  <td colspan="2" class="fecha" valign="middle">';
      str += '    <a href="/cgi-bx/prontus_taxport_lista.cgi?seccion='+obj.actual_secc_list[g]+'&_REL_PATH_PRONTUS=/prontus_noticias_v2">';
      str += '    <img src="/prontus_noticias_v2/imag/site/dest'+obj.actual_secc_list[g]+'.gif" border="0" /></a></td>';
      str += '</tr>';
    };
    str += '<tr>';
    if(obj.actual_wimg_list[g]!='' && obj.actual_wimg_list[g]!=null && obj.actual_wimg_list[g]!=undefined) {
      str += '  <td valign="top" class="fecha">';
      str += '    <img src="'+obj.actual_img_list[g]+'" width="'+obj.actual_wimg_list[g]+'" height="'+obj.actual_himg_list[g]+'" alt="'+obj.actual_titu_list[g]+'" class="'+obj.id_div+'_img"/></td>';
      str += '  <td class="textos" valign="top">';
    } else {
      str += '  <td colspan="2" class="textos" valign="top">';
    };
    str += '    <a href="'+obj.actual_file_list[g]+'" class="tit_azul">'+obj.actual_titu_list[g]+'</a><br />';
    str += '    <a href="'+obj.actual_file_list[g]+'" class="links2">'+obj.actual_aut_list[g]+'</a>';
    str += '    <a href="'+obj.actual_file_list[g]+'" class="textos">'+obj.actual_baj_list[g]+'<img src="/prontus_noticias_v2/imag/site/ir_negro.gif" width="9" height="7" hspace="4" border="0" /></a>';
    if (BROWSER_VALIDO_REC) {
      str += '    <div class="r" id="rec'+obj.actual_ts_list[g]+'"><a href="javascript:void(0);" ><img src="/prontus_noticias_v2/imag/recortes/carpeta_gris.gif" width="11" height="9" alt="tijera" border="0" title="Agregar este artículo a tus recortes" /></a></div>';
    };
    str += '  </td>';
    str += '</tr>';
    str += '</table>';
    str += '</div>\n';
    str += '<div class="destacados_separador"></div>\n';
  };
  return str;
};


//------------------------------------------------------------------------------
//   ROTAR AUTOMÁTICO
//------------------------------------------------------------------------------
function autoBloque(id_div, sec) {
  this.id_div = id_div;
  this.sec = sec;

  this.imag_list = new Array();
  this.himag_list = new Array();
  this.wimag_list = new Array();
  this.texto_list = new Array();
  this.url_list = new Array();

  this.total = 0;     //total de artículos
  this.actual = -1;

  //  Funciones y Metodos para este objeto
  this.autoAddBloque = autoAddBloque;
  this.autoShowLayer = autoShowLayer;
  this.changeBloque = changeBloque;
};

//------------------------------------------------
function autoAddBloque(imag, wimag, himag, texto, url) {
  this.imag_list[this.total] = imag;
  this.wimag_list[this.total] = wimag;
  this.himag_list[this.total] = himag;
  this.texto_list[this.total] = texto;
  this.url_list[this.total] = url;
  this.total++;
};

//------------------------------------------------
function changeBloque() {
  this.actual++;
  if(this.actual >= this.total) {this.actual=0;}
};

//------------------------------------------------
function autoShowLayer() {
  var div = eval("document.getElementById('"+this.id_div+"')");
  if( this.imag_list[this.actual]!='' ) {
    var html = '<a href="'+this.url_list[this.actual]+'"  class="textos"><img src="'+this.imag_list[this.actual]+'" width="'+this.wimag_list[this.actual]+'" ';
    html += 'height="'+this.himag_list[this.actual]+'" border="0" alt="La Nacion" style="border: 1px solid #000000" /><br />' + this.texto_list[this.actual] + '</a>';
    div.innerHTML = html;
  };
};

//------------------------------------------------
function initLayerAuto() {
  bloque_auto.changeBloque();
  bloque_auto.autoShowLayer();
  setTimeout("initLayerAuto()",bloque_auto.sec*1000);
};