/******************************************************************************/
/*                                                                            */
/* GENERAL INFORMATION                                                        */
/*                                                                            */
/* kx_content - Page Content Routines                                         */
/*                                                                            */
/* (C) Copyright 2004, Keropac Computing.  All rights reserved.               */
/*                                                                            */
/* Provides various content uppdate routines.                                 */
/*                                                                            */
/* By default the previous element is not hidden before a new element is      */
/* shown, elements do not slide in and out and the speed is set to 7, and     */
/* the initial content is not shown.  Use he setContentOptions function as    */
/* part of the onLoad of the page to change the previous element setting and  */
/* the sliding option.  The first two parameters are boolean, i.e. true or    */
/* false.  The next is a value between 1 and 10, 1 for slow and 10 for very   */
/* fast and the final is also bollean.  If used, this function must be called */
/* before anything else.                                                      */
/*                                                                            */
/* The getContentElements function should be run as part of the onLoad of the */
/* page.  It requires one parameter, a filter for retrieving the names  of    */
/* elements on the page, a "*" will retrieve the names of all elements.       */
/*                                                                            */
/* The contentToggleAll function requires one parameter, "hide" to hide all   */
/* elements or "show" to show all elements.                                   */
/*                                                                            */
/* The contentToggle function requires one parameter, the name of the element.*/
/* element.  If the element can currently be seen, it will be hidden, and     */ 
/* vice versa.                                                                */
/*                                                                            */
/* MODIFICATIONS                                                              */
/*                                                                            */
/* Ref.  By    Date    Description                                            */
/* ----  --    ----    -----------                                            */
/* @nnn  xx  dd/mm/yy  XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX */
/*                     XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX */
/*                     XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX */
/*                                                                            */
/******************************************************************************/

<!-- Begin

var contentSize = new Array();
var previousElement = "";
var hidePrevious = false;
var slideDisplay = false;
var initialHide = false;
var slideWait = 10;
var slidePixels = 4;
var actualHeight = 0;
var targetHeight = 0;
var currentElem = "";
var nextElem = "";
var minHeight = 0;

// ---------------------------------------------------------------------------
// Gett names of elements, filtered using the filter.
// ---------------------------------------------------------------------------

function getContentElements(filter)

{
  var allElements = document.all ? document.all : document.getElementsByTagName("*")

  for (var i=0; i<allElements.length; i++)
  {
    if (typeof allElements[i].id == "string" && allElements[i].id.indexOf(filter) != -1)
    {
      currentId = allElements[i].id;
      contentSize[currentId] = getElementHeight(getElement(currentId));

      getElement(currentId).style.overflow="hidden";
      
      // If selected, initially hide the element.

      if (initialHide)
      {
        getElement(currentId).style.height = minHeight + bwPX;
        nonDisplayElement(getElement(currentId));
      }      
    }
  }
}

// ---------------------------------------------------------------------------
// Toggle state of one specified element.
// ---------------------------------------------------------------------------

function contentToggle(elem)

{
  // Do we need to show or hide the element.
  
  if (getElementHeight(getElement(elem)) == minHeight)
  {
    // Hide previous element, then show selected element.

    if (hidePrevious && elem != previousElement)
    {
      if (previousElement != "")
      {
        contentHideElement(previousElement);
        nextElem = elem;
      }
      previousElement = elem;
    }
    
    // Show selected element.

    if (nextElem == "")
    {
      contentShowElement(elem);
    }
  }

  // Hide selected element.

  else
  {
    contentHideElement(elem);
  }

}

// ---------------------------------------------------------------------------
// Hide element by sliding it out.
// ---------------------------------------------------------------------------

function contentHideElement(elem)

{
  // Element name, actual height and target height.
  
  currentElem = elem; 
  actualHeight = getElementHeight(getElement(elem));
  targetHeight = minHeight;
  
  // Hide element.
  
  setTimeout("toggleElement()", slideWait);
}

// ---------------------------------------------------------------------------
// Show element by sliding it in.
// ---------------------------------------------------------------------------

function contentShowElement(elem)

{
  // Element name, actual height and target height.

  currentElem = elem; 
  actualHeight = minHeight;
  targetHeight = contentSize[elem];
  
  // Show element before increasing it's size.
    
  displayElement(getElement(currentElem));

  // Show element.
  
  setTimeout("toggleElement()", slideWait);
}

// ---------------------------------------------------------------------------
// Toggle element by sliding it out or in.
// ---------------------------------------------------------------------------

function toggleElement()

{
  // No sliding.

  if (!slideDisplay)
  {
    actualHeight = targetHeight;
  }
  
  // Slide element out.
  
  else if (actualHeight > targetHeight)
  {
    actualHeight -=  slidePixels;
    if (actualHeight < targetHeight)
      actualHeight = targetHeight;
  }
  
  // Slide element in.
  
  else if (actualHeight <= targetHeight)
  {
    actualHeight += slidePixels;
    if (actualHeight > targetHeight)
      actualHeight = targetHeight;
  }

  // Set new height.
    
  getElement(currentElem).style.height = actualHeight + bwPX;

  // Hide element if the size is now zero.

  if (actualHeight == 0)  
  {  
    nonDisplayElement(getElement(currentElem));
  }

  // Check if we have finished, if not keep going.
          
  if (actualHeight != targetHeight)
    setTimeout("toggleElement()", slideWait);
    
  // Finished this element, is there a different one to show.
  
  if (actualHeight == targetHeight && nextElem != "")
  {
    currentElem = nextElem;
    nextElem = "";
    contentShowElement(currentElem);
  }
}

// ---------------------------------------------------------------------------
// Set the previous element and slide content options.
// ---------------------------------------------------------------------------

function setContentOptions(hide, slide, speed, initHide)

{
  // Hide previous selection.
  
  hidePrevious = hide;
  
  // Slide content in and out.
  
  slideDisplay = slide;
  
  // Speed of sliding (1 = Slow, 10 = Very Fast)
  
  if (speed == 1) { slideWait = 50; slidePixels = 1; }
	if (speed == 2) { slideWait = 30; slidePixels = 1; }
	if (speed == 3) { slideWait = 20; slidePixels = 1; }
	if (speed == 4) { slideWait = 15; slidePixels = 1; }
	if (speed == 5) { slideWait = 10; slidePixels = 1; }
	if (speed == 6) { slideWait = 10; slidePixels = 2; }
	if (speed == 7) { slideWait = 10; slidePixels = 4; }
	if (speed == 8) { slideWait = 10; slidePixels = 7; }
	if (speed == 9) { slideWait = 10; slidePixels = 11; }
	if (speed == 10) { slideWait = 10; slidePixels = 16; }

  // Initially hide the content.
  
  initialHide = initHide;
}

// End -->
