//------------------------------------------------------------
// etracker - delay if etracker-server not reachable => start
//------------------------------------------------------------
var toSleep = true; function stopTimer(){toSleep=false;}
function clickTracker(LinkName){var secureID="CggCU3";
var redirectUrl="http://www.etracker.de/skin/de.def/img/1px.gif";
etrackerSink=new Image(1,1);toSleep=true;
etrackerSink.src="http://www.etracker.de/lnkcnt.php?et="+secureID+"&url="+
redirectUrl+"&lnkname="+LinkName;etrackerSink.onload=stopTimer;if(toSleep==true)
{maxDelay(500);}return true;}function maxDelay(gap){var then,now;then=new
Date().getTime();now=then; while( toSleep==true&&(now-then)<gap){now=new Date().
getTime();}}
//------------------------------------------------------------
// etracker - delay if etracker-server not reachable => end
//------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function resetRollover(imgName, imgSrc){
	var x;
	if ((x=MM_findObj(imgName))!=null) x.src = imgSrc;
}


/* funktionen fuer pulldowns */
function pdWrite(name, selected, options){
	pd = new Array();
	pd[name+'_timeout'] = null;
	
	
	document.write("<div style=\"position: absolute;\" id=\"pd-"+name+"-close\" class=\"pd-container pd-close\">");	
	document.write("	<a href=\"javascript:pdOpen('"+name+"');\">"+selected+"</a>");
	document.write("</div>");	
	
	document.write("<div id=\"pd-"+name+"-open\" class=\"pd-container pd-open\" onmouseover=\"pdStopTimer('"+name+"');\" onmouseout=\"pdStartTimer('"+name+"');\">");
	for (i=0; i<options.length; i+=2){
		if (options[i]==selected){
			document.write(" <span class=\"sub-selected\">"+options[i]+"</span>");
		} else {			
			document.write(" <a href=\""+options[i+1]+"\" onclick=\"javascript:pdClose('"+name+"');\">"+options[i]+"</a>");
		}
	}	
	document.write("</div>");
	// folgende zeile, um die hoehe des pulldowns zu gewaehren	
	document.write("&nbsp;");	
}

function pdStartTimer(pdName){
	pd[name+'_timeout'] = setTimeout("pdClose('"+pdName+"');", 1000);
}

function pdStopTimer(pdName){
	clearTimeout(pd[name+'_timeout']);
}

function pdOpen(pdName){						
	MM_showHideLayers('pd-'+pdName+'-close','','hide');
	MM_showHideLayers('pd-'+pdName+'-open','','show');
}

function pdClose(pdName){
	MM_showHideLayers('pd-'+pdName+'-close','','show');
	MM_showHideLayers('pd-'+pdName+'-open','','hide');
}

// simpler popup-opener (z.b. lexikon)
function openpopup(path, name, param){
	popwin=window.open(path, name, param);
	popwin.focus();
}

/* externe links */
function setExternTargets(){
	/* links mit rel="external" bekommen einen target=blank */
	if (typeof document.getElementsByTagName == "function"){
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i < anchors.length; i++) {
	 		var anchor = anchors[i];
	 		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	 	}
	}
}

// prueft die maximal-laenge eines feldes..
function checkMax(field, max, language) {
	var fieldLength = field.value.length;
	if (fieldLength>max) {
		field.value = field.value.substr(0,max);
		alert('Es sind max. '+max+' Zeichen erlaubt.');
	}
}
function showPopup (targetObjectId, eventObj, posi) {
	
    if (posi==1)
    {
			// store variables to control where the popup will appear relative to the cursor position
			// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
			var xOffset = -300;
			var yOffset = 150;    	
    }
    else
    {
			var xOffset = -450;
			var yOffset = 150;  			    	
    }
    
    if(eventObj) {
    	
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	//var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);	
	//moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	moveObject(targetObjectId, newXCoordinate, yOffset);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object	    
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
		
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
	
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject



/* sticky footer */

/**
 * Prueft, ob der verwendete Browser Internet Explorer 6 oder aelter ist.
 * @return boolean true, wenn User Agent IE6 oder aelter ist, sonst false
 */
function isIE6OrLess(){
	var agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	return (is_ie && (is_major == 4) && (agt.search(/msie [56]\./)!=-1) );
}

$(document).observe("dom:loaded", function() {
	
	// wenn wir mit nem normalen Browser hier sind, initialisiere
	// die dynamischen Funktionalitaeten der Seite
	if (!isIE6OrLess()) {
		
		// Füge dem body Klasse hinzu, damit im CSS zwischen JS und
		// Non-JS unterschieden werden kann
		$(document.body).addClassName('dynd');
		
		// initialisiere globales Overlay
		if ($('overlay')) 
			window.overlay = new Overlay($('overlay'));

		// initialisiere das Layer am Footer bei Klick auf Fingerstern
		if ($('layertrigger') && $('sternlayer')) {
			$('layertrigger').observe('click', function(event) {
				event.stop();
				if (overlay.show($('sternlayer'))) {
					$('sternlayer').down('h2.akm').writeAttribute('tabindex', "-1");
				}
			});
			
			$('sfooterlogo').observe('mouseover', function(event) {
				Effect.Queues.get('sfooter').each(function(effect) { effect.cancel(); });

				new Effect.Parallel([
						new Effect.Morph($('layertrigger').down("img"), {
							style: "width:142px;",
							sync: true
						}),
						new Effect.Morph($('sfooterlogo'), {
							style: "top:-20px;",
							sync: true
						})
					], {
						duration:0.5,
						delay:0.1,
						queue: {
							scope:'sfooter'
						}
					}
				);
			});
			
			$('sfooterlogo').observe('mouseout', function(event) {
				Effect.Queues.get('sfooter').each(function(effect) { effect.cancel(); });
				
				new Effect.Parallel([
						new Effect.Morph($('layertrigger').down("img"), {
							style: "width:75px;",
							sync: true
						}),
						new Effect.Morph($('sfooterlogo'), {
							style: "top:0px;",
							sync: true
						})
					], {
						duration:0.5,
						delay:0.1,
						queue: {
							scope:'sfooter'
						}
					}
				);
			});
		}
	}
});




var Overlay = Class.create({
	initialize: function(elm) {
		this.element = $(elm).hide();
		this.open = false;
		this.content = null;
		this.lastContent = null;
		
		this.element.observe('click', function(event) {
			event.stop();
			this.hide();
		}.bind(this));
	},
	show: function(content) {
		this.content = content;
		if (!this.open && this.content) {
			
			this.element.setStyle({
				height: ( Math.max($(document.viewport).getHeight(), $(document.body).getHeight()) )+"px"
			});
			
		
			this.element.appear({
				duration: 0.4,
				to:0.8,
				afterFinish: function() {
					this.open = true;
					document.fire("overlay:opened");
					
					if (this.content) {
						this.content.appear({duration:0.4});
					}
					
				}.bind(this)
			});
			
			this.lastContent = this.content;
			return true;
		}
		else if(this.content && this.content != this.lastContent) {
			this.lastContent.fade({duration:0.4});
			this.content.appear({duration:0.4});
			this.lastContent = this.content;
			return true;
		}
		else {
			return false;
		}
	},
	hide: function() {
		if (isIE6OrLess()) {
			return true;
		}
		
		if (this.open) {
			if (this.content) {
				this.content.fade({duration:0.4});
			}
			
			this.element.fade({
				duration: 0.4,
				afterFinish: function() {
					this.open = false;
					document.fire("overlay:closed");
				}.bind(this)
			});
			return true;
		}
		else {
			return false;
		}		
	}
});