function nascondiEventi() {
        $("#elencoEventi").hide(0,function() {
		$("#ElencoDirette").show();});
		
		$("#ulEventi").remove();

    }
    function mostraEventi(nEventi) {
	$("#ElencoDirette").hide(0,function() {
		$("#elencoEventi").show();});


if ($("#ulEventi").children().length > 1)
            $(".newsticker-jcarouselliteNO").jCarouselLite({
                start: 0,
                circular: true,
                vertical: true,
                visible: 1,
                auto: 500,
                speed: 500
            });
        //});
            setTimeout("nascondiEventi(); setTimeout('AggiornaEventiStripEvidenza()', 5000);", nEventi * 4000); //3000+1000
    }
    $(document).ready(function () {
        _ultimoAggiornamento = new Date($.cookie("_ultimoAggiornamento"));
        //$("#dbg").html("coockie:" + $.cookie("_ultimoAggiornamento"));
        if (_ultimoAggiornamento == null)
            _ultimoAggiornamento = new Date("1/1/1990");
        if ($("#RDirette").children().length > 0)
            AggiornaEventiStripEvidenza();

        if ($("#RDirette").children().length > 1)
            $(".newsticker-jcarousellite").jCarouselLite({
                vertical: true,
                visible: 1,
                auto: 3000,
                speed: 1000
            });

            if ($("#RNews").children().length > 1)
                $(".newsticker-jcarousellite").jCarouselLite({
                    vertical: true,
                    visible: 1,
                    auto: 3000,
                    speed: 1000
                });


    }
  );

    Date.prototype.toAspNet = function () { return formatDate(this, "dd/MM/yyyy HH:mm:ss") }
    String.prototype.dataFromAspNet = function () { return new Date(parseInt(this.replace("/Date(", "").replace(")/", ""), 10)) }
    var _ultimoAggiornamento ;
    function AggiornaEventiStripEvidenza() {

        // Add the page method call as an onclick handler for the div.
        $.ajax({
            type: "POST",
            url: "/ws/stripEvidenza.aspx/Aggiorna",
            data: "{'StrUltimoAggiornamento':'" + _ultimoAggiornamento.toAspNet() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var eventiPartita = msg.d;


                if (eventiPartita.length > 0) {
                    var ul = $('<ul id="ulEventi"></ul>');
                    $(".newsticker-jcarouselliteNO").append(ul);
                    //                    $("#ulEventi").empty();
                    $.each(eventiPartita, function (index, eventoPartita) {




                        if (_ultimoAggiornamento == "" || _ultimoAggiornamento < eventoPartita.DataAggiornamento.dataFromAspNet())
                            _ultimoAggiornamento = eventoPartita.DataAggiornamento.dataFromAspNet();

                        if (eventoPartita.Diretta)
                            link = "/dirette/diretta.aspx?IdPartita=" + eventoPartita.IdPartita;
                        else
                            link = "/RisultatiLive.aspx";
                        var newRow = $("<li><a href='" + link + "'><img src='/img/BtDiretta/" + eventoPartita.Tipo + ".png' title='" + eventoPartita.Tipo + "'/>" + eventoPartita.Tipo + " " + eventoPartita.Squadra + " - " + eventoPartita.Minuti + "' - " + eventoPartita.Tempo + "° Tempo <span>" + eventoPartita.Punteggio + "</span></a></li>");

                        $("#ulEventi").append(newRow);
                    });


                    $.cookie("_ultimoAggiornamento", _ultimoAggiornamento);
                    mostraEventi(eventiPartita.length);
                }
                else
                    setTimeout("AggiornaEventiStripEvidenza()", 10 * 1000);

            }
        });
    }
