﻿var newsDisplay = 4;       // number of items to display
var scrollInterval = 5000; // time > 1500
var countNews;             // available news items
var divWidth = 215;        // width div (use same values as in css)
var divHeight = 50;        // height div (use same values as in css)
var divMargin = 0;         // margin between divs (use same values as in css)

function doTicker() {
  if (newsDisplay > countNews) {
    newsDisplay = countNews;
  }
  for (var i = newsDisplay; i < countNews; i++) {
    $($("#jqnewsticker").children()[i]).css("opacity", "0");
  }
  var gestInter = setInterval(doTickerRotate, scrollInterval);
  // Gestione del mouseover-mouseout
  $("#jqnewsticker").mouseover(function() { clearInterval(gestInter) });
  $("#jqnewsticker").mouseout(function() { gestInter = setInterval(doTickerRotate, scrollInterval); });
}

function doTickerRotate() {    
    // Hide della prima news
    $($("#jqnewsticker").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
        // Movimento verso l'alto
        $($("#jqnewsticker").children()[0]).animate({ marginLeft: -divWidth }, 1000, "linear", function() {
            // Ripristino posizione elemento nascosto
            $($("#jqnewsticker").children()[0]).css("margin", divMargin);
            // Spostamento in coda dell'elemento nascosto
            $("#jqnewsticker").append($($("#jqnewsticker").children()[0]));
            // Visualizzazione dell'ultima news
            $($("#jqnewsticker").children()[(newsDisplay - 1)]).animate({ opacity: 1 }, 1000);
        });
    });
}
