var imgs = new Array();
var current = 0;
var ma_is_selected;

function showContent(link) {
	/*$('content').fade({duration: 0.5});
	window.setTimeout("loadNewContent('"+link+"')",500);*/
	loadNewContent(link);
}

function loadNewContent(link) {
	window.location.href = link;
}

function showContentRight(link) {
	/*$('content_right').fade({duration: 0.5});
	window.setTimeout("loadNewContent('"+link+"')",500);*/
	loadNewContent(link);
}

function showMA(username,name,tel,email,anmerkung,hasPic) {
	var pic1 = "./images/team/"+username+"1.jpg";
	var pic2 = "./images/team/"+username+"2.jpg";
	
	if(!hasPic) {
		pic1 = "./images/trans.gif";
		pic2 = "./images/trans.gif";
	}
	
	// container ausleeren
	while($(content_right).firstChild) { $(content_right).removeChild($(content_right).firstChild); }
	
	var image_container = document.createElement("div");
	image_container.id = "image_container";
	
	var image1 = document.createElement("img");
	
	image1.src = pic1;
	image1.id = "image1";
	image1.style.display = "none";
	image1.style.position = "absolute";
	image1.style.top = image_container.style.top;
	image1.style.left = image_container.style.left;
	
	var image2 = document.createElement("img");
	image2.src = pic2;
	image2.id = "image2";
	image2.style.display = "none";
	image2.style.position = "absolute";
	image2.style.top = image_container.style.top;
	image2.style.left = image_container.style.left;
	
	image_container.appendChild(image1);
	image_container.appendChild(image2);
	
	$(content_right).appendChild(image_container);
	$("image1").appear({duration: 0.3});
	window.setTimeout("so_init();",300);
	
	var text_container = document.createElement("div");
	var name_container = document.createElement("div");
	name_container.appendChild(document.createTextNode(name));
	name_container.style.fontSize="20px";
	text_container.appendChild(name_container);
	if(tel.length>0) {
		text_container.appendChild(document.createTextNode(tel));
		text_container.appendChild(document.createElement("br"));
	}
	if(email.length>0) {
		var email_link = document.createElement("a");
		email_link.href = "mailto:" + email;
		email_link.appendChild(document.createTextNode(email));
		text_container.appendChild(email_link);
		text_container.appendChild(document.createElement("br"));
	}
	
	if(anmerkung.length>0) text_container.appendChild(document.createTextNode(anmerkung));
	text_container.style.position = "relative";
  // Ticket#2012010210000677
	text_container.style.top = "420px";
	text_container.style.zIndex = "2";
	
	if(ma_is_selected) {
		document.getElementById("link_to_"+ma_is_selected).style.color = 'black';
		document.getElementById("link_to_"+ma_is_selected).style.backgroundColor = 'transparent';
	}
	ma_is_selected = username;
	var ma_link = document.getElementById("link_to_"+username);
	ma_link.style.color = "white";
	ma_link.style.backgroundColor = "black";
	
	
	
	$(content_right).appendChild(text_container);
}

function so_init() {
	var d = document;
	if(!d.getElementById || !d.createElement)return;


	imgs = d.getElementById("image_container").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	//setTimeout(so_xfade,1000);
	imgs[0].onmouseover = function() { so_xfade(); }
	imgs[1].onmouseout = function() { so_xfade(); }
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		//setTimeout(so_xfade,1000);
	} else {
		setTimeout(so_xfade,20);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}

function showMap(image,url) {
	var container = document.getElementById("content_right");
	while(container.firstChild) { container.removeChild(container.firstChild); }
	container.style.display='table-cell';
	container.style.verticalAlign="middle";
	container.style.textAlign='center';
	var link = document.createElement("a");
	link.href=url;
	var image = document.createElement("img");
	image.border=0;
	image.href=image;
	link.appendChild(image);
	container.appendChild(link);
}

function so_xfade_cust(imgs,current) {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		//setTimeout(so_xfade,1000);
	} else {
		setTimeout(so_xfade_cust(imgs,current),30);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}



function flag_animation() {
		var links = document.getElementsByTagName("a");
		for(var c=0; c < links.length; c++) {
			if(links[c].firstChild && links[c].firstChild.nodeValue == 'Deutsch') {
				links[c].onmouseover = show_flag;
				
			}
			else if(links[c].firstChild && links[c].firstChild.nodeValue == 'English') {
				links[c].onmouseover = show_flag;
				
			}
		}
}

function show_flag() {
	if(this.firstChild.nodeValue == 'Deutsch') var current_flag = "deutsch.gif";
	if(this.firstChild.nodeValue == 'English') var current_flag = "english.gif";
	
	var link = this;
	var img_url = "./images/"+current_flag;
	var img = document.createElement("img");
	img.id = current_flag;
	img.src = img_url;
	img.style.position="absolute";
	setOpa(img,0);
	img.style.zIndex = "-2";
	img.style.top='220px'; img.style.left='220px';
	document.body.appendChild(img);
	new Effect.Opacity(current_flag, { from:0, to: 0.1, duration: 0.4});
	link.onmouseout = hide_flag;
	link.onclick = hide_flag;
}

function hide_flag() {
	if(this.firstChild.nodeValue == 'Deutsch') var current_flag = "deutsch.gif";
	if(this.firstChild.nodeValue == 'English') var current_flag = "english.gif";
	new Effect.Opacity(current_flag, { from:0.1, to: 0, duration: 0.4});
}


function setOpa(node,opa) {
	node.style.opacity = opa;
	node.style.MozOpacity = opa;
	node.style.filter = "alpha(opacity=" + (opa*100) + ")";
}

var is_fading = new Array();

function changePic(name) {
	
	var event;
	if(!name) name=window.event; // thx IE -.-
	if(typeof(name)=='object') {
		var treffer = this.id.match(/^(.+?)\d\.jpg/);
		event=name;
		name=treffer[1];
	}
	
	for(var c=0; c < is_fading.length; c++) {
		if(is_fading[c] == name) { return; }
	}
	
	
	is_fading.push(name);

	var dir = "./images/team/vorstand/";
	var container = $(name+"_pic_container");
	var current; var next;
	current=1; next=2;
	
	if(event && event.type == 'mouseout') {
		current = 2; next = 1;
	}
	if(event && event.type == 'mouseover') {
		current = 1; next = 2;
	}
	
	var image = $(name+current+'.jpg');
	var new_image = $(name+next+'.jpg');
	
	$(name+"2.jpg").onmouseout = changePic;
	$(name+"1.jpg").onmouseover = changePic;

	image.fade({duration: 0.4,afterFinish: function(obj) {
				
		for(var c=0; c < is_fading.length; c++) {
			if(is_fading[c] == name) { is_fading[c] = undefined; }
		}
	
	}});
	new_image.appear({duration: 0.3});
}

function renderBackground(url,pos) {
	var image_container = document.createElement("div");
	
	var image = document.createElement("img");
	image.style.height="361px";
	image.style.width="450px";
	image.width="450";
	image.height="361";
	image.style.position="relative";
	image.style.zIndex="1";
	image.src = url;
	setOpa(image,0.4);
	
	image_container.style.zIndex="1";
	image_container.style.position="absolute";
	
	image_container.style.width="450px";
	image_container.style.height="361px";
	
	
	if(pos=="ro") {
		image_container.style.top="5px";
		image_container.style.left="450px";
	}
	else if(pos=="lo") {
		image_container.style.top="8px";
		image_container.style.left="100px";
	}
	else if(pos=="lu") {
		image_container.style.top="200px";
		image_container.style.left="100px";
	}
	else if(pos=="ru") {
		image_container.style.top="198px";
		image_container.style.left="450px";	
	}
	
	image_container.id="background_image_container";
	image_container.appendChild(image);
	$("buch").appendChild(image_container);

	if(document.all) {
		$("content").style.display="none";
		window.setTimeout("$('content').style.display='block';",0);	
	}
	
}

