﻿var itemWidth = 168;




function CallService(comp) {
        //alert("Llamada");
        $.get("/services/realTime.aspx?comp=" + comp,
				function (data) {
				    //alert("call");
				    $("#flow").html(data);
					printScores();
				    $("#compValue").val(comp);
				    if (data == "")
				        CallService(25);
				});



    }


function printScores()
{

var timerId = 0;
    var itemsCount = $("#flow .box").size();
    var pageIndex = 0;
    var totalPages = (itemsCount / 4) - 1;
    var totalWidth = itemsCount * itemWidth;
    var isAnimating = false;


    $("#flow").css("width", totalWidth);
    $("#flow").css("left", 0);


    $("#score-next").unbind('click').click(function () {
        clearInterval(timerId);
        if ( pageIndex < totalPages) {
            pageIndex++;
            isAnimating = true;
            $("#flow").animate({ left: '-=' + (itemWidth * 4) }, 1000, function () { isAnimating = false; });
        }
    });

    $("#score-prev").unbind('click').click(function () {
        clearInterval(timerId);
        if ( pageIndex > 0) {
            pageIndex--;
            isAnimating = true;
            $("#flow").animate({ left: '+=' + (itemWidth * 4) }, 1000, function () { isAnimating = false; });
        }
    });

}

function moveGallery() {
    $("#flow :first").animate({ opacity: "0" }, 500, function () { });
    $("#flow :first").animate({ width: 0, opacity: "0" }, 1000, function () {
    $("#flow :first").clone().css("width", 160).appendTo('#flow').animate({ opacity: "1" }, 2000, function () {});
    $("#flow :first").remove();

  });


    

}



