// JavaScript Document
function gE(id){return document.getElementById(id);}
function wDim() {
	var x,y;
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}
function wScroll() {
	var x,y;
	if (window.pageXOffset) {
		x = window.pageXOffset;
		y = window.pageYOffset;
	} else {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	return [x,y];
}


var Dpics = new Array(); // Liste aller Bilder auf der Seite, die in "diashow"s stehen
var Dpos = 0; // letzte Position in Dpics
window.onload = D_init;
function D_init() {
	var p_s = document.getElementsByTagName('p');
	for (var i=0;i<p_s.length;i++) {
		if (p_s[i].className == 'diashow') {
			var i_s = p_s[i].getElementsByTagName('img');
			for (var j=0;j<i_s.length;j++) {
				if (i_s[j].parentNode.tagName == 'A') {
// 					alert(i_s[j].parentNode.href);
					var pic = new Object();
					pic.src = i_s[j].parentNode.href;
					pic.title = i_s[j].title;
					pic.width = 1000; // geschätzte Größe
					pic.height = 667;
					if (!pic.title.length)
						pic.title = i_s[j].alt;
					Dpics.push(pic);
					i_s[j].parentNode.onclick = new Function("return D_show("+(Dpics.length-1)+")");
				}
			}
		}
	}
	if (Dpics.length) {
		var o;
		o = document.createElement('div');
		o.id = 'abdunkeln';
		o.onclick = D_close;
		document.body.insertBefore(o,document.body.firstChild);

		o = document.createElement('div');
		o.id = 'bild_nav';
		o.innerHTML = '<span onclick="D_show(Dpos-1)">&larr;</span><span onclick="D_show(Dpos+1)">&rarr;</span>';
		document.body.insertBefore(o,document.body.firstChild);

		o = document.createElement('div');
		o.id = 'bild_title';
		document.body.insertBefore(o,document.body.firstChild);

		o = document.createElement('img');
		o.id = 'bild_pop';
		o.title = 'zum Verkleinern anklicken';
		o.onclick = D_close;
		document.body.insertBefore(o,document.body.firstChild);
	}
}
function D_show(p) {
	var pop = gE('bild_pop');
	if (pop.src.length) { // Bild ist bereits geladen
		Dpics[Dpos].width = pop.width;
		Dpics[Dpos].height = pop.height;
	}
	Dpos = (p+Dpics.length)%Dpics.length;
	var img = Dpics[Dpos];
	var wd = wDim();
	var ws = wScroll();
	var x2 = Math.floor(wd[0]/2-img.width/2+ws[0]);
	var y2 = Math.floor(wd[1]/2-img.height/2+ws[1]);
	if (x2 < 0) x2 = 0;
	if (y2 < 0) y2 = 20;
	pop.src = img.src;
	pop.style.left = x2+'px';
	pop.style.top = y2+'px';
	pop.style.display = 'block';
	gE('abdunkeln').style.display = 'block';
	var nav = gE('bild_nav')
	nav.style.left = (x2+15)+'px';
	nav.style.top = (y2+15)+'px';
	nav.style.display = 'inline-block';
	var tit = gE('bild_title')
	tit.style.display = 'none';
	if (img.title.length) {
		tit.style.left = (x2+15)+'px';
		tit.style.top = (y2-26)+'px';
		tit.innerHTML = img.title;
		tit.style.display = 'inline-block';
	}
// 	alert(Dpics[p].src);
	return false;
}
function D_close() {
	gE('bild_pop').style.display = 'none';
	gE('abdunkeln').style.display = 'none';
	gE('bild_nav').style.display = 'none';
	gE('bild_title').style.display = 'none';
}

