/*---------------------------------------------------------------
| Author      : Mollink.com, Margré Mollink
| Filename    : pilot.js
| Description : Guides the pages through the menu frame
| Created     : 2000-06-15
| HISTORY
| 2000-09-04 Changes because of new directories. Every room now
|   has it's own directory with an index file building the frames.
|   Changed code of OnClickRoom, because onClick replaces the
|   entire window with frames from the index file.
| 2000-10-03 Changed code OnClickRoom back to old code, because
|   replacing the entire window makes things too complex (and it's
|   slow). Now index files should only be called when a fContent
|   fContent page is orphaned (see setframes.js).
|   More location changes: moved general files (like dummy, title)
|   to Home/ and moved description files to their room's dir.
|   Added this.dir, reset room colours to new colour scheme.
| 2000-10-04 Polishing.
| 2000-12-05 Archive room (2) added to Studio (3).
| 2001-01-03 Renumbered rooms. Now Reception=1, Lounge=2, Hall=3,
|   Library=4, Studio=5. Also made the rooms smaller (we now only
|   have 5). Colours unchanged (so Studio still red).
| 2001-01-07 New colours for rooms: Reception=yellow,
|   Lounge=Lilac, Hall=red, Library=brown, studio=green.
| 2001-01-14 Moved files from Home/ to include/.
|   Only construction.html remains in Home/.
| 2001-01-24 Moved menu.html to Home/. As a consequense, changed
|   img.scr to "../images/xxx.gif" (was "images/xxx.gif").
|   That way menu images are referred to with the same relative
|   path from both Home/menu.html and Reception/reception.html
|   (because reception calls EnterRoom(x) which changes the room
|   image to xx_on.gif). Also change this.dir and sMenuPage to
|   relative path (add '..\\').
|   New function EnterRoom(x) which changes the menu image and
|   colours the sidebar. N.B. First leave the current room
|   before entering the new room.
|   Replace <BODY> tag by
|   <BODY onload:"JavaScript:LeaveRoom(-1);EnterRoom(N);">
|   where -1 indicates unknown room, and N the number of the 
|   room you want to enter.
|   for the opening page of so every room. That way the menu and
|   sidebar are also changed when the "text menu" at the bottom
|   of the content page is used (instead of the graphical menu
|   in the fMenu frame).
| 2001-02-20 Moved \include\dummy.html to \Home\dummy.html, so
|   \include\ doesn't need to be published any more.
| 2001-06-01 sMenuPage is the default page (menu instructions)
|   for the fDesc frame. It replaces sDummyPage (fDesc only!).
| 2001-07-09 Initialisation code in seperate file (pilot-init.js)
|   Includes definition of global variabeles for pilot.
| 2001-07-15 New <BODY onload="Start()" onunload="Stop()">
|   Start contains call to new SetFrames(), Stop = LeaveRoom().
|   Also replace reference to variables defined in pilot-init.js
|   with parent.fMenu.<var> and include pilot-init only in fMenu
|   page (=Home/menu.html). Main pages for every room include
|   setframes.js and pilot.js.
|   Since iCurrentRoom is global, it can be referred to as
|   parent.fMenu.iCurrentRoom ==> LeaveRoom(-1) unnecessary !!
\--------------------------------------------------------------*/
//----> BEGIN MAIN --------------------------------------------->
//<---- END MAIN <---------------------------------------------//

//--->> BEGIN FUNCTIONS >>------------------------------------->>
//Variables used in functions: (see pilot-init.js)
//sText - text string
//sImgID - ID of the named image (room) to be replaced
//sRoomName - (part of) prefix of filename containing the description text
//iRoomNr - index in array of rooms
//imgObj - the name of the image object (= preloaded images)

//--->> Set menu and show description >>----------------------->>
function onMouseOverRoom(iRoomNr)
{
  var sTargetFrame = 'fDesc';
  var sTargetLocation = 'unknown';

//window.alert("onMouseOverRoom " + iRoomNr);
  if (iRoomNr > 0 && iRoomNr <= iMaxRoom)
  {
	document.cursor='hand';		//set cursor
	ChangeImg(iRoomNr,1);		//colour the room
	//display a description in the 'fDesc' frame and a text on the statusbar
	//Description text is in file '<dir>\\<prefix><roomName><extension>
//BEGIN old code
//	location = Rooms[iRoomNr].dir + sDescPrefix + Rooms[iRoomNr].name + sFileExt;
//END old code
//BEGIN new code
      sTargetLocation = Rooms[iRoomNr].dir + sDescPrefix + Rooms[iRoomNr].name + sFileExt;
//      window.alert("onMouseOverRoom " + iRoomNr + " = " + sTargetLocation);
      eval(sTargetFrame).location = sTargetLocation;
//END new code
  }
  //ELSE do nothing
}//END onMouseOverRoom(iRoomNr)

//--->> Reset menu and show description >>--------------------->>
function onMouseOutRoom(iRoomNr)
{
  var sTargetFrame = 'fDesc';
  var sTargetLocation = 'unknown';

  //reset cursor, clear frame fDesc, Map and statusbar
  document.cursor='default';
//BEGIN old code
//  location = sTargetLocation;
//END old code
//BEGIN new code
  sTargetLocation = sMenuPage;
//  window.alert("onMouseOverRoom " + iRoomNr + " = " + sTargetLocation);
  eval(sTargetFrame).location = sTargetLocation;
//END new code

  ChangeImg(iRoomNr,0); //de-colour the room the mouse was over
//  if (iCurrentRoom > 0) ChangeImg(iCurrentRoom,1); //re-colour the room we're "in" now
}//END onMouseOutRoom(iRoomNr)

//--->> Enter room and show content >>------------------------->>
function onClickRoom(iRoomNr)
{
  var sTargetFrame = 'fContent';

  //Enter new room...
  EnterRoom(iRoomNr);
  //...then display it's content = file '<dir>\\<RoomName><Extension>'
  //MM 20030209 onload wordt niet meer uitgevoerd, dus altijd parent vervangen door index.html
  //parent.fContent.location = parent.fMenu.Rooms[iRoomNr].dir + parent.fMenu.Rooms[iRoomNr].name + parent.fMenu.sFileExt;
//MM 20040314 parent location set in menu.html href
//  parent.location = parent.fMenu.Rooms[iRoomNr].dir + "index.html";
}//END onClickRoom(iRoomNr)

//--->> Set menu and show side bar >>-------------------------->>
function LeaveRoom(iRoomNr)
{
  //fMenu: de-colour the current iRoomNr
  if (iRoomNr > 0)
  {
    //fMenu: de-colour the room
    ChangeImg(iRoomNr,0);
  }
  else
  { 
    if (iRoomNr < 0) 
    {
      //Problem: unknown current iRoomNr, so clear all
      for (i=1;i<=iMaxRoom;i++) ChangeImg(i,0);
    }
    //else do nothing
  }

  //clear side bar...
  ColourSideBar(Rooms[0].colour);

}//END LeaveRoom(iRoomNr)

//--->> Set menu and show side bar >>-------------------------->>
function EnterRoom(iRoomNr)
{
  //tijdelijke oplossing: eerst LeaveRoom
  LeaveRoom(iCurrentRoom);

  iCurrentRoom = iRoomNr;
  ChangeImg(iCurrentRoom,1);
//  ColourSideBar(Rooms[iCurrentRoom].colour);
}//END EnterRoom(iRoomNr)

//--->> Replace named image based on room number >>------------>>
function ChangeImg(iRoomNr,bState)
{
  var sImg = "";
  var sImgID  = "Room" + iRoomNr; 	// e.g. 'Room1'

  if (iRoomNr > 0 && iRoomNr <= iMaxRoom)
  {
      sImg += "img" + iRoomNr;
	if (bState == 1)
	{
	  sImg += "_on";	//e.g. 'img1_on.src'
	}
	else
	{
	  sImg += "_off";	//e.g. 'img1_off'
	}
      sImg += ".src"; 
  }//IF >0
//window.alert("ChangeImg " + iRoomNr + " = " + sImg + " = " + eval(sImg));

  if (browserVer == 1)
  {
	document.images[sImgID].src = eval(sImg);
  }
}//END ChangeImg(iRoomNr,bState)

//--->> Set background colour in fSidebar >>--------------->>
function ColourSideBar(hxColour)
{
  var sTargetFrame= 'fSideBar';
  parent.fSideBar.document.bgColor=hxColour;
}//END ColourSideBar(hxColour)

//--->> Set text on status bar >>------------------------------>>
function SetStatusBar(sAction,iID)
{
  if (sAction == "click") sText = "Click now to enter the " + iID + " / " + Rooms[iID].longname;
  else if (sAction == "clear") sText = "";
  else sText = "";
  window.status=sText;
}//END SetStatusBar(sAction,iID)
//<<--- END FUNCTIONS <<---------------------------------------<<
//END SCRIPT
