//-------------------------------------------<IMAGE ROLLOVERS>----------------------------------------- //

var restoreImg = ""; //source last image switched, for RestoreImage
var lastImg = ""; //name of last image switched, for RestoreImage

function PreloadImages() { 
  images = new Array;
  for (x=0; x<PreloadImages.arguments.length; x++) {
  	images[x]=new Image;
  	images[x].src=PreloadImages.arguments[x];
  	}
}

function SwapImage (oldimg,newimg) {
  if (document.images) {
   restoreImg = document.images[oldimg].src;
   document.images[oldimg].src=newimg;
   lastImg = oldimg;
  }
}

function SwapImageBlip (oldimg,newimg) {
  if (document.images) {
   restoreImg = document.images[oldimg].src;
   document.images[oldimg].src=newimg;
   lastImg = oldimg;
   // document.all['wave1'].src='/blip.wav';  This must have triggered a sound on image swap
  }
}

function RestoreImage () {
  if (document.images) {
   document.images[lastImg].src=restoreImg;
  }
}


//-------------------------------------------<TEXT SCROLLING>----------------------------------------- //

// The "GetDiv" function takes a layer and returns an ID ???

function GetDiv (lyr) {
  lyr = document.getElementById(lyr);  // Get Element by ID
  // There was a bunch of Netscape 4 code here. I axed it
  // My research shows that "document.all" is no longer proper
  
   return lyr;
} // End of "GetDiv" function

//----------------------------------------------------------------------------------------------------------------------------------------------------------

function GetBox (elem)
	{
	var result = new Object;
	
	var left	= 0;
	var top		= 0;

	for (var item = elem; item; item = item.offsetParent)
		{
		left += item.offsetLeft; // How far away from the left of the parent element is the box?
		top  += item.offsetTop; // How far away from the top of the parent element is the box?
		
		if (item.style.borderLeftWidth)
			{
			var bwid = parseInt (item.style.borderLeftWidth);
			if (!isNaN (bwid)) // If the border is a number.
				left += bwid; // If the element has a border, then we need to add this to the left coordinate.
			}
		}
	
	result.left		= left;
	result.top		= top;
	result.right	= left + elem.offsetWidth; // the width of the box is the original width plus any borders and padding.
	result.bottom	= top  + elem.offsetHeight; // the lenght of the box is the original lenth plus any borders and padding.

	return result;  // An object is returned that gives the exact position of the element.
	} // End function
//----------------------------------------------------------------------------------------------------------------------------------------------------------

var page = 1; //initial page is 0
var num_pages = 0;
var clength = 0;
var cmlength = 0;
var timerID = 0;
var dir;
var speed;
var pageLength = 389; // This is how deep the visible scrolled text is. You have to play with it.

//----------------------------------------------------------------------------------------------------------------------------------------------------------


function initPage(content, contentclip, scrolltext, pl) {
if(pl > 0)
pageLength = pl;

//alert("page initialized");
   pagecontent = GetDiv(content); // Make a call to the "content" division
   b = GetBox(pagecontent); // Create an object out of the "content" divsion
if (content== 'content') {
		clength = (b.bottom - b.top); 
		// Measure the length of the "content" division VERY IMPORTANT: other functions use this.
   num_pages = parseInt (clength / pageLength); //pageLength is the length of a full page, but allow room for a bottom margin

}else { 
		cmlength = (b.bottom - b.top); 
		// Measure the length of the "content" division VERY IMPORTANT: other functions use this.
		   num_pages = parseInt (cmlength / pageLength); //pageLength is the length of a full page, but allow room for a bottom margin

		}

   
  num_pages += 1; //round up no matter what
   
   if (num_pages == 1) { // If there is not enough text to scroll . . .
      s = GetDiv(scrolltext); // Make a call to the "scrolltext" division . . .
      s.style.display = "none"; // Now shut the "scrolltext" division off. 

      c= GetDiv(content);
      cclip = GetDiv(contentclip);

      if(pl > 0) {
		c.style.width = 417 + "px";
      cclip.style.width = 417 + "px";
      cclip.style.clip = "rect(0," + cw + ",417,0)";
 } else {
		c.style.width = 465 + "px";
      cclip.style.width = 465 + "px";
      cclip.style.clip = "rect(0," + cw + ",465,0)"; // The clipping of the "contentclip" division is updated to fill the void
     

}
   } // End if
} // End "inutPage" function

//----------------------------------------------------------------------------------------------------------------------------------------------------------

function scrollText (type) {
myType= type;
if(myType==1) {
myLength = clength;
} else { 
myLength = cmlength;
}
clearTimeout(timerID);
   if(type==1) { 
  pagecontent = GetDiv('content');
   ccontainer = GetDiv('contentcontainer');
b1 = GetBox(pagecontent);   
b2 = GetBox(ccontainer);   
} else {
  pagecontent = GetDiv('contentMenu');
   ccontainer = GetDiv('contentcontainerMenu');
b1 = GetBox(pagecontent);   
b2 = GetBox(ccontainer);     
 }



   y = b1.top - b2.top; // "y" is how far the "content" division with all the text has strayed from the "contentcontainer" 
                        // that is holding it. If "y" was "0" then you would be looking at the first line of the paragraph.
   if (dir == 1) { //scroll forward, if there's something to scroll to
  
if ((myLength - (0-y)) > pageLength) { 
      // If the "content" division plus the little gutter between the "contentcontainer"
      // and the "contentclip"  is all greater than 250 then there is something to scroll. ???
         if (speed == 0) {
            //scroll forward slow
            y -= 12;
         } else {
            y -= 36;
         }
      }
   } else {  // scroll back, if we're not at the top
      if (y < 0) {
         if (speed == 0) {
            //scroll back slow
            y+=12;
         } else {
            y+=36;
         }
         if (y > 0) {
            y = 0;
         }
      }
   }

pagecontent.style.top = y + "px"; 
// After we figured out just where the box with all the text in it was positioned, and what the
// new position should be according to what scroll button was pressed, we set that new position
// in the style sheet.

timerID = setTimeout("scrollText(myType)", 100); 
// All this happens in 1/10 of a second and starts all over again as the user
// continues to hold down the scroll button. Once "y" finally becomes "0" the
 // function is bypassed, because you've reached the end of the box.
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------

  function startScroll (newdir, newspeed, type) {
  // FOR DIRECTION: 0 scrolls up, 1 scrolls down || FOR SPEED: 0 is slow, higher is faster
dir = newdir;
   speed = newspeed;
t = type;
   timerID = setTimeout("scrollText(t)", 100); 
   // The function times out, to prevent repeated clicking. It allows you to hold the button
   // down for continuous scrolling ???
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------

function stopScroll () {
   clearTimeout(timerID);
}

//-------------------------------------------<POP UP WINDOW>----------------------------------------- //
var popupWindow=null;function popup(mypage,myname,w,h,pos,infocus,ScrollBar){if (pos == 'random')	{LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}else{LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}	settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + ScrollBar + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';popupWindow=window.open('',myname,settings);

if(infocus=='front'){popupWindow.focus();popupWindow.location=mypage;}if(infocus=='back'){popupWindow.blur();popupWindow.location=mypage;popupWindow.blur();}}

//-------------------------------------------<SHOW DIVS>----------------------------------------- //

function showDiv (lyr) {

makeWhite = GetDiv("viewerContent");
makeWhite.style.backgroundImage = "none";

turnOff = GetDiv("floor1");  // Get Element by ID
turnOff.style.display="none";

turnOff = GetDiv("floor2");  // Get Element by ID
turnOff.style.display="none";

turnOff = GetDiv("floor3");  // Get Element by ID
turnOff.style.display="none";

turnOff = GetDiv("floor4");  // Get Element by ID
turnOff.style.display="none";

turnOff = GetDiv("floor5");  // Get Element by ID
turnOff.style.display="none";

turnOff = GetDiv("entry");  // Get Element by ID
turnOff.style.display="none";

lyr = document.getElementById(lyr);  // Get Element by ID
lyr.style.display="block";

}

function colorMenu (menu) {
	for (x=1; x < 6; x++) {
		myVar = "fm" + x;
		turnOff = GetDiv(myVar);
		turnOff.style.color= "#6f2713";
	}

	turnOn = GetDiv(menu);
	turnOn.style.color="rgb(192,132,109)";

	myImage = GetDiv("bottomLeft");
	myImage.style.backgroundImage = 'url("images/bottomLeftBG_' + menu + '.jpg")';


} // end func


function colorMainMenu (menu, image) {
turnOn = GetDiv(menu);
newBack = "images/" + image + "-over.gif"
turnOn.style.backgroundImage = 'url("images/' + image + '-over.gif")';
}

//-------------------------------------------<ENTER STORY>----------------------------------------- //
function enterStory() {

turnOff = GetDiv("viewerEntry");
turnOff.style.display="none";

turnOn = GetDiv("viewerContentFull");
turnOn.style.display="block";
initPage('content', 'contentclip', 'scrolltext');
}

//-------------------------------------------<SwitchMaps>----------------------------------------- //

function switchMaps(map) {
turnOff = GetDiv("stateMap");
turnOff.style.display="none";

turnOff = GetDiv("localMap");
turnOff.style.display="none";

turnOff = GetDiv("golfMap");
turnOff.style.display="none";

turnOn = GetDiv(map);
turnOn.style.display="block";
}


