var urlService = "";
var countItens = 0;
var totalCarousel = 4;
var skip = 0;
var take = totalCarousel;
var globalList = new Array();

var Movimento = {

    _init: function(url) {
        try {
            this._util(url);
            this._countItens();

        } catch (e) {
            alert(
				'File   : ' + e.fileName + ' \n ' +
				'line     : ' + e.lineNumber + ' \n ' +
				'Name      : ' + e.name + ' \n ' +
				'Description : ' + e.message + ' \n '
			);
        };
    },


    _util: function(url) {
        // Set Url service on Caoursel
        urlService = url;

        //Run first Carousel
        this._serviceList();

        //Add height on box carousel
        $('.video_cur').css('height', '170px');
    },

    _next: function() {
        if (skip < (countItens - totalCarousel)) {
            skip += take;
            this._serviceList();
        }
    },

    _previos: function() {
        if (skip > 0) {
            skip -= take;
            this._serviceList();
        }
    },

    _countItens: function() {
        $.ajax({
            type: "GET",
            url: urlService + "/GetListCount",
            contentType: "application/json; charset=utf-8",
            data: "{}",
            success: function(data) {
                countItens = parseFloat(data.d);
            }
        });
    },

    _serviceList: function() {

        if (globalList != undefined || globalList != "") {

            $('.list_video').empty();

            if (globalList[skip] != null) {

                $.each(globalList[skip], function(index, value) {
                $('.list_video').append(Movimento._estrutura(value.dsTitulo, value.dsImage, value.dslink));
                    $('.list_video li:eq(' + index + ')').hide();
                });

                $('.list_video li:last').addClass('last');

                // effect xurupita
                for (var i = 0; i < $('.list_video li').length; i++) {
                    $('.list_video li:eq(' + i + ')').show('show');
                }
            }

            else {
                $.ajax({
                    type: "POST",
                    url: urlService + "/GetList",
                    contentType: "application/json; charset=utf-8",
                    data: "{pSkip:'" + skip + "',pTake:'" + take + "'}",
                    success: function(data) {
                        globalList[skip] = data.d;
                        $.each(data.d, function(index, value) {
                        $('.list_video').append(Movimento._estrutura(value.dsTitulo, value.dsImage, value.dslink));
                            $('.list_video li:eq(' + index + ')').hide();
                        });

                        $('.list_video li:last').addClass('last');

                        //effect xurupita
                        for (var i = 0; i < $('.list_video li').length; i++) {
                            $('.list_video li:eq(' + i + ')').show('show');
                        }
                    }
                });
            }
        }
    },

    _estrutura: function(pTitle, pImage,pLink) {
        return "<li class='item_video'>" +
						"<div class='video_cur'> <img src='" + pImage + "' width='200' height='112' /></div>" +
                    	"<cite><strong><a href='" + pLink + "'>" +
							pTitle +
						"</strong></cite>" +
					"</li>";
    }
};

















