$(document).ready(function() {
  set_friendly_timers($('span.destacada_fecha'));
  
  var maskHeight = $("#capa_bloqueo").height();
  var maskWidth = $("#capa_bloqueo").width();
  /*suponiendo el tamaño adecuado de cada*/
  var tamanio_imagen_titular_pequenio_h=100;
  var tamanio_imagen_titular_pequenio_w=190;
  var tamanio_imagen_titular_mediano_h=152;
  var tamanio_imagen_titular_mediano_w=298;
  var tamanio_imagen_titular_grande_h=302;
  var tamanio_imagen_titular_grande_w=591;
  /*40 tamanio del icono de reproduccion pequenio y 60 el icono de reproduccion grande*/
  $(".reproductor_pequenio").css('top',tamanio_imagen_titular_pequenio_h/2-40/2);
  $(".reproductor_pequenio").css('left',tamanio_imagen_titular_pequenio_w/2-40/2);
  $(".reproductor_mediano").css('top',tamanio_imagen_titular_mediano_h/2-40/2);
  $(".reproductor_mediano").css('left',tamanio_imagen_titular_mediano_w/2-40/2);
  $(".reproductor_grande").css('top',tamanio_imagen_titular_grande_h/2-60/2);
  $(".reproductor_grande").css('left',tamanio_imagen_titular_grande_w/2-60/2);

  $("#icono_reproductor").css('top',  maskHeight/2-40/2);
  $("#icono_reproductor").css('left',maskWidth/2-40/2);
  
  $('div[name=modal]').click(function(e) {
    //Cancel the link behavior
    var elemento=e.target;
    
    $.ajax({
      url:'/app/plantillas/ajax_video_web.php?video=' + $(elemento).attr("rel"),
success:function(res){
        $("#dialog1").html(res);
      }
    });
    e.preventDefault();
    
    var id = $(this).attr('href');
    //Get the screen height and width
    //var maskHeight = $("#capa_bloqueo").height();
    //var maskWidth = $("#capa_bloqueo").width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':326});

    //transition effect
    $('#mask').fadeIn(1000);
    $('#mask').fadeTo("slow",0.8);

    //Get the window height and width
    //var winH = $("#capa_bloqueo").height();
    //var winW = $("#capa_bloqueo").width();

    //Set the popup window to center
    $(id).css('top',  maskHeight/2-$(id).height()/2+187);
    $(id).css('left', ($(window).width())/2-$(id).width()/2);

    $("#mask").css('top',  maskHeight/2-$(id).height()/2+172);
    $("#mask").css('left', ($(window).width())/2-maskWidth/2);

    //transition effect
    $(id).fadeIn(2000);

  });
});


$(function(){
  $(".div_noticia").hover(
    function() {
      var elemento_div=$(this).children(".informacion_extra");
      $(elemento_div).fadeIn(400);
    },
    function(){
      var elemento_div=$(this).children(".informacion_extra");
      $(elemento_div).fadeOut('slow');
    }
  );

  $(".div_noticia_portada").hover(
    function() {
      var elemento_div=$(this).children(".informacion_extra_portada");
      $(elemento_div).fadeIn(400);
    },
    function(){
      var elemento_div=$(this).children(".informacion_extra_portada");
      $(elemento_div).fadeOut('slow');
    }
  );
});


// Carousel stuff
function mycarousel_initCallback(carousel) {
  // Disable autoscrolling if the user clicks the prev or next button.
  carousel.buttonNext.bind('click', function() {
    carousel.startAuto(0);
  });

  carousel.buttonPrev.bind('click', function() {
    carousel.startAuto(0);
  });

  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
  
  $('#mycarousel-next').bind('click', function() {
    carousel.next();
    return false;
  });
  
  $('#mycarousel-prev').bind('click', function() {
    carousel.prev();
    return false;
  });
};

$(function() {
  $("#mycarousel").jcarousel({
    initCallback: mycarousel_initCallback,
    buttonNextHTML: null,
    buttonPrevHTML: null,
    wrap: 'circular',
    auto: 7,
  });
});



