///////////////////////////////////////////////////////////////////////////////////////////////////
//  std.js
///////////////////////////////////////////////////////////////////////////////////////////////////
// Author: Co$MiXz
// Email: diabolixz@mail.com
// Website: cosmix.ods.org 
// Version: 3.2
// Date: 30/03/2000
// Short Description: Standard JavaScript for a web site.
// Comment: This code will work properly on IE and Netscape.
// Copyright: I don't mind if you use my code as long as my name remain everywhere and i still
//            get all the credit i afford for it. Please don't edit this file. Don't piss me off.
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
// HOW TO USE IT (at large)
///////////////////////////////////////////////////////////////////////////////////////////////////
// -You have to create 2 images file for each button. (Wich will be hosted at "/image/".)
// -The first one will be called "name_off.jpg" and the second one "name_on.jpg" where "name"
//  is the name of the button.
// -Moreover, in the corresponding IMG tag, you will add the property: NAME="!name" where "name"
//  is still the name of the button.
// -Your button IMG tag have to be enclosed by a <A> tag in wich you need to add the properties:
//  onMouseOver="switchOn('name')" onMouseOut="switchOff('name')"
//  where name stand for ... guess what?!? yeah, the name of the button.
// -You will need a file called "title_name.jpg" for each section.
// -The name of your title image have to be NAME="title0"
// -You have to add a form called "argv" and put an hiden field in it called "title0" wich will
//  hold the title of the current page.
// -Add, in the BODY tag, the property: onLoad="autoLoad();"
// It still look complicated? It's really not. The best way to understand it is to copy
// my source code from my website so go at http://cosmix.ods.org
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
// Global Scope Variables
///////////////////////////////////////////////////////////////////////////////////////////////////
imgVector = new Object();
titleVector = new Array();
imageBaseSrc = "/Image/";
imageType = ".jpg";
separator = "_";
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
function setDefaultSeparator(aSeparator) { //by Co$MiXz v3.2
// call this function before autoLoad() if you used a different separator than "_"
  separator = aSeparator;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setImageType(type) { //by Co$MiXz v3.2
// call this function before autoLoad() if you used a different imageType than ".jpg"
  imageType = type;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setImageBaseSrc(src) { //by Co$MiXz v3.2
// call this function before autoLoad() if your image files are not in "/image/"
  imageBaseSrc = src;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setTitle() { //by Co$MiXz v3.2
// call this function to highlight the current section button and to set the title image to 
// the corresponding section.
// ARG[0] set the level 0 title,
// ARG[1] set the level 1 subtitle, and so on ...
  var argv = setTitle.arguments;
  var argc = argv.length;
  titleVector = new Array(argc);
  for (var i=0; i<argc; i++)
  {
    var title = argv[i];
    titleVector[i] = title;
    switchOnTitle(title);
    setSrc("title" + i, imageBaseSrc + "title" + separator + title + imageType);
  }
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function isTitle(name) { //by Co$MiXz v3.2
// this function tell if name is currently a (title / subtitle) or not
  for (var i = 0; i < titleVector.length; i++) if (titleVector[i] == name) return true;
  return false;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function switchOnTitle(name) { //by Co$MiXz v3.2
// this function highlight the corresponding button if it exist
    if (document.images && document.images["!" + name]) switchOn(name);
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function getImgSrc(imgName,imgState) { //by Co$MiXz v3.2
// this function return the SRC of a preloaded image
  if (eval("imgVector." + imgName + "_" + imgState))
    return eval("imgVector." + imgName + "_" + imgState + ".src");
  else 
    return null;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setImgStateSrc(imgName,imgState,imgSrc) { //by Co$MiXz v3.2
// this function preload an image state
  eval("imgVector." + imgName + "_" + imgState + "= new Image();");
  eval("imgVector." + imgName + "_" + imgState + ".src =\"" + imgSrc + "\";");
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setImgSrc(imgName,imgSrc,aSeparator,filetype) { //by Co$MiXz v3.2
// this function preload both state of an image
  setImgStateSrc(imgName,"on",imgSrc + imgName + aSeparator + "on" + filetype);
  setImgStateSrc(imgName,"off",imgSrc + imgName + aSeparator + "off" + filetype);
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setAllImgSrc() { //by Co$MiXz v3.2
// this function load all states for all the parameter.
  var argv = setAllImgSrc.arguments;
  var argc = argv.length;
  for (var i=0; i<argc; i++) setImgSrc(argv[i],imageBaseSrc,separator,imageType);
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function setSrc(imgName,imgSrc) { //by Co$MiXz v3.2
// this function set the src of an image if that image exist
  if (document.images && document.images[imgName]) document.images[imgName].src = imgSrc;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function switchState(imgName,imgState) { //by Co$MiXz v3.2
// this function switch the src of an image to a specific state
  var imgSrc = getImgSrc(imgName,imgState);
  if (imgSrc) setSrc("!"+imgName,imgSrc);
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function switchOn(imgName) { //by Co$MiXz v3.2
// you will associate this function to the onMouseOver event
  switchState(imgName,"on");
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function switchOff(imgName) { //by Co$MiXz v3.2
// you will associate this function to the onMouseOut event
  if (!isTitle(imgName)) switchState(imgName,"off");
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function autoLoad() { //by Co$MiXz v3.2
// associate this function to the onLoad event. It's the greatest one since cause you use it, you
// don't event need to call setAllImgSrc('section1','section2',...) cause it will find all
// the images in your document begining with "!" and load em.
  if (document.images)
    for (var img in document.images)
    {
      imgName = "" + img; //Parce que Netscape est dure de la feuille. 
      if (imgName.charAt(0) == "!")
        setAllImgSrc(imgName.substring(1,imgName.length));
    }
  autoSetTitle();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
function autoSetTitle() { //by Co$MiXz v3.2
// this function load the title parameter from the page
// you need to create a form named "argv" and set some hidenfield called "title0", "title1", ...
// with the appropriate value.
  var titleList = "";
  for (var title in document.argv)
  {
    var titleString = "" + title;
    if (titleString.substring(0,5) == "title" && titleString.length > 5 && title[0] != "")
      { 
	  var titleValue = eval("document.argv."+titleString+".value");
        titleList += (titleList == "" ? "": ",") + "\"" + titleValue + "\"";
      }
  }
  eval("setTitle(" + titleList + ");");
}

///////////////////////////////////////////////////////////////////////////////////////////////////