/*
	Displays layers triggered by mouse-over events on certain elements.
	
	e.g.
	- to the right of OF/WA tab to select "Angebote & Gesuche", "nur Angebote", or "nur Gesuche"
	- beneath customer center menu item to display further information.
	
	Changes:
	21.05.2007	SD	#01	Added function positionLayer to set the correct position for
						absolute positioned layers, respective to their parent element.
*/

var activeSub = 0;
var SubNum    = 0;

var timerID    = null;
var timerOn    = false;
var timecount  = 500;
var what       = null;
var newbrowser = true;
var check      = false;


function InitLayer()
{
	//alert ("Running Init");
	
	if (document.layers) {
		//alert ("Running Netscape 4");
		layerRef    = "document.layers";
		styleSwitch = "";
		visibleVar  = "show";
		what        = "ns4";
		//screenSize  = window.innerWidth;
	} else if( document.all ) {
		//alert ("Running IE");
		layerRef    = "document.all";
		styleSwitch = ".style";
		visibleVar  = "visible";
		what        = "ie";
		//screenSize  = document.body.clientWidth + 18;
	} else if( document.getElementById ) {
		//alert ("Running Netscape 6");
		layerRef    = "document.getElementByID";
		styleSwitch = ".style";
		visibleVar  = "visible";
		what        = "moz";
	} else {
		//alert("Running browser older than 4.0");
		what       ="none";
		newbrowser = false;
	}
	
	check = true;
}


function positionLayer( strLayerName, strAnchorElement )
{
	//alert( "positionLayer()" );
	
	var currLeft = 0;
	var currTop  = 0;
	var currObj  = null;
	var numAnchorHeight = 0;
	objLayer  = document.getElementById( strLayerName );
	objAnchor = document.getElementById( strAnchorElement );
	
	if ( ! objLayer || ! objAnchor ) {
		return;
	}
	
	// Determine Position of anchor element
	if ( objAnchor.offsetParent ) {
		currLeft = objAnchor.offsetLeft;
		currTop  = objAnchor.offsetTop;
		currObj  = objAnchor;
		while ( currObj = currObj.offsetParent ) {
			currLeft += currObj.offsetLeft;
			currTop  += currObj.offsetTop;
		}
	}
	
	// Determine height of anchor element
	if ( objAnchor.offsetHeight ) {
		numAnchorHeight = objAnchor.offsetHeight;
	}
	
	if( check ) {
		if ( what == "none" ) {
			return;
		} else if ( what == "moz" ) {
			document.getElementById( strLayerName ).style.left = currLeft + "px";
			document.getElementById( strLayerName ).style.top  = ( currTop + numAnchorHeight - 3 ) + "px";
		} else {
			eval( layerRef + '["' + strLayerName + '"]' + styleSwitch + '.left="' + currLeft + '"' );
			eval( layerRef + '["' + strLayerName + '"]' + styleSwitch + '.top="'  + ( currTop + numAnchorHeight - 3 ) + '"' );
		}
	} else {
		// Wait for page to finish loading
		return;
	}
}


function showLayer( layerName )
{
	if( check ) {
		if ( what == "none" ) {
			return;
		} else if ( what == "moz" ) {
			document.getElementById(layerName).style.visibility = "visible";
		} else {
			eval( layerRef + '["' + layerName + '"]' + styleSwitch + '.visibility="' + "visible" + '"' );
		}
	} else {
		// Wait for page to finish loading
		return;
	}
}


function hideLayer( layerName )
{
	if( check ) {
		if ( what == "none" ) {
			return;
		} else if ( what == "moz" ) {
			document.getElementById(layerName).style.visibility = "hidden";
		} else {
			eval( layerRef + '["' + layerName + '"]' + styleSwitch + '.visibility="' + "hidden" + '"' );
		}
	} else {
		// Wait for page to finish loading
		return;
	}
}


function StartTime( layerName )
{
	if ( timerOn == false ) {
		timerID = setTimeout( "hideLayer('" + layerName + "')" , timecount );
		timerOn = true;
	}
}


function StopTime()
{
	if ( timerOn ) {
		clearTimeout( timerID );
		timerID = null;
		timerOn = false;
	}
}

