// hlavni scroll div musi mit id "block"

// unused, but useful:
function get_offsetTop(elem)
{
	if (elem.offsetParent) {
		return elem.offsetTop + get_offsetTop(elem.offsetParent);
	}
	else
		return elem.offsetTop;
}


function stable_heading_onload()
{
	if (!window.stable_heading_configured)
		return;
	
	scroll_obj = document.getElementById('block');
	
	//set_taxon_width();
	stable_heading_table = document.getElementById(stable_heading_table);
	stable_heading_header = document.getElementById(stable_heading_header);
//	stable_heading_body = document.getElementsByTagName('body')[0];
//	if (!stable_heading_body)
//		alert('body');

	set_table_header_size();

	//stable_heading_header.style.display = "none";
	stable_heading_header.className = "invisible";

//	scroll_obj.onscroll = function() { alert('hey'); }

	oldOnScroll = scroll_obj.onscroll;
	scroll_obj.onscroll = function()
	{
		check_heading_stability();
		if (oldOnScroll)
			oldOnScroll();
	}
//	scroll_obj.hej = 'Jojojo!';
//	alert(this + ', ' + this.nodeName + ', ' + this.nodeType);
//	alert(scroll_obj.nodeName + ', ' + scroll_obj.nodeType);
}

//function check_heading_stability()
//scroll_obj.check_heading_stability = function()
function check_heading_stability()
{
//	alert(scroll_obj.hej);
//	alert(this.nodeName + ', ' + this.nodeType);
	var table = stable_heading_table;
	var header = stable_heading_header;
//	var body = stable_heading_body;
	if (!table)
		return;
//	if (!stable_heading_body)
//		alert('body');

//	if (body.scrollTop >= table.offsetTop)
// document.documentElement.scrollTop je kdyz se scrolluje body... body.scrollTop je neofic jen pro quirks mode
// jinak asi kazdy objekt ma metody onscroll a hodnotu scrollTop - snad
//	alert(document.documentElement.scrollTop + ', ' + get_offsetTop(table));
//	alert(scroll_obj.scrollTop + ', ' + get_offsetTop(table));
	if (scroll_obj.scrollTop >= get_offsetTop(table)) {
	//		alert('y');
			header.className = "fixed";
			/* header.style.display = "fixed";
			header.style.backgroundColor = "red";
			header.style.top = 0; */
	}
	else {
			header.className = "invisible";
	}
}


function stable_heading_config(table_id, table_header_id)
{
	window.stable_heading_configured = 1;
	window.stable_heading_table = table_id;
	window.stable_heading_header = table_header_id;
}


window.onload_before_stable_heading4e2394 = window.onload;
window.onload = function()
{
	if (window.onload_before_stable_heading4e2394)
		window.onload_before_stable_heading4e2394();
	stable_heading_onload();
}












/* ============ tady uz jsou jen drivejsi pokusy, zakomentovane =========== */









/*

function check_heading_stability0()
{
//	var table = document.getElementById('csurvey');
	var table = document.getElementById('cur');
	if (!table)
		return;
	var body = document.getElementsByTagName('body')[0];
//	if (body.scrollTop >= table.offsetTop)
	if (body.scrollTop >= get_offsetTop(table))
			table.className = "fixed";
	else 
			table.className = "";
}


function check_heading_stability1()
{
	var table = document.getElementById('csurvey');
	if (!table)
		return;
	var ths = table.getElementsByTagName('th');
	for (i = 0; i < ths.length; i++) {
		if (ths[i].id == "point") {
			
			ths[i].className = "fixed";
			//ths[i].className = "red";
		}
	}
	return;
	var body = document.getElementsByTagName('body')[0];
	if (body.scrollTop >= ths[0].offsetTop)
		for (i = 0; i < ths.length; i++) 
			if (ths[i].id == "point")
				ths[i].className = "fixed";
	else
		for (i = 0; i < ths.length; i++) 
			if (ths[i].id == "point")
				ths[i].className = "";
}

*/

/*
Nefacha, protoze nelze nacist width!!! Jenom nastavit!!! 
function set_taxon_width()
{
//	document.getElementById('taxoncolheader').width = 
//		document.getElementById('taxoncol').width;

//	var cnt = 0;
	var table = document.getElementById('csurvey');
//	var taxon = document.getElementById('s');
	vs = table.getElementsByTagName('td');
	width = 0;
	yes = 0;
	for (i = 0; i < vs.length; i++)
		if (vs[i].id == "s") {
			//alert('ahoj' + vs.width);
			//break;
			//cnt++;
			width = vs[i].width;
			yes = 1;
			break;
		}
	alert('ahoj' + vs[i].width + 'be' + yes + 'n' + vs[i].nodeName + 'i' + vs[i].id);
	var taxonh = document.getElementById('taxoncolheader');
	taxonh.width = 100; //taxon.width;
//	alert('ahoj');
	alert('ahoj = "' + taxon.width + '"');

	
}
*/

