<!--
// Global variables

// Editabel variables
var fadingtime = 1;	// Speed of fading
var fadefrom = 7;	// Fading from (0=unvisible 10 = full visible)
var fadeto = 8;		// Fading to (0=unvisible 10 = full visible)

// Noneditable variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var load = false;	// Flag if page is loadet (not needet jet)
var timer;			// Timer var
var fixed_layer;	// The current layer
var navi;			// Count on layerelements
var screenwidth;	// Dynamic horizontal position of leftpagemargin (depending on browserwidth)	
var screentop;		// Height between top to start on layer
var offset = 16;	// Height of one colum
var openlayer;		// The current open layer

/*
 * initfunction calculate dimensions on browserwindow an 
 * set nessesary variables nad reset all layers
*/
function initonload() {
	load = true;
	if (ie) {
		if (navigator.platform.match("Mac")) {
			screenwidth = Math.floor(document.body.offsetWidth/2-271);
			screentop = 95;
		}
		else {
			screenwidth = Math.floor(document.body.offsetWidth/2-271);
			screentop = 92;
		}
	}
	else {
		screenwidth = Math.floor(document.body.offsetWidth/2-261);
		screentop = 92;
	}
	if (document.layers) { // Netscape
	    document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
	    document.onmousemove = captureMousePosition;
	}
	resetall();
}

/*
 * resetfunction to disable all layers
*/
function resetall() {
	oldspace = screentop;
	for (i=1;i<=navi;i++) {
//		alert ("layer"+i);
		b = new LyrObj("layer"+i);
		document.getElementById("layer"+i).style.filter = "alpha(opacity="+fadefrom+")";
		document.getElementById("layer"+i).style.opacity = "."+fadefrom+"";
		screentop = screentop + offset;
		b.setPos("left", screenwidth);
		b.setPos("top", screentop);
		b.setVisibility(false);
		setbackground("layer"+i, "#fff", "#555");
	}
	screentop = oldspace;
}

/*
 * resetfunction to disable a single Layer most like the resetall function 
 * for performace reasons a smaler and faster version
*/
function reset(openlayer) {
	setbackground(openlayer, "#fff", "#555");
	b = new LyrObj(openlayer);
	document.getElementById(openlayer).style.filter = "alpha(opacity="+fadefrom+")";
	document.getElementById(openlayer).style.opacity = "."+fadefrom+"";
	b.setVisibility(false);
}

/*
 * start fading with this function (init fading
*/
function fade(direction, layer) {
	if (fixed_layer != layer) {
		if (direction == "in") {
			if (openlayer) {
//				alternativ fade the layer out as well (not working yet)
//				fader("out", fadeto, openlayer);
				reset(openlayer);
			}
			b = new LyrObj(layer);
			b.setVisibility(true);
			openlayer = layer;
			fader(direction, fadefrom, layer);
		}
		else {
			fader(direction, fadeto, layer);
		}
	}
}


function setbackground(layer, color, linkcolor) {
	bgnr = layer.substr(5, layer.length);
	document.getElementById("tdlink"+bgnr).style.backgroundColor = color;
	document.getElementById("link"+bgnr).style.color = linkcolor;
}

/*
 * recursive function to fade untin end depending on direction
*/
function fader(direction, fade, layer) {
	if (direction == "in") {
		if (fade == fadefrom)
			setbackground(layer, "#738A8C", "#fff");
		if (fade < fadeto) {
			fade++;
			document.getElementById(layer).style.filter = "alpha(opacity="+(fade*10)+")";
			document.getElementById(layer).style.opacity = "."+fade;
			window.setTimeout("fader('"+direction+"', "+fade+", '"+layer+"')", fadingtime);
		}
		else {
			timer = false;
		}
	}
	else {
		setbackground(layer, "#fff", "#555");
		if (fade > fadefrom) {
			fade--;
			document.getElementById(layer).style.filter = "alpha(opacity="+(fade*10)+")";
			document.getElementById(layer).style.opacity = "."+fade;
			window.setTimeout("fader('"+direction+"', "+fade+", '"+layer+"')", fadingtime);
		}
		else {
			timer = false;
			b = new LyrObj(layer);
			b.setVisibility(false);
			fixed_layer = "";
			openlayer = "";
		}
	}
}

/*
 * function to mark a layer as fix
*/
function fixlayer(layer) {
	fixed_layer = layer;
}

/*
 * capture function this function captures the mouse position
 * it calculates the mouseposition at the ratio of the visible layer 
 * if the mouse leaves the cords of the active layer the layer will collapse
*/
function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }

	if (fixed_layer) {
		b = new LyrObj(fixed_layer);
		height = b.getHeight();
//		ylimit = height + screentop;

		layernumber = parseInt(fixed_layer.substring((fixed_layer.length-1), fixed_layer.length))+1;

		width = b.getWidth();
		xlimitstart = screenwidth;
		xlimitend = width + screenwidth;

		ylimitstart = (layernumber * offset + screentop)-offset;
		
		ylimitend = (height + (layernumber * offset + screentop))-offset;

		if ((yMousePos < ylimitstart || yMousePos > ylimitend) || (xMousePos < xlimitstart || xMousePos >  xlimitend)) {
			reset(fixed_layer);
//			alternativ fade the layer out as well
//			fader("out", fadeto, fixed_layer);
			fixed_layer = "";
			openlayer = "";
		}
	}	
}
//-->
