// JavaScript Document
function gE(id) { return document.getElementById(id); }

function init() {
	var alle = gE('inhalt').getElementsByTagName('IMG');
	for(i=0;i<alle.length;i++) {
		if (alle[i].className.indexOf('bild_') == 0) {
			alle[i].setAttribute('title','anklicken zum Vergrößern');
			alle[i].style.cursor = 'pointer';
		}
	}
}

function getPos(ob) {
	var x=0, y=0;
	do {
		x += ob.offsetLeft || 0;
		y += ob.offsetTop || 0;
//		x -= ob.scrollLeft || 0;
//		y -= ob.scrollTop || 0;
		ob = ob.offsetParent || 0;
	} while (ob);
	return [x,y];
}
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 x1,x2,y1,y2,w1,w2,h1,h2,v_dauer;
v_start = 0;
v_dauer_wachsen = 500;
v_dauer_schrumpfen = 300;
v_step = 20;
var vis = false;
var vis_2 = false;
function picBig(e) {
	e = (window.event)?window.event:e;
	var o = (window.event)?e.srcElement:e.target;
	var zeit = new Date(); zeit = zeit.getTime();
	var pop = gE('bild_pop');
	if (o.className.indexOf('bild_') == 0 && !vis) {
		var wd = wDim();
		var p = getPos(o);
		var ws = wScroll();
		var img = new Image();
		img.src = o.src;
		x1 = p[0];
		y1 = p[1];
		w1 = o.width;
		h1 = o.height;
		x2 = Math.floor(wd[0]/2-img.width/2+ws[0]);
		y2 = Math.floor(wd[1]/2-img.height/2+ws[1]);
		w2 = img.width;
		h2 = img.height;
		v_start = zeit;
		pop.src = o.src;
		v_dauer = v_dauer_wachsen;
		o.style.visibility = 'hidden';
		vis = o;
		setTimeout('picFlow()',v_step);
	} else if (vis) {
		var t;
		t=x1;x1=x2;x2=t;
		t=y1;y1=y2;y2=t;
		t=w1;w1=w2;w2=t;
		t=h1;h1=h2;h2=t;
		if (zeit-v_start < v_dauer)
			v_start = zeit-(zeit-v_start)/v_dauer_wachsen*v_dauer_schrumpfen;
		else
			v_start = zeit;
		v_dauer = v_dauer_schrumpfen;
		setTimeout('picFlow()',v_step);
	}
}
function picFlow() {
	var pop = gE('bild_pop');
	var zeit = new Date(); zeit = zeit.getTime();
	var diff = zeit - v_start;
	if (diff < v_dauer) {
		//var scale = diff/v_dauer; // linear
		var scale = Math.sin(diff/v_dauer*Math.PI/2);
		pop.style.left = Math.floor((x2-x1)*scale)+x1+'px';
		pop.style.top = Math.floor((y2-y1)*scale)+y1+'px';
		pop.style.width = Math.floor((w2-w1)*scale)+w1+'px';
		pop.style.height = Math.floor((h2-h1)*scale)+h1+'px';
		setTimeout('picFlow()',v_step);
		pop.style.display = 'block';
	} else {
		pop.style.left = x2+'px';
		pop.style.top = y2+'px';
		pop.style.width = w2+'px';
		pop.style.height = h2+'px';
		if (w1 > w2) {
			pop.style.display = 'none';
			v_start = 0;
			if (vis) {
				vis.style.visibility = 'visible';
				vis.blur();
			}
			vis = false;
		}
	}
}

document.onclick = picBig;

