﻿// ****
// PBTV
// ****

function pbtvSubmitMovie(id){

    document.getElementById("formMovie").value=id;
    document.getElementById("formPbtv").submit();

}

function pbtvSubmitPage(position){

    document.getElementById("formPosition").value=position;
    document.getElementById("formPbtv").submit();

}

function pbtvPlayMovie(path)
{

    var oPlayer = document.getElementById("swfpbtv");

    if(oPlayer)
    {
    
        oPlayer.sendEvent("stop");
        
        oPlayer.loadFile({file:path});
    
        oPlayer.sendEvent("playpause");
    
    }

    

}

// ****
// MENU
// ****

var menuTimers = new Array();

function menuDisplay(index)
{

    if(menuTimers[index] && menuTimers[index] >= 0)
    {

        window.clearTimeout(menuTimers[index]);

        menuTimers[index] = -1;
        
    }
    
    var oDiv = document.getElementById("menu_div_" + index);
    
    if(oDiv)
    {
    
        oDiv.style.display = "block";
    
    }

}

function menuHide(index)
{

    menuTimers[index] = window.setTimeout("menuHide_execute(" + index + ")", 50);
    
    
}

function menuHide_execute(index)
{

    var oDiv = document.getElementById("menu_div_" + index);
    
    if(oDiv)
    {
    
        oDiv.style.display = "none";
    
    }
    
    menuTimers[index] = -1;
    
}

// ******
// SCROLL
// ******

var scrollWidth = 0;
var scrollTimers = new Array();
var scrollPositions = new Array();

function scrollCheckPositions(id,positions)
{

    if(!scrollPositions[id])
    {

        scrollPositions[id] = new Array();

    }

    scrollPositions[id][0] = (!scrollPositions[id][0] || scrollPositions[id][0] > positions)?0:scrollPositions[id][0];
    
}

function scrollCheckTimer(id)
{

    if(!scrollTimers[id])
    {

        scrollTimers[id] = new Array();
        
    }

}

function scrollDiv(id,mode,step,position,amount)
{

    scrollCheckTimer(id);
    
    switch(mode)
    {
    
        case "left" :

            position = document.getElementById(id).scrollLeft + amount;
    
            scrollDivLeft(id,step,position);

            break;
    
        case "right" :

            position = document.getElementById(id).scrollLeft - amount;
    
            scrollDivRight(id,step,position);

            break;

        case "position" :

            clearTimeout(scrollTimers[id][1]);

        case "auto" :

            var move = document.getElementById(id).scrollLeft - position;
            
            switch(true)
            {
            
                case (move < 0) :

                    scrollDivLeft(id,step,position);

                    break;
            
                case (move > 0) :

                    scrollDivRight(id,step,position);

                    break;

                case (move == 0) :

                    break;

                default :

            }

            break;

        default :

    }

    scrollLeds(id,position);

}

function scrollLeds(id,position)
{

    if(scrollWidth > 0)
    {
    
        position = position / scrollWidth;
        
        for(i=0;i<50;++i)
        {
            
            var oLed = document.getElementById("slidesContainer_Led_" + i);
            
            if(oLed)
            {

                switch(i == position)
                {
                
                    case true :

                        oLed.style.backgroundPosition = "0px -9px";
                        
                        break;
                
                    case false :
                    
                        oLed.style.backgroundPosition = "0px 0px";
                        
                        break;
                        
                    default :

                }
            
            }
        
        }
//        alert(document.getElementById(id).style.width)
    
    }

}

function scrollDivLeft(id,step,position)
{

    clearTimeout(scrollTimers[id][0]);

    if(document.getElementById(id).scrollLeft < position)
    {

        document.getElementById(id).scrollLeft = (document.getElementById(id).scrollLeft + step <= position)?(document.getElementById(id).scrollLeft + step):position;

        scrollTimers[id][0] = setTimeout("scrollDivLeft('" + id + "'," + step + "," + position + ")", 10);

    }
    
}

function scrollDivRight(id,step,position)
{

    clearTimeout(scrollTimers[id][0]);

    if(document.getElementById(id).scrollLeft > position)
    {

        document.getElementById(id).scrollLeft = (document.getElementById(id).scrollLeft - step >= position)?(document.getElementById(id).scrollLeft - step):position;

        scrollTimers[id][0] = setTimeout("scrollDivRight('" + id + "'," + step + "," + position + ")", 10);

    }
    
}

function scrollAutoslide(id,step,width,positions,tempo)
{

    scrollWidth = width;
    
    scrollCheckTimer(id);
    scrollCheckPositions(id,positions);

    var slideto = scrollPositions[id][0] * width;

    ++scrollPositions[id][0];

    scrollDiv(id,"auto",step,slideto);

    scrollTimers[id][1] = setTimeout("scrollAutoslide('" + id + "'," + step + "," + width + "," + positions + "," + tempo + ")", tempo);
   
}
