
var GLOBAL_PHOTOGAL_TIMEOUT = 5000;
var GLOBAL_PHOTOGAL_ON_FLAG = false;
var GLOBAL_FADE_IN_PERCENTAGE = 25;
var GLOBAL_FADE_IN_MILLISECONDS_INTERVAL = 100;

// Function loads given image number and its caption.
function loadImage(sImgNo, bTurnOffAutoGallery)
{
    var sImgPath = BASE_IMAGES_DIR + sImgNo + IMAGES_SUFFIX;
    var oThePhotoImg = document.getElementById(THE_PHOTO_IMG_ID);
    var oThePhotoCaption = document.getElementById(THE_PHOTO_CAPTION_ID); 
    var sCaption = arrayCaptions[sImgNo-1];   
    if (oThePhotoImg != null)
    {
        // Use the photo image's img object 
        // and reset it's opacity to 0%.
        setOpacity(oThePhotoImg, 0);
        
        // Then, update the phot image's img object
        // to refer to the source path for the new
        // image being loaded.
        oThePhotoImg.src = sImgPath;

        // Use the photo image's img object 
        // and reset it's opacity to 0% again.
        setOpacity(oThePhotoImg, 0);
        
        // Finally, set up the fade in effect
        // via the browser's event handler.
        fadeIntoFullOpacity(THE_PHOTO_IMG_ID, 0);
    }
	
	if (oThePhotoCaption != null)
	{
        oThePhotoCaption.innerText = sCaption;	
	}
    
    // Turn off the Auto Play Gallery if directed to do so.
    if (bTurnOffAutoGallery)
    {
        GLOBAL_CURRENT_PHOTO = 0;    
        turnOffAutoGalImg();                      
        GLOBAL_PHOTOGAL_ON_FLAG = false;          
    }
    
    return;    
}

function autoPlayPhotoGal()
{
    if (GLOBAL_PHOTOGAL_ON_FLAG)
    {
        // Turn off the gallery.
        GLOBAL_CURRENT_PHOTO = 0;    
        turnOffAutoGalImg();                      
        GLOBAL_PHOTOGAL_ON_FLAG = false;          
    }
    else if (!GLOBAL_PHOTOGAL_ON_FLAG)
    {
        // Turn on the gallery.
        GLOBAL_CURRENT_PHOTO = 0;        
        turnOnAutoGalImg();              
        GLOBAL_PHOTOGAL_ON_FLAG = true;                      
        nextPhoto();                
    }  
}

function nextPhoto()
{
    if (GLOBAL_CURRENT_PHOTO < GLOBAL_MAX_NO_PHOTOS)
    {
        // Only cycle to the next photo if the auto gallery is still on.
        if (GLOBAL_PHOTOGAL_ON_FLAG)
        {
            GLOBAL_CURRENT_PHOTO++;
            loadImage(GLOBAL_CURRENT_PHOTO,false);
            setTimeout('nextPhoto()',GLOBAL_PHOTOGAL_TIMEOUT);  
        }
    }
    else if (GLOBAL_CURRENT_PHOTO == GLOBAL_MAX_NO_PHOTOS)
    {
        // When reaching the last photo, reset and reload the first photo.
        // Then, turn off the photo gallery.
        GLOBAL_CURRENT_PHOTO=1;
        loadImage(GLOBAL_CURRENT_PHOTO,true);
    }    
}

function turnOnAutoGalImg()
{
    var oTheImg = document.getElementById(THE_AUTO_PLAY_IMG_ID);  
    if (oTheImg != null)
    {
        oTheImg.src = THE_AUTO_PLAY_IMG_PATH_ON;   
    }   
}

function turnOffAutoGalImg()
{
    var oTheImg = document.getElementById(THE_AUTO_PLAY_IMG_ID);  
    if (oTheImg != null)
    {
        oTheImg.src = THE_AUTO_PLAY_IMG_PATH_OFF;   
    }   
}


function doNothing()
{
	return;
}

function hideShowLayer(sLayerName)
{
    var oDivObject = document.getElementById(sLayerName);
    var sDisplayVal = oDivObject.style.display;
    if (sDisplayVal == 'none')
    {
        oDivObject.style.display = 'block';
    }
	else
	{
        oDivObject.style.display = 'none';	
	}

	return;
}

function fadeIntoFullOpacity(sTheImageObjectId, iStartingOpacityVal)
{
    if (sTheImageObjectId != null)
    {
        if (iStartingOpacityVal <= 100)
        {
            var oTheImageObject = document.getElementById(sTheImageObjectId);            
            if (oTheImageObject == null)
                return;
            
            // Initialize the image's opacity to the given value.
            setOpacity(oTheImageObject, iStartingOpacityVal);
            
            // Increment the opacity by 10%
            iStartingOpacityVal += GLOBAL_FADE_IN_PERCENTAGE;
            
            // Set onto the page's event handler, 
            // the fadeIntoFullOpacity() method
            // to let this event handler automatically
            // call this method every 100 milliseconds
            // until the opacity is at 100%.
            window.setTimeout("fadeIntoFullOpacity('" + sTheImageObjectId + "', " +  iStartingOpacityVal + ")", GLOBAL_FADE_IN_MILLISECONDS_INTERVAL);      
        }
    }
}

function setOpacity(oTheImageObject, iOpacityValue)
{
    var opacity = (iOpacityValue == 100)?99.999:iOpacityValue;
    
    if (oTheImageObject != null)
    {
        var sOpacityStyle = "alpha(opacity:" + opacity + ")";
        
        // Handle MSIE Browsers
        oTheImageObject.style.filter = sOpacityStyle;
        
        // Handle Older Mozilla/FireFox
        oTheImageObject.style.MozOpacity =  opacity/100;  
    }
}



