﻿/*
* JqNews - JQuery NewsTicker
* Author: Gravagnola Saverio and Iuliano Renato
* Version: 2.0 Orizzontale e Verticale
*/

// 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 = 220; //width div
var altezzaDivVert = 55; //height div
var margineDivVert = 5; //margin between div


// Settings for the vertical rotation.
var newsVisualVertical2 = 4; //Number of news to be displayed
var intervalloVert2 = 4000; // time > 2500
var numNewsVert2;
//Enter the same value used in the file css/style.css for "jqnewsVert"
var larghezzaDivVert2 = 220; //width div
var altezzaDivVert2 = 55; //height div
var margineDivVert2 = 5; //margin between div


$(document).ready(function() {
    // Totale news
    numNewsVert = $("#jqnewsVert").children().length;

    // Totale news 
    numNewsVert2 = $("#jqnewsVert2").children().length;

    // Se si è creato il div per le news a rotazione verticale
    if (numNewsVert > 0) {
        jqnewsVertical();
    }
     
	 if (numNewsVert2 > 0) {
        jqnewsVertical2();
    }
});

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 = setInterval(jqNewsRotateVertical, intervalloVert);

    // Gestione del mouseover-mouseout
    $("#jqnewsVert").mouseover(function() { clearInterval(gestInter) });
    $("#jqnewsVert").mouseout(function() { gestInter = setInterval(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 jqnewsVertical2() {
    // Controllo di overflow
    if (newsVisualVertical2 > numNewsVert2) {
        newsVisualVertical2 = numNewsVert2;
    }

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

    var gestInter = setInterval(jqNewsRotateVertical2, intervalloVert2);

    // Gestione del mouseover-mouseout
    $("#jqnewsVert2").mouseover(function() { clearInterval(gestInter) });
    $("#jqnewsVert2").mouseout(function() { gestInter = setInterval(jqNewsRotateVertical2, intervalloVert2); });
}

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