// GRUPO SCOUT NIERY (Villar del Arzobispo)
// (c) 2003, ansanma@hotmail.com

// INICIAR PÁGINA
function fIniciar(pag) {
  if (pag == 'index') fIniciarMarquesina();
  else fMostrarMini(listaEventos[listaEventos.length - 1].id);
}

// MARQUESINA
var longitud;
var max = 800;
var x;
var reloj;

function fIniciarMarquesina() {
  if (marquesinaMostrar) {
    texto = marquesinaTexto;
    if (texto == '') {
      n = Math.floor(Math.random() * frases.length);
      texto = frases[n];
    }
    longitud = 9 * texto.length;
    x = max;
    obj = fItem('derecha');
    obj.style.width = (12 * texto.length + 100) + 'px';
    obj = fItem('marquesina');
    obj.style.width = longitud + 'px';
    obj.style.left = x + 'px';
    obj.innerHTML = texto;
    fMostrarItem('marquesina');
    reloj = window.setInterval('fMoverMarquesina()', 15);
  } else {
    fOcultarItem('marquesina');
  }
}

function fMoverMarquesina() {
  x = x - 2;
  if (x < -longitud) x = max;
  fItem('marquesina').style.left = x + 'px';
}


// CORREO
function fCorreo(quien) {
  if (quien == 'grupo') { usuario = 'niery.msc'; servidor = 'scouts-es'; dominio = 'net'; }
  else if (quien == 'webmaster') { usuario = 'ansanma'; servidor = 'hotmail'; dominio = 'com'; }
  correo = usuario + '@' + servidor + '.' + dominio;
  if (correo != '@.') document.write('<a href="mailto:'+ correo + '">' + correo + '</a>');
}

// FOTOS
// Objeto foto
function foto(evento, fichero, texto) {
  this.evento = evento;
  this.fichero = fichero;
  this.texto = texto;
  this.mini = '_' + fichero;
}

// Objeto evento
function evento(id, titulo, descripcion) {
  this.id = id;
  this.titulo = titulo;
  this.descripcion = descripcion;
}

// Pintar la lista de eventos
function fsListaEventos() {
  lista = '';

  for (i = listaEventos.length - 1; i >= 0; i--) {
    evento = listaEventos[i];
    lista = lista + '<a href="javascript:fMostrarMini(' + evento.id + ')">' + evento.titulo + '</a>';
    if (i != 0) lista = lista + ' ˇ ';
  }

  return lista;
}

// Pintar la lista de miniaturas
function fsListaMini(id) {
  lista = '';
  n = 0;

  for (i = 0; i < listaFotos.length; i++) {
    foto = listaFotos[i];
    if (foto.evento == id) {
      lista = lista + ' <a href="javascript:fMostrarFoto(' + i + ');"><img src="fotos/' + foto.mini + '" alt="' + foto.texto + '"></a>';
      n++;
      if (n % 2 == 0) lista = lista + '<br>';
    }
  }

  return lista;
}

// Mostrar lista de miniaturas al seleccionar un evento
function fMostrarMini(id) {
  fItem('mini').innerHTML = fsListaMini(id);

  i = -1;
  if (listaFotos.length > 0) {
    do {
      i++;
      evento = listaFotos[i].evento;
    } while (evento != id && i < listaFotos.length);

    fMostrarFoto(i);
  }
}

// Mostrar una foto seleccionada
function fMostrarFoto(n) {
  fItem('fotoImg').src = 'fotos/' + listaFotos[n].fichero;
  for (var i = 0; i < listaEventos.length; i++) {
    if (listaEventos[i].id == listaFotos[n].evento) evento = listaEventos[i].descripcion;
  }
  fItem('fotoTxt').innerHTML = '<b>' + evento + '</b><br>' + listaFotos[n].texto;
}

// CALENDARIO
// Objeto diaCalendario
function diaCalendario(fecha, titulo, descripcion) {
  this.fecha = fecha;
  this.titulo = titulo;
  this.descripcion = descripcion;
}

function fsPintarCalendario() {
  lista = '<table>';
  for (var i = 0; i < calendario.length; i++) {
    objeto = calendario[i];
    lista += '<tr><td class="calendario"><b>' + objeto.fecha + '</b> &gt; ' + objeto.titulo + '<br><span class="nota">' + objeto.descripcion + '</span></td></tr>';
  }
  lista += '<tr><td class="calendario">&nbsp;</td></tr></table>';

  return lista;
}

// ENLACES
// Objeto enlace
function enlace(tipo, nuevo, nombre, descripcion, direccion) {
  this.tipo = tipo;
  this.nuevo = nuevo;
  this.nombre = nombre;
  this.descripcion = descripcion;
  this.direccion = direccion;
}

function fsPintarEnlaces() {
  tipo = '';
  lista = '<table>';
  for (var i = 0; i < enlaces.length; i++) {
    if (tipo != enlaces[i].tipo) lista += '<tr><td class="apartado"><br>enlaces &#155; ' + enlaces[i].tipo + '</td></tr>';
    tipo = enlaces[i].tipo;
    lista += '<tr><td class="texto">'
    lista += '  <br><b>&#155;&nbsp;';
    if (enlaces[i].nuevo == 1) lista += ' <span class="nuevo">NUEVO</span> ';
    lista += enlaces[i].nombre + '</b>';
    lista += '  <br>&nbsp;&nbsp;&nbsp;<span class="nota">' + enlaces[i].descripcion + '</span>';
    lista += '  <br>&nbsp;&nbsp;&nbsp;<a href="http://' + enlaces[i].direccion + '" target="_blank">' + enlaces[i].direccion + '</a>';
    lista += '</td></tr>';
  }
  lista += '</table>';

  return lista;
}


// Funciones genéricas
function fItem(id) {
  if (document.all) obj = eval(id);       // IE
  else obj = document.getElementById(id); // Mozilla
  return obj;
}

function fOcultarItem(id) { fItem(id).style.display = 'none'; }
function fMostrarItem(id) { fItem(id).style.display = ''; }

