// A better and more flexible way to show and hide layers than the standard DW code
// Much less code in the html

/*
   Example usage:
   CSS
   Specifications for container for layers to show/hide.
   Most browsers need both width and height set.

   #container {
	   position:relative;
	   width:380px;
	   height:220px;
	   z-index:100;
   }

   Include id's for all your layers here, with commas between.

   #lyr1, #lyr2, #lyr3	{ 
	position:absolute;
	visibility:hidden;
	left:0;
	top:0;
	z-index:1
   }

   HTML
   <a href="javascript:void(null);" onclick="swapLayers('desc_2'); return false" >Foo</a>

*/





// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) {
	  lyr.css.visibility = "visible";
	  lyr.style.zIndex = 100000;
	  lyr.css.zIndex = 100000;
  }
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// get reference to nested layer for ns4
// from old dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}
