﻿// Settings for the horizontal rotation.
var newsVisualOrizzontal2 = 1;   //Number of news to be displayed
var intervalloOriz2 = 5000; // time > 1500
var numNewsOrizzontal2;
//Enter the same value used in the file css/style.css for "bannerOriz"
var larghezzaDivOriz2 = 526; // width div
var altezzaDivOriz2 = 114; // height div
var margineDivOriz2 = 0; // margin between div

$(document).ready(function() {
    // Totale news
    numNewsVert2 = $("#jqnewsVert2").children().length;

    // Totale news orizzontali
    numNewsOrizzontal2 = $("#bannerOriz2").children().length;

    // Se si è creato il div per le news a rotazione verticale
    if (numNewsVert2 > 0) {
        jqnewsVertical2();
    }
    
    // Se si è creato il div per le news a rotazione orizzontale
    if (numNewsOrizzontal2 > 0) {
        bannerOrizzontal2();
    }
});


function bannerOrizzontal2() {
    // Controllo di overflow
    if (newsVisualOrizzontal2 > numNewsOrizzontal2) {
        newsVisualOrizzontal2 = numNewsOrizzontal2;
    }

    // Hide delle news superflue all'inizializzazione
    for (var i = newsVisualOrizzontal2; i < numNewsOrizzontal2; i++) {
        $($("#bannerOriz2").children()[i]).css("opacity", "0");
    }

    var gestInter2 = setInterval(jqNewsRotateOrizzontal2, intervalloOriz2);

    // Gestione del mouseover-mouseout
    $("#bannerOriz2").mouseover(function() { clearInterval(gestInter2) });
    $("#bannerOriz2").mouseout(function() { gestInter2 = setInterval(jqNewsRotateOrizzontal2, intervalloOriz2); });
}

function jqNewsRotateOrizzontal2() {    
    // Hide della prima news
    $($("#bannerOriz2").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
        // Movimento verso l'alto
       // $($("#bannerOriz2").children()[0]).animate({ marginLeft: -larghezzaDivOriz2 }, 1000, "linear", function() {
            // Ripristino posizione elemento nascosto
           $($("#bannerOriz2").children()[0]).css("margin", margineDivOriz2);
            // Spostamento in coda dell'elemento nascosto
           $("#bannerOriz2").append($($("#bannerOriz2").children()[0]));
            // Visualizzazione dell'ultima news
           $($("#bannerOriz2").children()[(newsVisualOrizzontal2 - 1)]).animate({ opacity: 1 }, 1000);
        //});
    });
}
