window.onload=function() {
  // Presentacion de encuesta en ajax
  if(document.getElementById("encuesta")) {
    document.getElementById("encuesta").innerHTML="<b style='background-color:red;color:white;'>loading....</b>";
    // Cargamos la encuesta
    var html = $.ajax({
      type: "POST",
      url: "/encuesta.png.php",
      data: "encuesta=last&cmd=viewpool",
      async: false
    }).responseText;
    // Ponemos la respuesta ajax en el div lo mas
    document.getElementById("encuesta").innerHTML=html;
    btn=document.getElementById("sbtform");
    btn.onclick=function(){
      params=refreshForm("encuesta");
      var htmlgraph = $.ajax({
        type: "POST",
        url: "/encuesta.png.php",
        data: params,
        async: false
      }).responseText;
      document.getElementById("encuesta").innerHTML=htmlgraph;
    };
  }
  // Fin de la presentacion de encuesta
  setInterval("changePic()",6000);
  timer = setInterval("next()",5000);
  var play = true;
  $("#nav .prev a").click(function () {
    prev();
    if ( play ) {
      clearInterval(timer);
      timer = setInterval("next()",5000);
    }
  });
  $("#nav .next a").click(function () {
    next();
    if ( play ) {
      clearInterval(timer);
      timer = setInterval("next()",5000);
    }
  });
  $("#nav .state a").click(function () {
    if ( play ) {
      $(this).removeClass("play");
      $(this).addClass("pause");
      play = false;
      clearInterval(timer);
    } else {
      $(this).removeClass("pause");
      $(this).addClass("play");
      play = true;
      timer = setInterval("next()",5000);
    }
  });
};

function next() {
  var cur = $(".noticia:visible");
  // Sacando
  cur.hide();
  if ( cur.next(".noticia").length > 0 )
    var next = cur.next(".noticia");
  else 
    var next = $(".noticia:first");
  next.show();
}

function prev() {
  var cur = $(".noticia:visible");
  // Sacando
  cur.hide();
  if ( cur.prev(".noticia").length > 0 ) {
    var prev = cur.prev(".noticia");
  } else  {
    var prev = $(".noticia:last");
  }
  prev.show();
}

