
lista_citazioni = new Array();


$(document).ready(function(){
  $("#box-menu").html($("#box-menu").html() + '<div id="box-menu-sx"></div><div id="box-menu-dx"></div>');
  $("#box-menu").find("a").each(function(){
    $(this).mouseover(function(){
      $(this).attr("class", "selected");
    }).mouseout(function(){
      $(this).attr("class", "");
    });
   /* $('.carousel').carousel();*/
  });
  
  var options = { opacity: 0.5, height: 35 };
  
  $('#anteprima-copertine img').reflect(options);
  $('#griglia-cataloghi h2').html("");    
  $("#anteprima-video").mouseover(function(){
    $("#anteprima-video img").hide();
  }).mouseout(function(){
    $("#anteprima-video img").show();
  }).prettyPhoto({
            show_title: false,
            width: 800,
            height: 350,
            custom_markup: '<video id="videoPlayerAg" width="600" height="350" controls="controls" preload="none" autoplay="autoplay"><source type="video/wmv" src="/video/SPOT.wmv"/><source type="video/mp4" src="/video/SPOT.mp4" /></video>', changepicturecallback: function(){ load_mediaelement(); }
          });

  $('.carousel').carousel({
      hAlign:'left', 
      vAlign:'center', 
      backZoom: 1.0, 
      vMargin:1.0, 
      hMargin:1.2, 
      directionNav: true, 
      frontWidth:70, 
      frontHeight:90,
      top:4,
      left:44,
      reflection:true,
      autoplay:true,
      slidesPerScroll:5,
      reflectionColor:'35,35,35'});

  var options2 = { opacity: 0.5, height: 12 };
  $('.carousel').find('img').reflect(options2);
  $('#catalogoHome img').reflect(options2);
  
  $("#citazione").find("img").each(function(){
    lista_citazioni.push($(this));
  });
  show_citazione(0);
});

function start_carousel() {
 setTimeout(function(){
    $('.carousel').carousel().next();
    start_carousel();
  }, 1500);
}

function show_citazione(index_citazioni) {
  lista_citazioni[index_citazioni].fadeIn(2000, function() {
    setTimeout(function(){
      hide_citazione(index_citazioni);
    }, 3000);
  });
}

function hide_citazione(index_citazioni) {
  lista_citazioni[index_citazioni].fadeOut(2000, function(){
    if(index_citazioni == lista_citazioni.length -1) {
      next = 0;
    } else {
      next = index_citazioni + 1;
    }
    show_citazione(next);
  });
}

function load_mediaelement(){
  //alert("carico mediaelements");
  $('#videoPlayerAg').mediaelementplayer({
    enablePluginDebug: false, plugins: ['silverlight'], pluginPath: '/clientBin/', silverlightName: 'silverlightmediaelement.xap',
    defaultVideoWidth: 640, defaultVideoHeight: 360, pluginWidth: -1, pluginHeight: -1, timerRate: 250, startVolume: 0.5,
    success: function (mediaElement, domObject) {
        /*if (mediaElement.pluginType == "silverlight") {
            mediaElement.setSrc("/video/SPOT.wmv");
            mediaElement.load(); //force reload settings
        }*/

        mediaElement.play();

        //hide the control bar
        $(".mejs-mediaelement").trigger("mouseleave");
    },

    error: function () {
        alert("Error on video player");
    }
  });
}
