// JavaScript Document

// The functions beginning with "MM_" are by Macromedia
// as supplied for a class by Dr. Tan.

var flag1=1;

function MM_findObj(n, d) { 
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
   }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
  return x;
}

function MM_swapImage() 
{ 
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null)
	{
		document.MM_sr[j++]=x; 
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}
function MM_swapImgRestore() 
{ 
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ 
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{ 
			d.MM_p[j]=new Image; 
			d.MM_p[j++].src=a[i];
		}
	}
}

function MM_showHideLayers() 
{ 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
	  v=args[i+2];
	  if (obj.style) { 
		  obj=obj.style; 
		  v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
	  }
	  obj.visibility=v;
		window.status=obj.top+' , '+obj.left;
	}
}

// The next two functions are from Macromedia Dreamweaver
// and used as a reference for the "RVH_" scripts I wrote.

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

// The following scripts are Copyright (c) 2004-2005 Richard V. Hall, Jr.

/*

I made these loosely based on the functions above in order 
to better mimic OS menus with minimal script, implementing 
menus primarily in HTML with CSS using DIV and TABLE tags. 

The features I wanted to add include:

  * the ability to align menus with existing objects rather 
	  than using direct numeric positioning;

  * the addition of a delay when hiding menus, in case the 
	  CSS alignment is off or the user mouses outside the lines 
		for a split second;

  * the ability to use menus at will simply by adding onmousover
	  and onmouseout events, without requiring the programmer to 
		manually initialize the menus; and
	
	* faster processing of menus by using hash arrays (objects) 
	  to store outcomes of previous decisions for future use 
		(optimizing for speed instead of memory)
		
	* Compatibility with MacIE5 (the MM scripts break under MacIE5).
	
To use, add the following properties to a menubar item (always visible):

   id="mbi_[name]" 
	 class="RVH_menubar_item"
	 onmouseover="RVH_showLayer('menu_[name]')" 
	 onmouseout="RVH_hideLayer('menu[name]')"

Then, add the following properties to a menu layer (usually hidden):
   
	 id="menu_[name]"
	 class="RVH_menu"
	 onmouseover="RVH_showLayer('menu_[name]')"
	 onmouseout="RVH_hideLayer('menu_[name]')"
	 
In the above examples, replace [name] with a string that uniquely 
identifies a pairing of menubar item with a menu. For example, for a 
menubar item called "Home", the menubar item's ID should be 
"mbi_home" and its menu ID should be "menu_home". If this convention
will not work for you, you will need to supply the actual ID of the
menubar item as the second argument for the RVH_showLayer() function.

Style note: single-character variables run faster in JavaScript, so
where I have chosen my own variables, I use single characters.

Comments also slow down JavaScript, so I have included them here
only for the sake of the class I am taking.

*/

//menus are a kind of "layer".
//we use following array to track visible layers.
var RVH_layerTimeouts=new Array();

// a menubar item is a kind of "station".
// we use following array to track stations.
var RVH_layerStations=new Array(); 

// directly show a layer
function RVH_showLayer(n,p,dx,dy){ // name of menu, name of station (optional), offset (optional)
  RVH_hideActiveLayers();
  RVH_clearLayerTimeout(n);
  var i,m,x,y,s,r=RVH_layerStations;
	if(!r[n])r[n]=new Array(); //if no station exists, make one.
	s=r[n];
	s.n=n;
	s.dx=(dx? dx: s.dx? s.dx: 0);  //remember position
	s.dy=(dy? dy: s.dy? s.dy: 16);
	if(p && s.p && (p!=s.p))s.i=false; //detect a change in menu bar item.
	s.p=(p? p: s.p? s.p: n.split('menu_').join('mbi_') ); //allow default naming system
	if(!s.s)s.s='show'; //set defaults for show/hide values
	if(!s.h)s.h='hide';
	if(!(s.m && s.m.visibility)){ //if menu object is unknown, find it.
		s.m=MM_findObj(n);
		if(s.m==null)s.m=false;
		if(s.m && s.m.style){
			s.m=s.m.style;
			s.s='visible';
			s.h='hidden';
		}
	}
	if(!(s.i && s.i.visibility)){ //if menubar item is unknown, find it.
		s.i=MM_findObj(s.p);
		if(s.i==null)s.i=false;
		s.o=s.i;
		if(s.i && s.i.style) s.i=s.i.style;
	}
  if( s.i && s.m ) { //if menubar item and menu are valid...
		RVH_moveLayer(s); // ...position the menu relative to the item...
	  s.m.visibility=s.s; // ...and show the menu. 
	}
	flag1=flag1*2; //this flag retained from other example-- has no purpose.
}

function RVH_moveLayer(s, o, x, y) { // station hash, object (optional), xy offset (optional)
  //positions one layer relative to another
	//must be called each time a menu layer is shown in case the "station" moves.
	if(!s)s=new Array();   // if a station hash is not provided, make one.
	o=(o?o:s.o?s.o:false); // store any change in object for future use
	if(!o)return s;        // short-circuit if the station object is not provided
	x=(x?x:s.dx?s.dx:0);   // get offset from hash if not provided 
	y=(y?y:s.dy?s.dy:0);
	if (!document.layers) { // if not Netscape Navigator...
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && window.getExplorerVersion && (window.getExplorerVersion() == 4.5); // this had to be fixed to work with MacIE5
		var par = o; //parent object initialized to station object
		var lastOffsetLeft = 0; //Left and top offsets are tracked separately
		var lastOffsetTop = 0;
		while(par){ //get a more convoluted position
			if( par.leftMargin && !onWindows ) x += parseInt(par.leftMargin);
			if( par.topMargin  && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetLeft != lastOffsetLeft) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( (par.offsetTop  != lastOffsetTop)  && par.offsetTop  ) y += parseInt(par.offsetTop);
			if( par.offsetLeft != 0 ) lastOffsetLeft = par.offsetLeft;
			if( par.offsetTop  != 0 ) lastOffsetTop  = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else { // otherwise, when using Netscape Navigator 4.x...
		if (i.x) x += i.x;
		if (i.y >= 0) y += i.y;
	}
	s.x=x; // store results for future use
	s.y=y;
	if(s.m){ // if the station is already associated with a menu, align it.
	  s.m.pixelLeft = s.x || (window.pageX + document.body.scrollLeft) || 0;
		s.m.left = s.m.pixelLeft + 'px';
		s.m.pixelTop = s.y || (window.pageY + document.body.scrollTop) || 0;
		s.m.top = s.m.pixelTop + 'px';
		//window.status=s.m.top+' , '+s.m.left;
	}
	return s;
}

function RVH_hideLayer(n) { // indirectly hides a layer if still not in use after 1 sec.
  if( RVH_layerTimeouts[n] ) RVH_clearLayerTimeout(n);
  RVH_layerTimeouts[n] = setTimeout("RVH_timeoutLayer('"+n+"')", 1000);
}

function RVH_timeoutLayer(n){ // directly hides a layer, called as a timeout
  RVH_clearLayerTimeout(n);   // kill pending threads of same function  
  var s, r=RVH_layerStations;
	if(!r[n])r[n]=new Array();  // if station hash doesn't exist, create it
	s=r[n];
	if(s.m && s.h){             // shortcuts to hiding the menu if we already know how.
		s.m.visibility=s.h;
	}else{                      // otherwise, find the menu and how to hide it,
		s.m=MM_findObj(n);        // and store the results in a station hash.
		if(s.m==null)s.m=false;
		if(s.m) { 
	    s.h='hide';
	    if (s.m.style) { 
		    s.m=s.m.style; 
		    s.h='hidden'; 
	    }
			s.m.visibility=s.h;
		}
	}
}
function RVH_clearLayerTimeout(n) { // clears any pending layer timeouts related to menu name n
  if (RVH_layerTimeouts[n]) clearTimeout(RVH_layerTimeouts[n]);
  RVH_layerTimeouts[n] = null;
}
function RVH_hideActiveLayers(){ // hides all visible menus immediately 
  for(var n in RVH_layerTimeouts) RVH_timeoutLayer(n); // this step also clears timeouts
}

// I use the following script to thwart spmers who scrape the web for email addresses.
// use: <a href="javascript:RVH_popup('talk to name at richhall decimal com about the website')">email me</a>

function RVH_popup(s){
  var t='to', i='il', m='ma';
  s=m+i+t+':' + s.substring(8,s.length);
  location.href=s.split('%20').join(' ').split(' at ').join('@').split(' decimal ').join('.').split(' about ').join('?subject=');
}