// ---------------------------------------------------------------
// Scripts to fade cube photos in and out on a timer.
//
// Created: 11/03/2007 kaw
// ---------------------------------------------------------------

    var currentPhotoNum = 1;
    var maxPhotos = 5;
    var timeoutInterval = 8000;	// 8 seconds between Photos; override in onload call
    var fadeInterval = 3000;	// 3 second to fade-in or out

    function startTimer(mSec)
    {
      timeoutInterval = mSec;
      Id = window.setTimeout("changePhoto();", timeoutInterval);
    }

    function changePhoto()
    {
      var lastPhoto = "imgPhotoCube" + currentPhotoNum;
      currentPhotoNum += 1;
      if (currentPhotoNum > maxPhotos)
        currentPhotoNum = 1;
      var newPhoto = "imgPhotoCube" + currentPhotoNum;
      //alert("changing Photo from " + lastPhoto + " to " + newPhoto);

      opacity(lastPhoto, 100, 0, fadeInterval); 
      opacity(newPhoto, 0, 100, fadeInterval); 

      Id = window.setTimeout("changePhoto();", timeoutInterval);
    }

    // -------------------------------------------------------------------
    // credit where credit is due:
    //     fade-in/fade-out scripts from site owner (name unknown) at
    //     http://www.brainerror.net/scripts_js_blendtrans.php
    //		in early 2006
    // -------------------------------------------------------------------

    function opacity(id, opacStart, opacEnd, millisec)
    { 
      //speed for each frame 
      var speed = Math.round(millisec / 100); 
      var timer = 0; 

      //alert("opacity called with: " + id +", " + opacStart + ", " + opacEnd + ", " + millisec);

      //determine the direction for the blending, if start and end are the same nothing happens 
      if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
      } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
      } 
    } 

    //change the opacity for different browsers 
    function changeOpac(opacity, id)
    { 
      var objectStyle = document.getElementById(id).style; 
      objectStyle.opacity = (opacity / 100); 
      objectStyle.MozOpacity = (opacity / 100); 
      objectStyle.KhtmlOpacity = (opacity / 100); 
      objectStyle.filter = "alpha(opacity=" + opacity + ")"; 
    } 

// --- end of script file (photocube.js) ---
