//  Menu Switcher with Text Changing
//	Creator: Daniel Schindler
//	--------------------------------------------------
//	Copyright © 2003-2005 webagentur logic-code
//	Design by webagentur logic-code
//	www.logic-code.de
//	--------------------------------------------------
//	Please don't use our work without permission, ask 
//	first.
//--------------------------------------------------
//
//  Place onload="load" into body
//  Place onMouseOver="on('name of layer','text')" into an image
//  Place onMouseOut="off()" into an image
//
//  global:
//  files and html-elements should have the same name
//  naming files: inactive - name of image + extension (ex. menu_home.png) 
//                active - name of image + act_ident + extension (ex. menu_home_act.png)
//  naming menu elements: name of file without extension
//  naming text display area: ident_text
//
//  function load:
//  set name to image filename without extension 
//  set text to an description for menu item
//


pics		= new Array();	//array for buttons informations
count		= 0;		//count of loaded images
file_ext	= ".gif";	//extension used for files
ident_act	= "_act";	//suffix for active menu items
ident_text	= "hdr_text";	//identifier for text item (unset if you don't use displaying text)
use_alt_text	= 1;		//if use_alt_text = 1 then use alt for text

function init_menu() {
  var id = 0;
  var m_no_js = document.getElementById(init_menu.arguments[0]);
  var m_js = document.getElementById(init_menu.arguments[1]);
  // load images into cache at page load
  for (id = 2; id < init_menu.arguments.length; id++) {
    on(init_menu.arguments[id]);
  }
  off();
   
  //switch from non_js menu to js_menu
  m_no_js.style.visibility = "hidden";
  m_js.style.visibility = "visible";
}

function on(name,text) {
  var i = 0;
  // reset first all menu images
  off();
  
  if (document.images) {
    var found = -1;
    
    // check if image is already in array
    for (i = 0; i < count; i++) {
      if (pics[i][0] == name){found = i;}
    }
    
    // add image into array if not found
    if (found == -1) {
      pics[count]		= new Array(5);
      pics[count][0]		= name;
      pics[count][1]		= text;
      pics[count][2]		= document.images[name].src;
      pics[count][3]		= new Image;
      
      //if no text is given and use_text 
      if (!text && use_alt_text) {
        pics[count][1]		= document.images[name].alt;
      }
      
      // get path for image
      if (pics[count][2].lastIndexOf('/')>-1){
        path = pics[count][2].substring(0,pics[count][2].lastIndexOf('/')+1);
      }
      {pics[count][3].src	= path + name + ident_act + file_ext;}
      
      //set index of new item and count items up
      found = count; 
      count++; 
    }
    
    // if requested image exists
    if (found != -1) {
      // set active image
      document.images[name].src	= pics[found][3].src;
      //set text for element
      if (ident_text) {
      	var o=document.getElementById(ident_text);
      	o.innerHTML = pics[found][1];
      }
      // mark image as active
      pics[found][4]		= 1;
    }
  }
}

function off() {
  var i = 0;
  if (document.images) {
    for (i = 0; i < count; i++) {
      if (pics[i][4] == 1) {
        document.images[pics[i][0]].src = pics[i][2];
        pics[i][4] = 0;
      }
    }
  }
  if (ident_text) {
    var o=document.getElementById(ident_text);
      	o.innerHTML = "";
  }
}
