/* This script will work only when button pictures adhere to following rule:
1. Name of a button picture when mouse is over (got "focus") it is created by adding "_f2" to a name of a
   picture without "focus"
2. All button pictures are gif type   
*/

var MaxSubBtn = 7;          // Max number of subbuttons on a page
var MenuOrigin              // Menu state when page loads
var MasterBtnID             // Active MasterButton (SubButtons depends on it)
var TimeOut					// Used internaly to store timer object (the time after which menu renturn to previous state)
var TimeOutSet = false      // Determine if timer is set or not 
                            // timer is set when cursor leave the button area
							// timer is canceled if mouse enters button area  
var TimeOutValue = 1000     // Amount of miliscecond after which menu returns to previous state (after leaving a button area)							
var MasterBtn               // Stores previous master button object (used to return to previous state)

 
function onLoad(args){
// Fired when page loads. Set Active button and preload images
  MenuOrigin = args
  MasterBtnID = args[0] 
  MasterBtn = args[1]
}
  
function CleanUp (){
// Fired by timer. Returns menu to original state
  return
  TimeOutSet = false
  OverMaster(MenuOrigin)
} 
 
function OverMaster(args){
// Fired when mouse pointer is over MasterButton (first row buttons)
// Changes source image for a master button and changes set of subbutton images when mouse is over that button

//  if (MasterBtnID == args[0]){ return }  // Back over the same button
  return
  MasterBtnID = args[0]
  var s =  document.getElementById(MasterBtn).src
  document.getElementById(MasterBtn).src = s.substring(0,s.length - 7) + ".gif" 
  MasterBtn = args[1]
  document.getElementById(MasterBtn).src=args[2]

  for (i=1; i<=MaxSubBtn; i++){ 
    s = args[i+2]
	document.getElementById("SubBtn" + i).src = (i<=args.length-3)?"img/btn" + s + ".gif":"img/btnempty.gif"
	document.getElementById("lSubBtn" + i).href = (i<=args.length-3)? (s.substring(s.length-3,s.length) == "_f2")?s.substring(0,s.length - 3):s + ".htm" :"" 
	document.getElementById("SubBtn" + i).width = (i<=args.length-3)?100:1
	//document.getElementById("SubBtn" + i).height = (i<=args.length-3)?36:36
  }
  document.getElementById("SubBtnEnd").width = 722 - (args.length-3)* (document.getElementById("SubBtn1").width-1)

  if (TimeOutSet == true) {
	clearTimeout(TimeOut)
	TimeOutSet = false
  }
}

function OverSlave(){
// Fired when mouse pointer is over SlaveButton (Second row buttons)
// Changes subbutton source image when mouse is over it
  var args=OverSlave.arguments;
  var s
  
  return
  //Scan through all buttons and if necessary bring them to original state
  for (i=1;i < MaxSubBtn; i++){
    s = document.getElementById("SubBtn" + i).src
	if (s.substring(s.length - 7, s.length - 4) == "_f2"){
	  document.getElementById("SubBtn" + i).src = s.substring(0, s.length - 7) + ".gif"
	}
  }  
  
  // Elevate the button on whih mouse pointer is. 
  // this depends on whih master button is selected
  // if particular master has no subbutons show Empty buton (do nothing)
  document.getElementById(args[0]).src= (MasterBtnID<args.length)?args[MasterBtnID]:"img/btnempty.gif"
  if (TimeOutSet == true) {
    clearTimeout(TimeOut)
	TimeOutSet = false
  }
}

function OutBtn (a_type, a_name){
// Sets timer that fire event that return menu into original state after predefined amount of time
// The timer is set when mouse pointer leave any button area (idle detection)

  return
  TimeOut = setTimeout("CleanUp()",TimeOutValue)
  TimeOutSet = true
}

function ClickBtn (a_name, a_image){
// Changes source image when button is clicked NOT IN USE!!!
}

