
var tabletop, tablebottom, divheadref, headref, tableref;
var tablecount;

function initFloatingHeaders() {
	if ((ie5 && !is_mac) || ns7) {
		tabletop = new Array();
		tablebottom = new Array();
		divheadref = new Array();
		headref = new Array();
		tableref = new Array();
		
		// find all the tables with ID of 'tableXX'
		var tablecollection = document.getElementsByTagName("TABLE");
		tablecount = 0;

		for (i=0; i<tablecollection.length; i++) {
			// if the table id begins with 'table'...
			if (tablecollection[i].id.indexOf('table') == 0) {
				tablecount++;
				var tablenum = tablecollection[i].id.substr(5);
				// save references to the div, head, and table
				divheadref[tablecount] = document.getElementById("divhead" + tablenum)	// this is a DIV, not a TABLE reference
				headref[tablecount] = document.getElementById("head" + tablenum)		
				tableref[tablecount] = tablecollection[i];
				
				divheadref[tablecount].style.visibility = "visible";				
				divheadref[tablecount].style.left = tableref[tablecount].offsetLeft		
			}
		}

		windowResize();
	}
}

function windowResize() {
	var elem; 
	
	if ((ie5 && !is_mac) || ns7) {
		for(i=1; i<=tablecount; i++) {
			headref[i].width = tableref[i].offsetWidth	// set the width of the column header table to the width of the data table
			tabletop[i] = tableref[i].offsetTop;
			tablebottom[i] = (tabletop[i] + tableref[i].offsetHeight) - divheadref[i].offsetHeight - tableref[i].rows[tableref[i].rows.length-1].offsetHeight;			
			divheadref[i].style.top = tabletop[i];
			
			
			elem = tableref[i].rows[0].cells[0];
			if (elem.currentStyle) {
				padding = parseInt(elem.currentStyle.paddingLeft) + 
				parseInt(elem.currentStyle.paddingRight) + 1;
			} else if (window.getComputedStyle) {
				var compStyle = window.getComputedStyle(elem, "");
				padding = parseInt(compStyle.getPropertyValue("padding-left")) + 
				parseInt(compStyle.getPropertyValue("padding-right")) + 1;			
			}
				
			// set the header table columns widths to the content table's column widths	
			for(j=0; j<headref[i].rows.length; j++) {
				for(k=0;k<headref[i].rows[j].cells.length;k++) {
					headref[i].rows[j].cells[k].width = tableref[i].rows[j].cells[k].offsetWidth-padding;

				}
			}
		}
	}
}

function windowScroll() {
	if ((ie5 && !is_mac) || ns7) {
		scrolltop = document.body.scrollTop;
	
		for (i=1; i<=tablecount; i++) {
			if (scrolltop > tablebottom[i])
				divheadref[i].style.top = tablebottom[i];
			else if (scrolltop > tabletop[i])
				divheadref[i].style.top = scrolltop;
			else
				divheadref[i].style.top = tabletop[i];
		}
	}
}
