/*========================================================================================
** frcscripts.js - JavaScript code for fallingrocks.org
==========================================================================================
**
** Copyright (c)2003, Dennis J. Wilkinson, II unless otherwise noted.
**
========================================================================================*/

function WM_netscapeCssFix() {
  /*
	Source: Webmonkey Code Library
	(http://www.hotwired.com/webmonkey/javascript/code_library/)

	Author: Taylor
	Author Email: taylor@wired.com
	Author URL: http://www.taylor.org/
	*/

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
	document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
	if (typeof document.WM == 'undefined'){
	  document.WM = new Object;
	}
	if (typeof document.WM.WM_scaleFont == 'undefined') {
	  document.WM.WM_netscapeCssFix = new Object;
	  document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
	  document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
	}
	window.onresize = WM_netscapeCssFix;
  }
}

// My globals
//-----------
var isNS4 = false;
var defaultMsg = "";
var ns4Layer = null;

function FindNS4Layer( layerID )
{
	if ( ns4Layer == null )
	{
		var NS4_layers = new Array();
		with (document) 
		{
			for (i=0; i < layers.length; i++) NS4_layers[i] = layers[i]; 
			{
			
				for (i=0; i < NS4_layers.length; i++) 
				{
					if (NS4_layers[i].document && NS4_layers[i].document.layers) 
					{
						for (j=0; j < NS4_layers[i].document.layers.length; j++) 
						{
							NS4_layers[NS4_layers.length] = NS4_layers[i].document.layers[j];
						}
						 
						if ( NS4_layers[i].name == layerID )
						{
							// So if the code matches the name of the layer, 
							// return the reference. 
							ns4Layer = NS4_layers[i];
						}
					}
				}
			}
		}
	}
}

// tuck away the default message for later reference
function SetDefaultMsg( msg )
{
	defaultMsg = msg;
}

// set the "statusArea" div's contents to msg
function SetMsg( msg )
{			
	if ( document.getElementById )
	{
		document.getElementById("statusArea").firstChild.nodeValue = msg;
	}
	else if ( document.all )
	{
		statusArea.innerHTML = msg;
	}
	else if ( document.layers )
	{
		FindNS4Layer("statusLayer");
		
		if ( ns4Layer )
		{
			ns4prefix = "<div id=\"statusArea\" class=\"statustext\">"; 
			ns4suffix = "</div>"; 
			ns4msg = ns4prefix + msg + ns4suffix;
		
			ns4Layer.document.write( ns4msg );
			ns4Layer.document.close();
		}
	}
	
}

// restore the default "statusArea" status
function DefaultMsg()
{
	SetMsg( defaultMsg );
}

function quoted( txt )
{
	result = "\"" + txt + "\"";
	return result;
} 

// PlaceImage is used to pick between transparent and
// non-transparent PNG flavors
function PlaceImage( regurl, nturl, cssClass, alt, align, w, h )
{
	if ( hasTransparentPNG || nturl != "" )
	{
		imgCode = "<img class=" + quoted(cssClass) +" src=";
		if ( hasTransparentPNG ) { imgCode += quoted(regurl); } else { imgCode += quoted(nturl); }
		imgCode += " border=\"0\" alt=" + quoted(alt) + " align=" + quoted(align);
		imgCode += " width=" + quoted(w) + " height=" + quoted(h) +">";
		document.writeln( imgCode );
	}
}

// fix up links and text for Navigator 4
if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4))
{
	isNS4 = true;
	
	document.tags.P.color = "white";
	document.tags.A.color = "white";
	document.tags.LI.color = "white";
	document.tags.H1.color = "white";
	document.tags.H2.color = "white";
	document.tags.H3.color = "white";
}

// make sure that CSS info doesn't get lost on resize in Nav4
WM_netscapeCssFixCheckIn(); 
