﻿
// Settings for the vertical rotation.
var newsVisualVertical = 4; //Number of news to be displayed
var intervalloVert = 4000; // time > 2500
var numNewsVert;
//Enter the same value used in the file css/style.css for "jqnewsVert"
var larghezzaDivVert = 150; //width div
var altezzaDivVert = 118; //height div
var margineDivVert = 5; //margin between div

// Settings for the horizontal rotation.
var newsVisualOrizzontal = 4;   //Number of news to be displayed
var intervalloOriz = 5000; // time > 1500
var numNewsOrizzontal;
//Enter the same value used in the file css/style.css for "jqnewsOriz"
var larghezzaDivOriz = 200; // width div
var altezzaDivOriz = 190; // height div
var margineDivOriz = "0px 0px 20px 5px"; // margin between div


function jqnewsVertical() {
    // Controllo di overflow
    if (newsVisualVertical > numNewsVert) {
        newsVisualVertical = numNewsVert;
    }

    // Hide delle news superflue all'inizializzazione
    for (var i = newsVisualVertical; i < numNewsVert; i++) {
        $($("#jqnewsVert").children()[i]).css("opacity", "0");
    }

    var gestInter = setTimeout(jqNewsRotateVertical, intervalloVert);

    // Gestione del mouseover-mouseout
    $("#jqnewsVert").mouseover(function() { clearTimeout(gestInter) });
    $("#jqnewsVert").mouseout(function() { gestInter = setTimeout(jqNewsRotateVertical, intervalloVert); });
}

function jqNewsRotateVertical() {
    // Hide della prima news
    $($("#jqnewsVert").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
        // Movimento verso l'alto
        $($("#jqnewsVert").children()[0]).animate({ marginTop: -altezzaDivVert }, 1000, "linear", function() {
            // Ripristino posizione elemento nascosto
        $($("#jqnewsVert").children()[0]).css("margin", margineDivVert);
        // Spostamento in coda dell'elemento nascosto
        $("#jqnewsVert").append($($("#jqnewsVert").children()[0]));
            // Visualizzazione dell'ultima news
        $($("#jqnewsVert").children()[newsVisualVertical - 1]).animate({ opacity: 1 }, 1000);
        });
    });
}

function jqnewsOrizzontal() {
    // Controllo di overflow
    if (newsVisualOrizzontal > numNewsOrizzontal) {
        newsVisualOrizzontal = numNewsOrizzontal;
    }

    // Hide delle news superflue all'inizializzazione
    for (var i = newsVisualOrizzontal; i < numNewsOrizzontal; i++) {
        $($("#jqnewsOriz").children()[i]).css("opacity", "0");
    }
    var gestInter = setInterval(jqNewsRotateOrizzontal, intervalloOriz);

    // Gestione del mouseover-mouseout
    $("#jqnewsOriz").mouseover(function() { clearInterval(gestInter) });
    $("#jqnewsOriz").mouseout(function() { gestInter = setInterval(jqNewsRotateOrizzontal, intervalloOriz); });
}

function jqNewsRotateOrizzontal() {    
    // Hide della prima news
    $($("#jqnewsOriz").children()[0]).animate({ opacity: 0 }, 400, "linear", function() {
        // Movimento verso l'alto
        $($("#jqnewsOriz").children()[0]).animate({ marginLeft: -larghezzaDivOriz }, 200, "linear", function() {
            // Ripristino posizione elemento nascosto
            $($("#jqnewsOriz").children()[0]).css("margin", margineDivOriz);
            // Spostamento in coda dell'elemento nascosto
            $("#jqnewsOriz").append($($("#jqnewsOriz").children()[0]));
            // Visualizzazione dell'ultima news
            $($("#jqnewsOriz").children()[(newsVisualOrizzontal - 1)]).animate({ opacity: 1 }, 400);
        });
    });
}
