var iLayerDirection = 0;

var iLayerDelta = 30; // Einfahrzeit
var iLayerStart = -3090; // Ausgangapunkt
var iLayerEnd = 10;
var iLayerPosition = 20;

var iLayerTimer = 50;
var iLayerScrollCheck = 1;
var iLayerStartDelay = layerDelay;
var bLayerCheckScrolling = false;

if(CookieExists() == false)
{
	if(typeof(layerWidth) == 'undefined') var layerWidth = 980;
	if(typeof(layerHeight) == 'undefined') var layerHeight = 650;
	
	document.write('<style type="text/css">\n.layerMainContainer { position:absolute; display:block; border: 1px solid black; text-align: center; background-color: white; z-index: 10000; width:' + layerWidth + 'px; }\n.layerUpperBar { background:#0E2E7B;width: 100%; height: 21px; padding: 0px; border-bottom: 1px solid black; z-index: 10001; overflow: hidden;}\n.layerUpperBarTeaser { float: left; margin-top: 3px; margin-right: 3px; margin-left:10px; }\n.layerUpperBarButtons { float: right; margin-top: 3px; margin-right: 3px; }\n.layerLowerBar { background:#0E2E7B;width: 100%; height:21px; padding:0px; border-top: 1px solid black; z-index: 10001; overflow: hidden; }\n.layerLowerBarTeaser {float: left; margin-top:2px; margin-left:10px;}\n.layerLowerBarButtons {float: right; margin-top: 2px; margin-right: 3px;}\n</style>');
	document.write('<div id="myLayer" class="layerMainContainer">');
	document.write('<div id="bar_up" class="layerUpperBar">');
	document.write('<span class="layerUpperBarTeaser">');
	document.write('<a href="' + layerLink + '" target="_blank" onclick="javascript:layerHideAndOpen(); return false;" style="position:static; font:10pt tahoma, verdana, arial, helvetica; color:#ffd600; font-weight:bold; text-decoration:none;" alt="' + layerText + '" title="' + layerText + '">' + layerText + '</a>');
	document.write('</span>');
	document.write('<span class="layerUpperBarButtons">');
	document.write('<a href="#" onclick="return hideLayer()" style="position: static;">');
	document.write('<font style="position:static; font:9pt tahoma, verdana, arial; color:#888888; text-decoration:none;">schliessen</font></a>&nbsp;&nbsp;');
	document.write('</span>');
	document.write('</div>');
	document.write('<div>');
	document.write('<iframe src="'+layerSource+'" border:none; width="100%" frameborder="0" height="' + layerHeight + '" name="'+layerLink+'">');
	document.write('</div>');
	document.write('</div>');
}

function getTheElement(sId)
{
	if (document.getElementById) {
		return document.getElementById(sId)
	}
	else if (document.all) {
		return document.all[sId]
	}
	else if (document.layers) {
		return document.layers[sId]
	}
}

function moveLayer()
{
	myLayer.style.display = 'block';
	if (iLayerDirection == 0 && getX(myLayer) < iLayerEnd) {
		myLayer.style.left = Math.min(iLayerEnd, getX(myLayer) + iLayerDelta) + 'px';
		if (getX(myLayer) < iLayerEnd) {
			setTimeout("moveLayer()", iLayerTimer);
		}
	}
	else if (iLayerDirection == 1 && getY(myLayer) < iLayerEnd) {
		myLayer.style.top = Math.min(iLayerEnd, getY(myLayer) + iLayerDelta) + 'px';
		if (getY(myLayer) < iLayerEnd) {
			setTimeout("moveLayer()", iLayerTimer);
		}
	}
}

function getX(el)
{
	if (el.offsetParent) {
		return (el.offsetLeft + getX(el.offsetParent));
	}
	else {
		return (el.offsetLeft);
	}
}

function getY(el)
{
	if (el.offsetParent) {
		return (el.offsetTop + getY(el.offsetParent));
	}
	else {
		return (el.offsetTop);
	}
}

function layerHideAndOpen()
{
	hideLayer()
	window.open(layerLink);
	return false;
}

function hideLayer()
{
	removeLayer();
	setCookie();	
	return false;
}

function CookieExists()
{
	if(document.cookie.search(/layerDisplay/) != -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function setCookie()
{		
	var expires = new Date();
	expires.setTime(expires.getTime() + (60 * 60 * 1000));
	document.cookie = "layerDisplay; expires=" + expires.toGMTString() +";path=/;";
}

function removeLayer()
{
	if (iLayerDirection == 0 && getX(myLayer) > iLayerStart) {
		myLayer.style.left = Math.max(iLayerStart, getX(myLayer) - iLayerDelta) + 'px';
	}

	if (iLayerDirection == 1 && getY(myLayer) > iLayerStart) {
		myLayer.style.top = Math.max(iLayerStart, getY(myLayer) - iLayerDelta) + 'px';
	}

	if (iLayerDirection == 0) {
		if (getX(myLayer) > iLayerStart) {
			setTimeout("removeLayer()", iLayerTimer);
		}
		else {
			myLayer.style.display = 'none';
			bLayerCheckScrolling = true;
		}
	}
	else if (iLayerDirection == 1) {
		if (getY(myLayer) > iLayerStart) {
			setTimeout("removeLayer()", iLayerTimer);
		}
		else {
			myLayer.style.display = 'none';
			bLayerCheckScrolling = true;
		}
	}
}

function startLayer()
{
	bLayerCheckScrolling = true;
	checkScroll();
	if (iLayerDirection == 0) {
		myLayer.style.left = iLayerStart + 'px';
		myLayer.style.top = iLayerPosition + 'px';
	}
	if (iLayerDirection == 1) {
		myLayer.style.top = iLayerStart + 'px';
		myLayer.style.left = iLayerPosition + 'px';
	}
	setTimeout("moveLayer()", iLayerStartDelay);
}

function checkScroll()
{
	if (!bLayerCheckScrolling) return;
	if(document.all)
	{
		if (document.documentElement && document.documentElement.scrollTop) {
			pos = document.documentElement.scrollTop
		}
		else if (document.body)	{
			pos = document.body.scrollTop
		}

		if (iLayerDirection == 0) {
			m = iLayerEnd;
		}
		else {
			m = iLayerPosition;
		}
		myLayer.style.top = pos + m + 'px';
		setTimeout("checkScroll()", iLayerScrollCheck);
	}
	else {
		myLayer.style.position = 'fixed';
	}
	
}

if(CookieExists() == false)
{
	var myLayer = getTheElement('myLayer');
	
	startLayer();
}

