// JavaScript Document

// Preload images
if(document.images)
{
  current_big = 'about';

  var image_array = new Array();
  // path to the directory with images
  var path = 'images/nav/';
  // enumeration of the "active" images
  image_array[0] = path + "about-over.png";
  image_array[1] = path + "sunday-over.png";
  image_array[2] = path + "serving-over.png";
  image_array[3] = path + "family-over.png";
  image_array[4] = path + "about.png";
  image_array[5] = path + "sunday-on.png";
  image_array[6] = path + "serving-on.png";
  image_array[7] = path + "family-on.png";
  var preload_image = new Array ();
  for(var i=0; i<image_array.length; i++)
  {
    preload_image[i]= new Image();
    preload_image[i].src = image_array[i];
  }
}

start_menu_timer();

// Start image rotation timer
function start_menu_timer()
{
  timer = setInterval("time_swap()",7000);  // 7000 = 7 seconds
}

// Stop image rotation timer
function stop_menu_timer()
{
  clearInterval(timer);
}

// Rollover top menu items
function rollover(name, filename)
{
  if (name != current_big)
    {
    var fullpath = 'images/nav/' + filename;
    document.images[name].src = fullpath;
	}
}

// Click on top menu items
function manual_swap(name, filename)
{
  stop_menu_timer();
  start_menu_timer();
  swap_big(name, filename);
}

// Swap big menu
function swap_big(name, submenu)
{
  document.getElementById("sub-menu-1").style.display = "none";
  document.getElementById("sub-menu-2").style.display = "none";
  document.getElementById("sub-menu-3").style.display = "none";
  document.getElementById("sub-menu-4").style.display = "none";
  document.getElementById(submenu).style.display = "block";

  current_big = name;
    
  document.images["about"].src = "images/nav/about.png";
  document.images["sunday"].src = "images/nav/sunday.png";
  document.images["serving"].src = "images/nav/serving.png";
  document.images["family"].src = "images/nav/family.png";

  var fullpath = 'images/nav/' + name + '-on.png';
  document.images[name].src = fullpath;
}

// Rotate images
function time_swap()
{
  if (current_big == "about") {
    swap_big('sunday','sub-menu-2');
  }
  else if (current_big == "sunday") {
	swap_big('serving','sub-menu-3');
  }
  else if (current_big == "serving") {
	swap_big('family','sub-menu-4');
  }
  else if (current_big == "family") { 
	swap_big('about','sub-menu-1');
  }
}
