﻿function PlayList() {
    this.speedAnimation = 1000;

    /********************
    NOTICIAS
    *********************/
    this.presentPositionN = 0;
    this.presentAnimationN = 1;

    //Configura as informacoes da playlist de noticias
    this.Noticias = function(pElementPl, pOrientation) {
        var elementPl = new String(pElementPl);
        var orientation = new String(pOrientation);
        var totalPaginas = new Number();
        var tbParentSize = new Number();
        var tbListSize = new Number();

        $(document).ready(function() {
            var index = new Number();
            elementPl = "." + pElementPl + " ";
            orientation = pOrientation;

            $(elementPl + ".scroll ul li").each(function(i) {
                index = i;
            });

            var containerSize = $(elementPl + " .scroll").css("" + orientation + "");
            tbParentSize = parseInt(containerSize.substring(0, containerSize.length - 2));

            var listSize = $(elementPl + " .scroll ul").css("" + orientation + "");
            tbListSize = parseInt(listSize.substring(0, listSize.length - 2));

            totalPaginas = Math.ceil(tbListSize / tbParentSize);
            var scrollSize = (tbParentSize * totalPaginas);
            $(elementPl + ".scroll ul").css("" + orientation + "", scrollSize + "px");

            $(elementPl + ".anterior").click(function() { PlayList.AnimateNoticias($(this).parents(".box-playlist"), "anterior", pOrientation, tbParentSize, totalPaginas); });
            $(elementPl + ".proximo").click(function() { PlayList.AnimateNoticias($(this).parents(".box-playlist"), "proximo", pOrientation, tbParentSize, totalPaginas); });
        });
    }

    //Faz movimentacao da playlist de Noticias
    this.AnimateNoticias = function(pElement, pType, pOrientation, pTbParentSize, pTotalPaginas) {
        if (pType == 'proximo' && PlayList.presentAnimationN < pTotalPaginas) {
            PlayList.presentAnimationN++;
            PlayList.presentPositionN = PlayList.presentPositionN - pTbParentSize;
        }
        else if (pType == 'anterior' && PlayList.presentAnimationN > 1) {
            PlayList.presentAnimationN--;
            PlayList.presentPositionN = PlayList.presentPositionN + pTbParentSize;
        }

        if (pOrientation == "height")
            pElement.find(".scroll ul").animate({ marginTop: PlayList.presentPositionN + "px" }, PlayList.speedAnimation);
        else
            pElement.find(".scroll ul").animate({ marginLeft: PlayList.presentPositionN + "px" }, PlayList.speedAnimation);
    }
}
