var t
var j = 0
var numOfPic = Pic.length
var pos = j

var runin = false //Variable que guarda si el SlideShow está corriendo o no.
var pausePos //Variable que guarda la posición en la que se pausa.
var currentBigImg = new Image() //Objeto imagen de la imagen en tamaño grande correspondiente a la que se está visualizando.
var HandlersEnabled = true //Booleano que permite la ejecución de los handlers si hay imágenes y viceversa

var preLoad = new Array()

//------------------------------------------------------
function preLoadPic(index)
{
    if (Pic[index] != '')
    {
        window.status='Cargando : '+Pic[index]
        preLoad[index] = new Image()
        preLoad[index].src = Pic[index]
        Pic[index] = ''
        window.status=''
    }
}
//------------------------------------------------------
function showPic(index)
{
    preLoadPic(index)
    document.forms[0].txtNamePic.value = 'Imagen '+(index+1)+' de '+Pic.length+' \nDescripci\xF3n: '+namePic[index]
    document.images.SlideShow.src = preLoad[index].src
    currentBigImg.src = (preLoad[index].src).replace('.jpg', '_big.jpg')
}
//---------------------------------------------------
function picTransition(index)
{
    if (index != '')
    {
        if (xIE4Up)
    {
        document.images.SlideShow.style.filter='blendTrans(duration=2)'
        document.images.SlideShow.style.filter= 'blendTrans(duration=crossFadeDuration)'
        document.images.SlideShow.filters.blendTrans.Apply()
    }
        document.images.SlideShow.src = preLoad[index].src
        document.forms[0].txtNamePic.value = 'Imagen '+(index+1)+' de '+Pic.length+' \nDescripci\xF3n: '+namePic[index]
        currentBigImg.src = (preLoad[index].src).replace('.jpg', '_big.jpg')
    
    if (xIE4Up)
    {
        document.images.SlideShow.filters.blendTrans.Play()
    }
        pos = index
        index = index + 1
        if (index > (numOfPic-1)) index=0
        t = setTimeout('runSlideShow()', slideShowSpeed)
        preLoadPic(index)
        runin = true
    }
    else
    {
        if (xIE4Up)
        {
            document.images.SlideShow.style.filter='blendTrans(duration=2)'
            document.images.SlideShow.style.filter= 'blendTrans(duration=crossFadeDuration)'
            document.images.SlideShow.filters.blendTrans.Apply()
        }
            document.images.SlideShow.src = preLoad[j].src
            document.forms[0].txtNamePic.value = 'Imagen '+(j+1)+' de '+Pic.length+' \nDescripci\xF3n: '+namePic[j]
            currentBigImg.src = (preLoad[j].src).replace('.jpg', '_big.jpg')
            
        if (xIE4Up)
        {
            document.images.SlideShow.filters.blendTrans.Play()
        }
            pos = j
            j = j + 1
            if (j > (numOfPic-1)) j=0
            t = setTimeout('runSlideShow()', slideShowSpeed)
            preLoadPic(j)
            runin = true
    }
}
//---------------------------------------------
function runSlideShow()
{
    picTransition('')
}
//------------------------------------------
function stopSlideShow()
{
    if (HandlersEnabled == true)
    {
        if (runin == true)
        {
            pausePos = 0
            j = 0
            pos = 0

            if (PlayPause.className != 'CTLImg_ImgPlay')
            {
                PlayPause.className='CTLImg_ImgPlay'
            }

            clearTimeout(t)
            runin = false
        }
        else
        {
            alert('La presentaci\xF3n ya est\xE1 parada.');
        }
    }
    else
    {
        alert('La presentaci\xF3n ya est\xE1 parada.');
    }
}
//----------------------------------------------
function selPlayPause()
{
    if (HandlersEnabled == true)
    {
        if (runin == true)
        {
            if (PlayPause.className != 'CTLImg_ImgPlay')
            {
                PlayPause.className='CTLImg_ImgPlay'
            }

            pauseSlideShow()
        }
        else
        {
            if (PlayPause.className != 'CTLImg_ImgPause')
            {
                PlayPause.className='CTLImg_ImgPause'
            }
            playSlideShow()
        }
    }
    else
    {
        alert('No hay m\xE1s im\xE1genes que reproducir.');
    }
}
//-------------------------------------------
function pauseSlideShow()
{
    if (HandlersEnabled == true)
    {
        pausePos = pos
        clearTimeout(t)
        runin = false
    }
    else
    {
        alert('No hay m\xE1s im\xE1genes que reproducir.');
    }
}
//----------------------------------------
function playSlideShow()
{
    if (HandlersEnabled == true)
    {
        pausePos = pos

        if (runin != true)
        {
            if (pausePos != '')
            {
                picTransition('')
            }
            else
            {
                picTransition(pausePos)
            }
        }
        else
        {
            clearTimeout(t)
            picTransition(pausePos)
            alert('La presentaci\xF3n ya est\xE1 corriendo')
        }
    }
    else
    {
        alert('No hay m\xE1s im\xE1genes que reproducir.');
    }
}
//----------------------------------------
function prevSlideShow()
{
    if (HandlersEnabled == true)
    {
        pos = pos - 1
        if (pos < 0) pos=numOfPic-1
        clearTimeout(t)
        showPic(pos)

        if (PlayPause.className != 'CTLImg_ImgPlay')
        {
            PlayPause.className='CTLImg_ImgPlay'
        }

        runin = false
    }
    else
    {
        alert('No hay m\xE1s im\xE1genes que reproducir.');
    }
}
//---------------------------------------
function nextSlideShow()
{
    if (HandlersEnabled == true)
    {
        pos = pos + 1
        if (pos > (numOfPic-1)) pos=0
        clearTimeout(t)
        showPic(pos)

        if (PlayPause.className != 'CTLImg_ImgPlay')
        {
            PlayPause.className='CTLImg_ImgPlay'
        }

        runin = false
    }
    else
    {
        alert('No hay m\xE1s im\xE1genes que reproducir.');
    }
}
//--------------------------------------
function showCurrentFrame(index)
{
    if (HandlersEnabled == true)
    {
        pos = index
        clearTimeout(t)
        showPic(pos)

        if (PlayPause.className != 'CTLImg_ImgPlay')
        {
            PlayPause.className='CTLImg_ImgPlay'
        }

        runin = false
    }
    else
    {
        alert('Esta imagen ya est\xE1 mostrada en el visualizador.');
    }
}
//-------------------------------------
function setImgClick()
{
    if (HandlersEnabled == true)
    {
        pausePos = pos

        if (PlayPause.className != 'CTLImg_ImgPlay')
        {
            PlayPause.className='CTLImg_ImgPlay'
        }

        clearTimeout(t)
        runin = false
    }
}
//--------------------------------------

preLoadPic(j)
