
var slideshows = new Array(20);      

function ZavolejFunkci(index, funkce)
{
   slideshows[index].ZavolejFunkci(funkce);
}

function SlideShowClass()
{
    var idCount = 0;
    var frameUp;
    var frameUnder;
    var interval;
    var repeat;
    var	userStop = false;
    var	endSlideShow = false;
    var slideshowTimeInterval;
    var isFirst = true;
    var opacityStep = 5;
    var	opacityUp = 100;
    var prefixName;
    var topID;
    var randomOrder = false;
    
    var index;
    
    this.GetRandom = function(min, max)
    {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }
    
    this.Kontruktor = function(castIDcka, intervalek, indexik, randomOrd)
    {
        if(!window.event)
	    {
		    opacityStep = 0.1;
		    opacityUp = 1;
		    opacity2 = 1;
	    }
    
        prefixName = castIDcka;
        slideshowTimeInterval = intervalek;
        index = indexik;
        
        if (randomOrd)
        {
            randomOrder = true;
            topID = -1;
            var idstring;
            do {
                ++topID;
                idstring = prefixName + (topID + 1);
            }
            while (document.getElementById(idstring) != null)
        }
    }
    
    this.Pokus = function()
    {
        alert('Pokus');
    }
    
    this.ZavolejFunkci = function(funkce)
    {
        if (funkce == 'Pokus')
            this.Pokus();
        else if (funkce == 'play')
            this.Play();
        else if (funkce == 'slideshow')
            this.SlideShow();
        else
            alert('Neznama funkce');
    }
 
    this.ZvedniElement = function(id)
    {
	    if (randomOrder)
	    {
	        var oldID = idCount;
	        do
	            idCount = this.GetRandom(1, topID);
	        while (topID != 1 && idCount == oldID)
	    }
	    else
	    {
	        var idstring = prefixName + (idCount+1);

	        if(document.getElementById(idstring) != null)
	            ++idCount;
	        else
	            idCount = 1;
	    }
    }
    
    this.Start = function()
    {
	    this.PrehodDolni();
	    this.PrehodHorni();

	    frameUnder.style.display = "block";	
    	
	    try
	    {
		    frameUnder.filters.Alpha.opacity = 100;
	    }
	    catch(e){}
    	
	    try
	    {
		    frameUnder.style.opacity = opacityUp;
	    }
	    catch(e){}
    	
	    repeat = setTimeout("ZavolejFunkci("+index+",'play')", slideshowTimeInterval);
    }



    this.PrehodDolni = function()
    {
	    try
	    {
		    frameUnder.style.display = "none";
	    }
	    catch(e){}
    	
	    this.ZvedniElement();
	    frameUnder = document.getElementById(prefixName + idCount);
    }

    this.PrehodHorni = function()
    {
	    try
	    {
		    frameUp.style.display = "none";
	    }
	    catch(e){}

	    this.ZvedniElement();
	    frameUp = document.getElementById(prefixName + idCount);
    }


    this.Play = function()
    {
	    clearInterval(repeat);
    	
	    if(userStop)
	    {
		    if(endSlideShow)
		    {
			    userStop = false;
		    }
		    else
		    {
			    repeat = setTimeout("ZavolejFunkci("+index+",'play')", 100);
		    }
	    }
	    else
	    {
		    clearInterval(interval);
		    interval = setInterval("ZavolejFunkci("+index+",'slideshow')", 100);
	    }
    }

    this.Stop = function()
    {
	    userStop = true;
    }

    this.PauseBottom = function()
    {
	    endSlideShow = true;
	    clearInterval(interval);
	    interval = setTimeout("ZavolejFunkci("+index+",'play')", slideshowTimeInterval);
	    this.PrehodHorni();
    }

    this.PauseUp = function()
    {
	    endSlideShow = true;
	    clearInterval(interval);
	    interval = setTimeout("ZavolejFunkci("+index+",'play')", slideshowTimeInterval);
	    this.PrehodDolni();
    }


    var opacity = 0;
    var opacity2 = 100;
    var type = true;

    this.SlideShow = function()
    {
	    endSlideShow = false;
    	
	    frameUp.style.display = "block";	
	    frameUnder.style.display = "block";	
    	
	    try
	    {
		    frameUp.filters.Alpha.opacity = opacity;
		    frameUnder.filters.Alpha.opacity = opacity2;
	    }
	    catch(e){}
    	
	    try
	    {
		    frameUp.style.opacity = opacity;
		    frameUnder.style.opacity = opacity2;
	    }
	    catch(e){}
    	
    	
    	
	    if(type)
	    {
		    opacity += opacityStep;
		    opacity2 -= opacityStep;
	    }
	    else
	    {
		    opacity -= opacityStep;
		    opacity2 += opacityStep;
	    }
    	
	    if(opacity > opacityUp)
	    {		
		    type = !type;
		    this.PauseUp();
	    }
    	
	    if(opacity < 0)
	    {
		    type = !type;
		    this.PauseBottom();
	    }
    }


}