﻿/************************************** Splendid *************************************
 * Creation Date:	3rd July 2007 2007
 * Edited ----------------------------------------------------------------------------
 *		By:	    On:
 * Description -----------------------------------------------------------------------
 *		This file contains the functions for creating the image slideshow/forward/back
 *
 *      Called by html page
 *          preLoadImages()
 *          checkLoaded( imgSrc )
 *          showSlideshowImage( i )
 *          showGalleryView()
 *          showSlideshowView()
 *          runSlidehow()
 *          stopSlideshow()
 *          slideshowNext()
 *          slideshowPrev()
 *          changeImage()
 *
 **************************************************************************************/

/********************************** Global Variables *********************************/
// Speed in milliseconds
var fadeSpeed = 1500;

var preLoad = new Array();
var t;
var j = 0;

/********************************** Public Functions *********************************/

/****
 * Preloads the images in the array so that they're there to use when needed.
 * Image data in imageDataDiv as innerHTML 
 * (<image src>:<image alt>|<image src>:<image alt>)
 ****/
function preLoadImages()
{
    var p = Pic.length;
    
    for (i=0; i<p; i++)
    {
        preLoad[i] = new Image();
        preLoad[i].src = Pic[i].src;
        preLoad[i].alt = Pic[i].alt;
    }

    changeImage();
    document.getElementById('imgP').style.display = 'block';
    document.getElementById('txtP').style.display = 'none';
}

/****
 * Changes to the next image in the imaes array
 ****/
function slideshowPrev()
{
    j = parseInt(j-1);
    if( j < 0 )
        j=parseInt((preLoad.length-1));

   $('#ctl00_ContentPlaceHolder1_slideshowImage').animate({
        opacity: 'hide'
        }, fadeSpeed, 'backinout', changeImage);
}

/****
 * Changes to the previous image in the images array
 ****/
function slideshowNext()
{
    j = parseInt(j+1);

    if( parseInt(j) > parseInt(preLoad.length-1) )
        j=0;

    $('#ctl00_ContentPlaceHolder1_slideshowImage').animate({
        opacity: 'hide'
        }, fadeSpeed, 'backinout', changeImage);

}

/****
 * Function to change the image over
 ****/
function changeImage()
{
    try
    {
        document.getElementById('ctl00_ContentPlaceHolder1_slideshowImage').src = preLoad[j].src;
        document.getElementById('ctl00_ContentPlaceHolder1_slideshowImage').alt = preLoad[j].alt;
        updateNumber();
        $('#ctl00_ContentPlaceHolder1_slideshowImage').animate({
            opacity: 'show'
            }, fadeSpeed, 'backinout');
    } catch(e){}
}

function updateNumber()
{
    document.getElementById('imageNavNum').innerHTML = parseInt(j+1);
}
