// A few global variables  ;-\ 
// I can't find a faster way...

VISIBLE_LAYER=0;
VISIBLE=document.layers ? 'show' : 'visible';
HIDDEN=document.layers ? 'hide' : 'hidden';


function imageFind(){
// This takes 1 or 2 arguments: the name of an image, and optionally the
// layer the image is on. So if it's in Netscape but there's no layer,
// it won't be fooled.
	var theImage=(document.layers && imageFind.arguments[1]) ? lookThroughLayersForItem(imageFind.arguments[1]).document.images[imageFind.arguments[0]] : document.images[imageFind.arguments[0]];
	return theImage;
}


function itemExists(itemID){
	// This checks to see if a div/span item exists or not. It should 
	// work in IE4+ N4, and W3C-compliant browsers
	if(document.all){
		return document.all[itemID] ? true:false;
	} else if(document.layers){	
		return lookThroughLayersForItem(itemID) ? true:false;
	} else if(document.getElementById){
		return document.getElementById(itemID) ? true:false;
	}

}

function menuTopClick(menuName){
	var visResult,menuID;
	// because the menus are named 'profileOptions' etc.
	menuID=menuName + "Options";
	// visResult will return the string equivalent of hidden or visible
	visResult=showTog(menuID);
	// Here's where the global comes in; because IE on the Mac
	// moves about as fast as snail on opium, time is of the essence.
	// it's quicker to just remember the last layer I showed & hide
	// it than looking through all the layers & doing all that stylesheet
	// mumbo-jumbo (see function WM_checkIn) for each one just to see 
	// the one that's visible
	if(VISIBLE_LAYER && (VISIBLE_LAYER!=menuID)){
		showTog(VISIBLE_LAYER,HIDDEN);
	}
	VISIBLE_LAYER = visResult.toLowerCase()==VISIBLE ? menuID : 0;
	showTog('headnote',visResult);
}

function menuTopOver(menuName){
	// button goes down...
	var pictureName=menuName+"ButtonBG";
	var pictureLayer=menuName+"Button";
	var theImage=imageFind(pictureName,pictureLayer);
	theImage.src='images/button_down.gif';
}

function menuTopOut(menuName){
	// button goes up...
	var pictureName=menuName+"ButtonBG";
	var pictureLayer=menuName+"Button";
	var theImage=imageFind(pictureName,pictureLayer);
	theImage.src='images/button.gif';
}

function showTog(){
	// Borrowed from Taylor's DHTML tutorial, but HEAVILY modified to
	// work with this program
	var theObj=WM_checkIn(showTog.arguments[0]);
	// Function is modified so that if you pass no second argument, 
	// it just switches the visibility on/off. If you pass it a 
	// second argument, which is either the variable HIDDEN or
	// VISIBLE, then it will do that to the object.
	if(showTog.arguments.length>1){
		theObj.visibility=showTog.arguments[1];
	} else {
		theObj.visibility=(theObj.visibility.toLowerCase()==VISIBLE) ? HIDDEN:VISIBLE;
	}
	//alert(theObj.visibility);
	return theObj.visibility;
}

// All functions below this line are written by Taylor or someone else
// from Webmonkey, with some modification, as noted. (except - AHEM -
// all variables in functions made *local* the way they should be in 
// OO programming)

// this just in: local author eats crow... see comments on line 1




function lookThroughLayersForItem(WM_id){
// Jimboweb: This function was originally part
// of Taylor's function; I separated it out so I can
// use it above in itemExists();

// Taylor: Now we're in Netscapeland. The main problem here 
// is finding the object in a maze of hierarchy.
// I wish I could say that I'm proud of this code, 
// because it's really slick. Unfortunately, I ripped 
// it off from Macromedia Dreamweaver's drag layer code 
// (with permission, of course :-) 
// Dreamweaver/Configuration/Behaviors/Actions/Drag Layer.htm 
// It works wonderfully and solves the problem.

var i,j,WM_layers = new Array();
with (document) {
  for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
	for (i=0; i<WM_layers.length; i++) {
	  if (WM_layers[i].document && WM_layers[i].document.layers) {
		for (var j=0; j<WM_layers[i].document.layers.length; j++) {
		  WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
		}
		if(WM_layers[i].name == WM_id){
		  // So if the code matches the name of the layer, 
		  // return the reference. 
		  var theObj = WM_layers[i];
		}
	  }
	}
  }
}
return theObj;
}


function WM_checkIn(WM_id) { 




/*
WM_checkIn()
Takes the ID of a positioned HTML element and returns an object reference.

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/

Usage: WM_checkIn('id')
*/

  // Taylor: First we initialize all the variables.
  var theObj,ss,sr,i,j,WM_layers=new Array();
  // Taylor: This chunk handles the IE portion of the checkIn code.
  if (document.all) {
    // Taylor: This checks to see if the inline style declaration has 
    // a position property associated with it. If not, it will 
    // scan the global stylesheets for the ID.
    if((document.all[WM_id].style.position != 'absolute') && (document.all[WM_id].style.position != 'relative')){
      // Taylor: This little loop I'm very proud of, because it's kinda 
      // slick and I wrote it all myself. It loops through all 
      // global stylesheets and all the rules in each stylesheet, 
      // tests for the selected ID, then returns that as the object.
      for (ss=0 ; ss < document.styleSheets.length; ss++) {
        for (sr=0 ; sr < document.styleSheets(ss).rules.length; sr++) { 
          if (document.styleSheets(ss).rules(sr).selectorText == '#' + WM_id) {
            var theObj = document.styleSheets(ss).rules(sr).style;
            break;
          }
        }
      }
    } else {
      // Taylor: This works the same as in the light version, so you can 
      // use inline styles.
      var theObj = document.all[WM_id].style;
    }
  }
  
  
  else if(document.layers) {
	theObj=lookThroughLayersForItem(WM_id)
  }
  // Jimboweb: I added this to Taylor's function myself. According
  // to Netscape's explanation of theW3C DOM, this should make it work 
  // with all the new W3C compliant browsers, including
  // N6, Opera, MacIE5, Konqueror... Why am I suspicious?
	else if(document.getElementById){
		var theObj=document.getElementById(WM_id).style;
	}


  return theObj;
} 


function WM_swapLayerBgcolor() {
  // Make sure the browser supports DHTML.
  if(document.layers || document.all || document.getElementById)
    with(WM_swapLayerBgcolor)
      // Loop through all arguments, two at a time.
      for(var i = 0; i < (arguments.length - 1); i += 2)
  // Get an object reference and set the 
  // bgcolor according to the DOM.
	  if(document.layers) {
	  //alert(WM_checkIn(arguments[i]).document.bgColor);
		WM_checkIn(arguments[i]).document.bgColor = arguments[i+1];
	  } else {
		WM_checkIn(arguments[i]).backgroundColor = arguments[i+1];
	  } 
	  
	  // note : The following is for Opera, but will not work, because Opera won't
	  // recognize there's a background-color style unless there already is one, but 
	  // if it is, Communicator thinks the document.bgcolor is different from the
	  // background-color style and changes some other background behind the background. 
	  // (Only Netscape...) So Opera just can't do the background thingy until I find a
	  // smarter way. But that's not going to kill any Opera users; the site still works fine.

	  /* 
	  else { 
		WM_checkIn(arguments[i]).background = arguments[i+1];
	  }*/
}

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;
  }
}


function WM_preloadImages() {

/*
WM_preloadImages()

Loads images into the browser's cache for later use.

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

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_preloadImages('image 1 URL', 'image 2 URL', 'image 3 URL', ...);
*/

	// Don't bother if there's no document.images
	if (document.images) {
		if (typeof(document.WM) == 'undefined'){
			document.WM = new Object();
		}
		document.WM.loadedImages = new Array();
		// Loop through all the arguments.
		var argLength = WM_preloadImages.arguments.length;
		for(arg=0;arg<argLength;arg++) {
		// For each arg, create a new image.
		document.WM.loadedImages[arg] = new Image();
		// Then set the source of that image to the current argument.
		document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
		}
	}
}

function loader1(){
	WM_preloadImages('images/bgmask.jpg','images/button.gif','images/button_down.gif','images/close_arrow.gif','images/menuBar.gif','images/title.gif');
	WM_netscapeCssFixCheckIn();
}