// Banner_Rotate.js
// This file randomly changes the site's banner at regular intervals
// with a cross-fade effect.  The image rotation script is original
// but the actual cross-fade effect was graciously provided by a 
// programmer by the name of Brothercake - http://www.brothercake.com/

// Configurable settings
var _min = 1; // Minium image number (format : imageX.jpg where X = _min)
var _max = 7; // Maximum image number (format : imageX..jpg where X = _max)
var _rotate_duration = 5000; // Number of milliseconds between banners
var _fade_duration = 2; // Number of seconds for the actual cross-fade
var _image_path = 'banner/'; // The path (relative to the the php/html file) of the banner folder
var _banner_id = 'bannerimage'; // The ID for the banner image <img id="?" />

// Global variables
var _t;
var _firstload = true;
var _image;
var _newimagesource;
var _rand;

// This function starts the actual banner timer
function start_banner_rotation()
{
	_t = setTimeout("start_banner_rotation()", _rotate_duration);
	if (_firstload == true) { _firstload = false; }
  else { rotate_banner(); }
}

function stop_banner_rotation()
{
	clearTimeout(_t);
}

// This function does the actual image transition
function rotate_banner()
{
  // Define the objects we'll be using
  _image = document.getElementById(_banner_id);
  // Generate a random number and the new image source
  _rand = Math.floor((_max - (_min - 1)) * Math.random()) + _min;
  _newimagesource = _image_path+'image'+_rand+'.jpg';
  // Check if the new image is actually new - if so replace the current one
  if (_image.src.search(_image_path+'image'+_rand) == -1)
  {
    // Start the cross-fade effect
	crossfade(_image, _newimagesource, _fade_duration);
  }
  // Otherwise, recursively call this function again
  else
  {
    // Recursively call this script again (to try for a new random number)
	rotate_banner();
    return false;
  }
}
