﻿// JScript File
// var picArray = new Array();
// var altArray = new Array();

// 'whatToSeeAndDo.jpg', 'whereToDineAndShop.jpg', 'whereToStay.jpg');

// var nextArrayIndex = 1;
// var imageID = '';

function startRotation(picArray, altArray, imageID, startImageNum)
{
    
	voidCallbackFunction = function() {};
	startRotationWithCallback(picArray, altArray, imageID, startImageNum, voidCallbackFunction);

}

function startRotationWithCallback(picArray, altArray, imageID, startImageNum, callbackFunction)
{
	
	/*
		picArray = imageSRCArray;
		altArray = imageAltArray;
		imageID = theImageID;
		*/
		
		if (startImageNum == picArray.length - 1)
			nextArrayIndex = 0;
		else
			nextArrayIndex = startImageNum + 1;
		
        // preload images
        picImageArray = new Array();
                
        for (i = 0; i < picArray.length; i++)
        {
            picImageArray[0] = new Image(285, 380);
            picImageArray[0].src = picArray[i];
        }
        
        // start the rotation;
		document["nextFunction_" + imageID] = function() { rotateImage(picArray, altArray, imageID, nextArrayIndex, callbackFunction); };
        // setTimeout("rotateImage(picArray, altArray, imageID, nextArrayIndex)", 5000);
		setTimeout(document['nextFunction_' + imageID], 5000);
	
}

function rotateImage(picArray, altArray, imageID, nextArrayIndex, callbackFunction)
{
	
	// alert("RI: " + alertMsg);
	
    // Fade the image out
    new Rico.Effect.FadeTo( document.getElementById(imageID), 0.0, 1000, 10, {complete:function() { rotateImage2(picArray, altArray, imageID, nextArrayIndex, callbackFunction);}} );
    
    // setTimeout("rotateImage2()", 1050);

}

function rotateImage2(picArray, altArray, imageID, nextArrayIndex, callbackFunction)
{
    	
	// alert("RI2: " + alertMsg);

	nextFunction = function() { rotateImage3(picArray, altArray, imageID, nextArrayIndex, callbackFunction); };
	document.getElementById(imageID).onload = nextFunction;
    document.getElementById(imageID).src = picArray[nextArrayIndex];
	
	
// 	alert('Set alt tag to ' + altArray[nextArrayIndex]);
    
    // setTimeout("rotateImage3()", 100);
    
}

function rotateImage3(picArray, altArray, imageID, nextArrayIndex, callbackFunction)
{
	
	// alert("RI3: " + alertMsg);
	// Set alt tag
	document.getElementById(imageID).alt = altArray[nextArrayIndex];
	document.getElementById(imageID).title = altArray[nextArrayIndex];
	
	callbackFunction();
	
    // Fade the image in
    new Rico.Effect.FadeTo( document.getElementById(imageID), 1.0, 1000, 10, {} );
    
    if (nextArrayIndex == picArray.length - 1)
        nextArrayIndex = 0;
    else
        nextArrayIndex++;
      
	document["nextFunction_" + imageID] = function() { rotateImage(picArray, altArray, imageID, nextArrayIndex, callbackFunction); };
  	// setTimeout("rotateImage(picArray, altArray, imageID, nextArrayIndex)", 6000);
	setTimeout(document['nextFunction_' + imageID], 6000);
		
    
}
