// NOTE:  you must have the following:
//
//	1. an image tag named "ImageContainer":
//		<img name="ImageContainer" src="dummy.jpg" />
//	2. <body onload="runImages()">
//
// the lower the ImagesSpeed the faster the images change (seems like 1000 = 1 second)

var ImagesSpeed = 4000;
var crossFadeDuration = 3;
var timeOut;

// load the Product Video images for morphing
var imgPV;
var currPVImgIdx = 0;
var picLocationPV = new Array();
picLocationPV[0] = 'Images/misc/tv_1.jpg';
picLocationPV[1] = 'Images/misc/tv_2.jpg';
imgPV = CreateImageArray(picLocationPV);

// load the SNN images for morphing
var imgSNN;
var currSNNImgIdx = 0;
var picLocationSNN = new Array();
picLocationSNN[0] = 'Images/PicsLogos/logo_snn6_83.gif';
picLocationSNN[1] = 'Images/Misc/logo_liveon83.jpg';
imgSNN = CreateImageArray(picLocationSNN);


// load the XFactor images for morphing
var imgXFactor;
var currXFactorImgIdx = 0;
var picLocationXFactor = new Array();
picLocationXFactor[0] = 'Images/PicsLogos/XFactor_dark_80.jpg';
picLocationXFactor[1] = 'Images/PicsLogos/XFactor_80.jpg';
imgXFactor = CreateImageArray(picLocationXFactor);


// Once everything is loaded in terms of images this function is called from the
// onLoad event within the body tag
function runImages()
{
	   currPVImgIdx = (currPVImgIdx > (imgPV.length - 1)) ? 0 : currPVImgIdx;
    currSNNImgIdx = (currSNNImgIdx > (imgSNN.length - 1)) ? 0 : currSNNImgIdx;
    currXFactorImgIdx = (currXFactorImgIdx > (imgXFactor.length - 1)) ? 0 : currXFactorImgIdx;
    
    MorphImages('ImageContainerPV', imgPV, currPVImgIdx);
    MorphImages('ImageContainer', imgSNN, currSNNImgIdx);
    MorphImages('ImageContainerXFactor', imgXFactor, currXFactorImgIdx);
    
    currPVImgIdx++;
    currSNNImgIdx++;
    currXFactorImgIdx++;
    
    timeOut = setTimeout('runImages()', ImagesSpeed);
}


// This kicks off the morphing for the image container and set of images that are
// created for it
function MorphImages(imageContainer, imgArray, currIdx)
{
   if (document.all)
   {
      eval('document.images.' + imageContainer).style.filter="blendTrans(duration=2)";
      eval('document.images.' + imageContainer).style.filter="blendTrans(duration=crossFadeDuration)";
      eval('document.images.' + imageContainer).filters.blendTrans.Apply();
   }
   
   eval('document.images.' + imageContainer).src = imgArray[currIdx].src;
   
   if (document.all)
   {
      eval('document.images.' + imageContainer).filters.blendTrans.Play();
   }   
}

// Create an Image array from an array of image locations
function CreateImageArray(imgLocation)
{    
    retImages = new Array();
    for (i = 0; i < imgLocation.length; i++)
    {
       retImages[i] = new Image();
       retImages[i].src = imgLocation[i];
    }
    
    return(retImages);
}