/*
 * $Id: waw.js,v 1.11 2002/05/30 06:59:45 christo Exp $
 * main javascript file for Wild About Wetlands
 * developed by chris@think.net.au
 * Think Internet Consulting think.net.au
 * copyright 2002 All Rights Reserved
 */

/* global associative arrays to hold the rollover images */
var myOnImages = new Object();
var myOffImages = new Object();
var myDescImages = new Object();

/*
 * This primes the rollovers in the document, preloading images into the
 * holder provided. This is an object, or associative array (hash) key clashes
 * may produce undesired effects, so try to make sure the imageNames array
 * elemnets are all unique.
 *
 * Image names would usually correspond to the base names of the files, it is
 * followed by the suffix parameter (usually _on.gif or _off.jpeg etc).
 * 
 * baseNames     is an array of <img> element names
 * prefix        added before (used for specifying a subdirectory or
 * URL fragment
 * suffix is the string added after the on state and off state suffixes in
 * order to form the complete URL
 * 
 */
function primeRollovers(holder, prefix, baseNames, suffix) {
   var imgName;
   for (var i=0; i<baseNames.length; i++) { 
      imgName = baseNames[i];
      holder[imgName] = new Image();
      holder[imgName].src = prefix + imgName + suffix;
   }
}

/*
   turns the menu image to the on state for the given base image name
   and set the the section description image correspondingly
*/
function menuOn(imgName) {
   var buttonImage, descImage;
   if (_IMTOOL) {
      // turn on button
      buttonImage = _IMTOOL.getImageByName("b_" + imgName);
      if (buttonImage != null) {
         buttonImage.src = myOnImages[imgName].src;
      }
      // set appropriate description image
      descImage = _IMTOOL.getImageByName("section-description");
      if (descImage != null) {
         descImage.src = myDescImages[imgName].src;
      }
   } 
}

/*
   turns the menu image to the off state and returns the section description 
   to the current section setting.
*/
function menuOff(imgName) {
   var buttonImage, descImage;
   if (_IMTOOL) {
      if(imgName != _CURRENT_SECTION) {
         // turn off button 
         buttonImage = _IMTOOL.getImageByName("b_" + imgName);
         if (buttonImage != null) {
            buttonImage.src = myOffImages[imgName].src;
         }
      } 
      // reset description image
      descImage = _IMTOOL.getImageByName("section-description");
      if (descImage != null) {
         descImage.src = myDescImages[_CURRENT_SECTION].src;
      }
   }
}

function syncMenu() {
   //TODO: handle submenu synchronisation here.
   _IMTOOL = new ImTool();
   menuOn(_CURRENT_SECTION);
   
}

function setSection(current_section, current_subsection) { 
   //TODO: parameter checking against the section array in _rollover_images
   _CURRENT_SECTION = current_section;
   CURRENT_SUBSECTION = current_subsection;
   syncMenu();
}

/* opens the about window */
function openAbout() {
   aboutWin = window.open("about.html", "about", "width=450,height=500,resizable,scrollbars");
   aboutWin.focus();
}

/* opens an undecorated popup big enough for the image referenced by the parameters */
function popupImage(url, width, height) { 
   var widthBuffer = 30;
   var heightBuffer = 30;
   var winoptions = "width=" + (widthBuffer + width) 
                  + ",height=" + (heightBuffer + height)
                  + ",scrollable,resizable";
   var w = window.open(url, "imwin", winoptions);
}


var _rollover_images = new Array("latest_news",
                                 "the_place",
                                 "living_things",
                                 "heroes",
                                 "forum",
                                 "hop_in_and_help",
                                 "digging_deeper",
                                 "teachers");

primeRollovers(myOnImages, "images/b_", _rollover_images, "_on.gif");
primeRollovers(myOffImages, "images/b_", _rollover_images, "_off.gif");
primeRollovers(myDescImages, "images/desc_", _rollover_images, ".gif");

/*
 * PRIVATE GLOBALS
 * The setSection() function should be called as soon as possible once
 * the correct section name is known.
 */
var _IMTOOL, _CURRENT_SECTION, _CURRENT_SUBSECTION;


// end
