window.addEvent('domready', function() {

//	Avoid framing
	if(top!=self) top.location=self.location;

//	Set random key visual
	//var randVis = Math.floor(Math.random()*10) + 1;
	//document.getElementById('row-mid').style.background = "url(/images/visual-" + randVis + ".jpg) no-repeat -1000px 0";

//	Position key visual
	function posVisual() {
		var area = document.getElementById('visual-area').offsetWidth;
		document.getElementById('row-mid').style.backgroundPosition = area - 700 + "px 0";
	}
	posVisual();
	window.onresize = posVisual;

// 	Image roll over
	$$('img.mo').each(function(img) {
		var src = img.getProperty('src');
		var extension = src.substring(src.lastIndexOf('.'),src.length);
		// Preload the image
		new Asset.image([src.replace(extension,'-on' + extension)]);
		img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'-on' + extension)); });
		img.addEvent('mouseleave', function() { img.setProperty('src',src); });
	});

//	Fix IE title-as-tooltip-bug
	if(Browser.Engine.trident) {
		// detect support
		if(!document.getElementById || !document.getElementsByTagName) return;
		var imgs = document.getElementsByTagName("img");
		if(!imgs) return;
		for(var i=0; i<imgs.length; i++) {
			var elImg = imgs[i];
			// if there isn't already a title attribute set on the image, set the title attribute to blank, thus overriding the alt tooltip behaviour
			// use == '' because IE always thinks title is a string (cannot distinguish between undefined and empty attributes)
			if(elImg.getAttribute('title') == '') elImg.setAttribute('title','');
		}
	}

//	Manipulate links
	function Links() {
		if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for(var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			/*anchor.tabindex = i;*/
			if (anchor.getAttribute("href")) {
				anchor.onfocus = function() {
					this.blur();
				}
				if (anchor.className.search(/link-extern/) != -1 || anchor.className.search(/link-download/) != -1) {
					anchor.target = "_blank";
					if (document.getElementsByTagName("html")[0].lang == "en") {
						if (!anchor.title) anchor.title = "open in new window"
						else anchor.title += " (new window)";
					}else {
						if (!anchor.title) anchor.title = "in neuem Fenster öffnen"
						else anchor.title += " (neues Fenster)";
					}
				}
			}
		}
		var forms = document.getElementsByTagName("form");
		for(var i=0; i<forms.length; i++) {
			var form = forms[i];
			if (form.getAttribute("rel") == "ext") {
				form.target = "_blank";
			}
		}
	}
	Links();

});


//	E-Mail Obfuscation
/*
 *  Written by: Florian Wobbe
 *  Contact: www.eprofs.de
 *  Created: 2008-01-12 - v1.1
 *  Modified: 2008-01-17 - v1.2 - Email encoding
 *  Modified: 2008-01-19 - v1.3 - Custom Base64 encoding
 *  For: MODx cms (modxcms.com)
 *  Name: emo - E-Mail Obfuscation
 *  Description: These javascript functions replace html placeholder span elements with decrypted email addresses.
 *  License: GPL
 */
//	Decrypt all email addresses
	function emo_replace() {
		for (var i = 1; i < emo_addresses.length; i++) {
			var id = '_emoaddrId' + i;
			var elem = document.getElementById(id);
			if (elem) {
				if (elem.firstChild) {
					elem.removeChild(elem.firstChild);
				}
				elem.innerHTML = decrypt_string(i);
			}
		}
//	UNORM: Spezialbehandlung für verlinktes Bild
// 		var id =  emo_addresses.length - 1;
// 		id = 'emo_addr_' + id;
// 		document.getElementById(id).className = "image-link";
// 		var myimg = document.createElement("img");
// 		myimg.src= "/images/foot-mail.gif";
// 		myimg.width= 96;
// 		myimg.height = 22;
// 		myimg.className = "mo";
// 		document.getElementById(id).removeChild(document.getElementById(id).firstChild);
// 		document.getElementById(id).appendChild(myimg);
//	Image roll over
// 		$$('img.mo').each(function(img) {
// 			var src = img.getProperty('src');
// 			var extension = src.substring(src.lastIndexOf('.'),src.length);
// 			// Preload the image
// 			new Asset.image([src.replace(extension,'-on' + extension)]);
// 			img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'-on' + extension)); });
// 			img.addEvent('mouseleave', function() { img.setProperty('src',src); });
// 		});
	}
//	Manage decryption cache
	var decryption_cache = new Array();
	function decrypt_string(n) {
	  var cache_index = "'"+n+"'";
	
	  if(decryption_cache[cache_index])			// If this string has already been decrypted, just
		return decryption_cache[cache_index];	// return the cached version.
	
	  if(emo_addresses[n])						// Is crypted_string an index into the addresses array?
		var crypted_string = emo_addresses[n];
	
	  if(!crypted_string.length)				// Make sure the string is actually a string
		return "Error, not a valid index.";
	
	  var decrypted_string = decode_base64(crypted_string);
	
	  // Cache this string for any future calls
	  decryption_cache[cache_index] = decrypted_string;
	
	  return decrypted_string;
	}
//	Custom base 64 decoding
	function decode_base64(data) {
	  var tab = emo_addresses[0];
	  var out = "", c1, c2, c3, e1, e2, e3, e4;
	  for (var i = 0; i < data.length; ) {
		e1 = tab.indexOf(data.charAt(i++));
		e2 = tab.indexOf(data.charAt(i++));
		e3 = tab.indexOf(data.charAt(i++));
		e4 = tab.indexOf(data.charAt(i++));
		c1 = (e1 << 2) + (e2 >> 4);
		c2 = ((e2 & 15) << 4) + (e3 >> 2);
		c3 = ((e3 & 3) << 6) + e4;
		out += String.fromCharCode(c1);
		if (e3 != 64)
		  out += String.fromCharCode(c2);
		if (e4 != 64)
		  out += String.fromCharCode(c3);
	  }
	  return out;
	}

