﻿function PlayListVideos() {
    var tbByAnimationMax = new Number();
    var tbByAnimation = 5;
    var tbWidth = 167;
    var tbMarginR = 13;
    var tbParentWidth = 887;
    var presentPosition = 0;
    var presentAnimation = 1;
    var speedAnimation = 1000;
    var totalPaginas;
    var totalPaginasp;

    this.Initialize = function() {
        $().ready(function() {
            PlayListVideos.PlayList();
        });
    }

    this.PlayList = function() {
        var index = new Number();
        var indexp = new Number();
        $("#playListVideosExpedicionarios ul li").each(function(i) {
            index = i;
        });
        $("#playListVideosPrograma ul li").each(function(i) {
            indexp = i;
        });

        totalPaginas = Math.ceil((index + 1) / tbByAnimation);
        thumbL = ((index + 1) * (tbParentWidth));

        totalPaginasp = Math.ceil((indexp + 1) / tbByAnimation);
        thumbLp = ((indexp + 1) * (tbParentWidth));

        $("#playListVideosExpedicionarios ul").css("width", thumbL + "px");
        $("#playListVideosPrograma ul").css("width", thumbLp + "px");

        $("#playListVideosExpedicionarios .anterior").click(function() { PlayListVideos.AnimatePlayList("anterior") })
        $("#playListVideosExpedicionarios .proximo").click(function() { PlayListVideos.AnimatePlayList("proximo") })
        $("#playListVideosPrograma .anterior").click(function() { PlayListVideos.AnimatePlayListPrograma("anterior") })
        $("#playListVideosPrograma .proximo").click(function() { PlayListVideos.AnimatePlayListPrograma("proximo") })
    }

    this.AnimatePlayList = function(pType) {
        if (pType == 'proximo' && presentAnimation < totalPaginas) {
            presentAnimation++;
            presentPosition = presentPosition - (tbParentWidth + tbMarginR);
            $('#playListVideosExpedicionarios .scroll ul').animate({ marginLeft: presentPosition + "px" }, speedAnimation);
        }
        else if (pType == 'anterior' && presentAnimation > 1) {
            presentAnimation--;
            presentPosition = presentPosition + (tbParentWidth + tbMarginR);
            $('#playListVideosExpedicionarios .scroll ul').animate({ marginLeft: presentPosition + "px" }, speedAnimation);
        }
    }

    this.AnimatePlayListPrograma = function(pType) {
    if (pType == 'proximo' && presentAnimation < totalPaginasp) {
            presentAnimation++;
            presentPosition = presentPosition - tbParentWidth;
            $('#playListVideosPrograma .scroll ul').animate({ marginLeft: presentPosition + "px" }, speedAnimation);
        }
        else if (pType == 'anterior' && presentAnimation > 1) {
            presentAnimation--;
            presentPosition = presentPosition + tbParentWidth;
            $('#playListVideosPrograma .scroll ul').animate({ marginLeft: presentPosition + "px" }, speedAnimation);
        }
    }    

}
