<!--
/*
This code is from Dynamic Web Coding 
www.dyn-web.com 
Copyright 2001 by Sharon Paine 
Permission granted to use this code as long as this 
entire notice is included.
*/

dom = (document.getElementById) ? true : false;
ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
ns4 = (document.layers && !dom) ? true : false;
ie4 = (document.all && !dom) ? true : false;
nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

var origWidth, origHeight;
if (ns4) {
  origWidth = window.innerWidth;
  origHeight = window.innerHeight;
}
// reload/reposition on resize
function reDo() {
	if (ns4) {
	 if (window.innerWidth != origWidth || window.innerHeight != origHeight) 
	    window.location.reload();
	} else {
		setTimeout("getStatPos()",200);
	}
}
window.onresize = reDo;

// options for statPosition: "top left", "top right", "bottom left", 
// "bottom right", "top center", "bottom center"
var statPosition="top left";
var stat_yOff=15, stat_xOff=15;	// offsets from window edges
var statWidth=120, statHeight=20;	// layer width and height
var statLyr, statcss, stat_xPos, stat_yPos;
function initStatLyr(lyr) {
	if (nodyn) return;
	statLyr = (ns4)? document.layers[lyr]: (ie4)? document.all[lyr]: document.getElementById(lyr);
	statcss = (ns4)? statLyr: statLyr.style;
	statcss.width = (ns4)? statWidth: statWidth+"px"; 
	statcss.height = (ns4)? statHeight: statHeight+"px";
	// check whether browser is able to do fixed position
	// set to arbitrary left position which can be read back (Mac too?)
	// even if not "set" because of fixed positioning not supported
	if (ie5||ns5) {
		statcss.position="fixed";
		statcss.left="436px";	
		var curLeft = statLyr.offsetLeft;	// where is the layer?
		// allow for Mac discrepancy (how much?)
		if (curLeft<parseInt(statcss.left)-20) {
			// it can't, so position absolute
			statcss.position="absolute";
		}
	}
	getStatPos(); // send all to calculate position
}

// find top/left values for statLyr 
// based on statPosition variable value, window width/height
function getStatPos() {
	var winWd = (ie4||ie5)? document.body.clientWidth: window.innerWidth;
	var winHt = (ie4||ie5)? document.body.clientHeight: window.innerHeight;
	// adjust for scrollbars
	// There doesn't seem to be a way to get document.height in ns5 
	// if CSS-P is used to lay out the document. You get 0, so check if 0.
	if (ns4||ns5) {
		if (document.height>winHt||document.height==0) winWd-=20;
		//alert(document.width)
		// ns4 can give unreliable document.width readings
		// long table will give wider reading 
		// maybe comment out following line if using tables for layout
		// and static layer appears too high in ns4 (no horizontal scrollbars)
		if (document.width>winWd) winHt-=20;
	}
	switch (statPosition) {
      case "top left" :
      	stat_xPos=stat_xOff; stat_yPos=stat_yOff;
      break;
			case "top right" :
				stat_xPos=winWd-(statWidth+stat_xOff); 
				stat_yPos=stat_yOff;
			break;
			case "bottom left" :
				stat_xPos=stat_xOff;
				stat_yPos=winHt-(statHeight+stat_yOff);
			break;
      case "bottom right" :
      	stat_xPos=winWd-(statWidth+stat_xOff); 
				stat_yPos=winHt-(statHeight+stat_yOff);
      break;
			case "top center" :
				stat_xPos=Math.round((winWd-(statWidth+stat_xOff))/2); 
				stat_yPos=stat_yOff;
			break;
			case "bottom center" :
				stat_xPos=Math.round((winWd-(statWidth+stat_xOff))/2); 
				stat_yPos=winHt-(statHeight+stat_yOff);
			break;
      default: alert("Check the available choices again.")
   }
	posStatLyr();
	// statcss.visibility = "visible";
}

// constantly monitors scrolling and repositions layer accordingly
function posStatLyr() {
	var yScroll=(ie4||ie5)? document.body.scrollTop: window.pageYOffset;
	var xScroll=(ie4||ie5)? document.body.scrollLeft: window.pageXOffset;
	statcss.top=(ns4)? yScroll+stat_yPos: yScroll+stat_yPos+"px";
	statcss.left=(ns4)? xScroll+stat_xPos: xScroll+stat_xPos+"px";
	// no need to recall if fixed
	if (statcss.position!="fixed") var t=setTimeout("posStatLyr()",2);
}

//-->
