﻿var arrNews;
var arrNewsCount = 0;
var currentNews = 0;
var nextNews = -1;
var TimerNewsId = 0;

function initializeNews()
{
    arrNews = $(".NewsSlider");

    arrNewsCount = arrNews.length;

    if (arrNewsCount <= 0)
    {
        return;
    }
    
    showNews();
      
}

function showNews()
{
    currentNews = nextNews;

    $(arrNews[currentNews]).fadeIn(800);
    $("#link_news_" + currentNews).fadeIn(500);
    $("#pallino_"+currentNews).attr({'src':'/Content/img/pallino.png'});

    nextNews = currentNews + 1;

    if (nextNews > (arrNewsCount - 1))
    {
        nextNews = 0;
    }
    clearTimeout(TimerNewsId);
    TimerNewsId = setTimeout("HideNews()", 5000);
}

function HideNews()
{
    $(arrNews[currentNews]).fadeOut(800);
    $("#link_news_" + currentNews).fadeOut(500);
    $("#pallino_" + currentNews).attr({ 'src': '/Content/img/pallino_empty.png' });
    clearTimeout(TimerNewsId);
    TimerNewsId = setTimeout("showNews()", 1300);
}

function changeNews(id)
{
    clearTimeout(TimerNewsId);
    $(arrNews[currentNews]).stop(true, true);
    $(arrNews[currentNews]).fadeOut(800);
    $("#link_news_" + currentNews).fadeOut(500);
    $("#pallino_" + currentNews).attr({ 'src': '/Content/img/pallino_empty.png' });
    currentNews = id;
    $(arrNews[id]).fadeIn(800);
    $("#link_news_" + currentNews).fadeIn(500);
    $("#pallino_" + currentNews).attr({ 'src': '/Content/img/pallino.png' });
}
