﻿
var isAnimating = false;
var currentIndex=0;
var myIds = new Array();
var myIdsIndex = new Array();
var intervalID = 0;


    function paginationNews(divId) {
        var myDivID = divId;
        myIds[myIds.length] = myDivID;
       
        var totalChildren = $(myDivID + " .paginable").size();
        myIdsIndex[myIdsIndex.length] = 0;

        for (var i = 0; i < totalChildren; i++) {

            var $newdiv1 = $('<div class="page-icon disable" id="' + divId.replace(".", "").replace("#", "") + '_page_' + i + '"/>');
            if (i == 0)
                $newdiv1 = $('<div class="page-icon active" id="' + divId.replace(".", "").replace("#", "") + '_page_' + i + '"/>');
           
           
            $(divId+" .paginator").append($newdiv1);

            if (i > 0) {
                $(myDivID + " .paginable").eq(i).hide();
                $(myDivID + " .paginable").eq(i).css("top", 360);
            }
            
        }

        for (var i = 0; i < totalChildren; i++) {
            $("#" + divId.replace(".", "").replace("#", "") + "_page_" + i + "").click(function () {
			
                MoveToindex($(this).index(), myDivID);
            });
        }

       

        $(".attachs #att1 img").click(function () {
            
			
            MoveToindex(($(this).index()-1), myDivID);
        });


        $(".attachs #att2 img").click(function () {
           
            MoveToPlayerindex($(this).index(), myDivID, $(this).attr("name"));
        });

        $(".attachs #att4 img").click(function () {
           
            PlayerAudioindex($(this).index(), myDivID, $(this).attr("name"));
        });

        if (intervalID == 0 && document.location.pathname=="/")
            intervalID=setInterval("MoveToindexProg()", 8000);

    }


    function MoveToindexProg() {
      for (var i = 0; i < myIds.length; i++) {

            var obj = myIds[i];
            var index = myIdsIndex[i] + 1;
            var ind = index;
           
            if ($(obj + " .paginable").size() <= index)
               {
                index = 0;
                ind=0;
            }

            myIdsIndex[i] = index;
            
                var item = $(obj + " .paginable").eq(ind);
                var itemActive = $(obj + " .paginator .active").index();

                $(obj + " #videomediaSpace").html("");
                $(obj + " #audiomediaSpace").html("");

                $(obj + " .paginator .page-icon").attr("class", "page-icon disable");
                $(obj + " .paginator .page-icon").eq(ind).attr("class", "page-icon active");


                $(obj + " .videoelement").animate({ opacity: 0, top: 420 }, 800, function () {
                });
                $(obj + " .audioelement").animate({ opacity: 0, top: 420 }, 800, function () {
                });
				
                $(obj + " .paginable").eq(itemActive).animate({ opacity: 0, top: 420 }, 800, function () {

                });

                $(item).show();
                $(item).animate({ opacity: 100, top: 0 }, 800, function () { });
                 


                $(obj + " .videoelement").animate({ opacity: 0, top: 420 }, 800, function () {
                });
                $(obj + " .audioelement").animate({ opacity: 0, top: 420 }, 800, function () {
                });
            
        }
    }


    function MoveToindex(ind, obj) {

        var arrind = $.inArray(obj, myIds);
        //alert(arrind);
        myIdsIndex[arrind] = ind;

        if (isAnimating == false) {
            isAnimating = true;
            var index = ind;
            var item = $(obj + " .paginable").eq(ind);
            var itemActive = $(obj + " .paginator .active").index();

            $("#videomediaSpace").html("");
            $("#audiomediaSpace").html("");

            $(obj + " .paginator .page-icon").attr("class", "page-icon disable");
            $(obj + " .paginator .page-icon").eq(ind).attr("class", "page-icon active");


            $(".videoelement").animate({ opacity: 0, top: 420 }, 800, function () {
            });

            $(".audioelement").animate({ opacity: 0, top: 420 }, 800, function () {
            });

            $(obj + " .paginable").eq(itemActive).animate({ opacity: 0, top: 420 }, 800, function () {
                $(item).show();
                $(item).animate({ opacity: 100, top: 0 }, 800, function () { isAnimating = false; });
            });

            $(".videoelement").animate({ opacity: 0, top: 420 }, 800, function () {
            });
            $(".audioelement").animate({ opacity: 0, top: 420 }, 800, function () {
            });
			currentIndex=index;

        }

    }


    function MoveToPlayerindex(ind, obj,file) {
//        alert(ind + "_" + obj + "_" + file);
        //$("#videomediaSpace"+ ind).html("");
        if (isAnimating == false) {
            isAnimating = true;
            var index = ind;
            
            var item = $(".videoelement"+ ind);
            //alert(".videoelement" + ind);
            var itemActive = $(obj + " .paginator .active").index();

            $(obj + " .paginator .page-icon").attr("class", "page-icon disable");
            $(obj + " .paginator .page-icon").eq(ind).attr("class", "page-icon active");

            $(obj + " .paginable").eq(itemActive).animate({ opacity: 0, top: 360 }, 800, function () {
                //printPlayer(file, index);
                $(item).show();

                $(item).animate({ opacity: 100, top: 0 }, 800, function () { isAnimating = false; });
            });
            //alert(ind + "_" + obj + "_" + file);
        }

    }

    function PlayerAudioindex(ind, obj, file) {
//        alert(ind + "audio_" + obj + "_" + file);
        //$("#videomediaSpace"+ ind).html("");
        if (isAnimating == false) {
            isAnimating = true;
            var index = ind;

            var item = $(".audioelement" + ind);
            //alert(".videoelement" + ind);
            var itemActive = $(obj + " .paginator .active").index();

            $(obj + " .paginator .page-icon").attr("class", "page-icon disable");
            $(obj + " .paginator .page-icon").eq(ind).attr("class", "page-icon active");

            $(obj + " .paginable").eq(itemActive).animate({ opacity: 0, top: 360 }, 800, function () {
                //printPlayer(file, index);
                $(item).show();

                $(item).animate({ opacity: 100, top: 0 }, 800, function () { isAnimating = false; });
            });
            //alert(ind + "_" + obj + "_" + file);
        }

    }

