﻿function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	opacityPercentage = opacity/100;
  
	// IE/Win
  	obj.style.filter = "alpha(opacity="+opacity+")";
  
	// Safari<1.2, Konqueror
	obj.style.KhtmlOpacity = opacityPercentage;
  
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacityPercentage;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacityPercentage;
  
	document.currentopacity = opacity;
}

function fadeIn(o) {
	document.timeoutid = undefined;
	if (o <= 100) {
		setOpacity(document.maindiv, o);
		o += 10;
		document.timeoutid = window.setTimeout("fadeIn("+o+")", (o > 0) ? o/2.5 : 10);
	} else if (document.nextcommand != undefined) {
		document.timeoutid = window.setTimeout(document.nextcommand, 10);
		document.nextcommand = undefined;
	} else if (document.mainimage.className == 'slideshow') {
		document.slideshowindex++;
		if(document.slideshowindex >= document.slideshowimages.length) {
			document.slideshowindex = 0;
		}
		document.nextcommand = "switchMainImage('"+ document.slideshowimages[document.slideshowindex] +"')";
		document.timeoutid = window.setTimeout("fadeOut(100)", 3000);
	}
}


function fadeOut(o) {
	document.timeoutid = undefined;
	if (o >= 0) {
		setOpacity(document.maindiv, o);
		o -= 10;
		document.timeoutid = window.setTimeout("fadeOut("+o+")", (o > 0) ? o/2.5 : 10);
	} else if (document.nextcommand != undefined) {
		document.timeoutid = window.setTimeout(document.nextcommand, 25);
		document.nextcommand = undefined;
	}
}


function preloadImages() {
	load();
	if(document.images) {
		if(!document.plist) document.plist= {};
		var i,a=preloadImages.arguments; 
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) { 
				document.plist[a[i]]=new Image; 
				document.plist[a[i]].src=a[i];
				document.slideshowimages.push(a[i]);
	    	}
    }
}

function switchMainImage(i) {
	document.timeoutid = undefined;
	document.mainimage.width=document.plist[i].width;
	document.mainimage.height=document.plist[i].height;
	document.maindiv.style.width = "" + document.mainimage.width + "px";
	document.maindiv.style.height = "" + document.mainimage.height + "px";
	document.mainimage.src=document.plist[i].src;
	fadeIn(0);
}

function setMainImageURL(i) {
	if(document.timeoutid == undefined) {
		if(document.mainimage.src == document.plist[i].src) {
			if(document.currentopacity < 99) {
				fadeIn(document.currentopacity + 10);
			}
		} else {
			document.nextcommand = "switchMainImage('" + i + "')";
			fadeOut(document.currentopacity > 99 ? 100 : document.currentopacity);
		}
	} else {
		window.clearTimeout(document.timeoutid);
		document.timeoutid = undefined;
		document.nextcommand = undefined;
		window.setTimeout("setMainImageURL('" + i + "')",25);
	}
}

function load()
{
	document.timeoutid = undefined;
	document.nextcommand = undefined;
	document.currentopacity = 0;
	document.slideshowindex = 0;
	document.slideshowimages = [];
	document.mainimage = undefined;
	document.maindiv = undefined;
	
	// replace e-mail addresses
	var spans = document.getElementsByTagName("span")
	var addresses = new Array
	var phonenumbers = new Array
	
	for (var i = 0; i < spans.length; i++) {
		var addr = spans[i]
		var cls = addr.getAttribute("class")
		if (cls == null)
			cls = addr.getAttribute("className")
		if (cls == "four") {
			addresses.push(addr)
		} else if (cls == "five") {
			phonenumbers.push(addr)
		}
	}
	for (var i = 0; i < addresses.length; i++) {
		var addr = addresses[i]
		spans = addr.getElementsByTagName("span")
		var url = "";
		for (var j = 0; j < spans.length; j++) {
			var span = spans[j]
			var cls = span.getAttribute("class")
			if (cls == null)
				cls = span.getAttribute("className")
			switch (cls) {
				case "one":
					url += span.childNodes[0].nodeValue
				break;
				case "two":
					url += '.' + span.childNodes[0].nodeValue
				break;
				case "three":
					url += '@' + span.childNodes[0].nodeValue
				break;
			}
		}
		var newElem = document.createElement("a")
		newElem.setAttribute("href", "mailto:"+url)
		var newText = document.createTextNode(url)
		newElem.appendChild(newText)
		var parent = addr.parentNode
		var replaced = parent.replaceChild(newElem,addr)
	}
	
	// set up transitions
	// incl. workaround for IE RGB 2 5 10 bug
	document.mainimage = document.getElementById('main');
	if(document.mainimage) {
		var imageParent = document.mainimage.parentNode;
		document.maindiv = document.createElement("div");
		document.maindiv.id = 'imageframe';
		document.mainimage.style.filter = "alpha(opacity=100)";
		document.maindiv.style.backgroundColor = "#01050A";
		document.maindiv.style.position = "relative";
		document.maindiv.style.width = "" + document.mainimage.width + "px";
		document.maindiv.style.height = "" + document.mainimage.height + "px";
		document.maindiv.style.marginLeft = "auto";
		document.maindiv.style.marginRight = "auto";
		
		
		// create divs for drop shadow
		var element = document.createElement("div");
		element.setAttribute('class', 'lf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'rf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'tlf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'tf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'trf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'blf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'bf');
		document.maindiv.appendChild(element);
		element = document.createElement("div");
		element.setAttribute('class', 'brf');
		document.maindiv.appendChild(element);
		
		document.maindiv.appendChild(document.mainimage);
		imageParent.appendChild(document.maindiv);
			
		setOpacity(document.maindiv, 0);
		document.mainimage.style.visibility = "visible";
		document.maindiv.style.visibility = 'visible';
  		fadeIn(0);
	}
}


function unload()
{
	if(document.timeoutid != undefined) {
		window.clearTimeout(document.timeoutid);
		document.timeoutid = undefined;
	}
}

document.write("<style type='text/css'>#main { visibility: hidden; } </style>");

window.onload = load;
window.onunload = unload;

