var timerOpacTable;
var opacity = 0;
var pictureId, pictureCnt, divTrans, tableZoom, picZoom, trPicTxt, tdPicTxt1, tdPicTxt2;

function doZoom(picId)
{
	divTrans = document.getElementById("divTrans");
	tableZoom = document.getElementById("tableZoom");
	picZoom = document.getElementById("picZoom");
	trPicTxt = document.getElementById("picTxt");
	tdPicTxt1 = document.getElementById("picTxt1");
	tdPicTxt2 = document.getElementById("picTxt2");
	
	pictureId = picId;
	pictureCnt = getPicCnt(picId);
	
	setOpac(divTrans, 0);

	divTrans.style.display = "block";

	timerOpac = setInterval("doBgGray()", 10);
}

function doBgGray()
{
	opacity = opacity + 12;
	
	setOpac(divTrans, opacity);
	
	if (opacity == 84) {
		clearInterval(timerOpac);
		timerOpac = false;
		opacity = 0;
		setTimeout("showPic()", 200);
	}
}

function setOpac(obj, opac)
{
	obj.style.filter = "alpha(opacity=" + String(opac) + ")";
	obj.style.MozOpacity = String(opac / 100);
	obj.style.opacity = String(opac / 100);
//	obj.style.KHTMLOpacity = String(opac / 100);
}


function showPic()
{
	tableZoom.style.display = "block";
	setPic(pictureId);
}

function setPic(picId)
{
	var picSrc, heightSrc, widthSrc, heightZoom, widthZoom, browser, txtCnt;
	browser = navigator.appName;
	
	picSrc = document.getElementById("pic" + String(picId)).src;

	heightSrc = document.getElementById("pic" + String(picId)).height;
	widthSrc = document.getElementById("pic" + String(picId)).width;
	
	heightZoom = 400;		//picZoom.height;
	widthZoom = heightZoom / heightSrc * widthSrc;
	
	picZoom.style.width = widthZoom;
	tableZoom.style.left = String((document.body.clientWidth - widthZoom - 20) / 2)+"px";
	tableZoom.style.width = widthZoom + 20;		// bild hat links+rechts 10px abstand

	picZoom.src = picSrc;
	
	txtCnt = 0;
	
	if (document.getElementById("txt1_" + String(picId))) {
		txtCnt++;
	}
	if (document.getElementById("txt2_" + String(picId))) {
		txtCnt++;
	}
	
	if (txtCnt > 0) {
		trPicTxt.style.display = (browser == "Netscape" ? "table-row" : "block");
		
		if (document.getElementById("txt1_" + String(picId))) {
			tdPicTxt1.style.display = (browser == "Netscape" ? "table-cell" : "inline");
			tdPicTxt1.innerHTML = document.getElementById("txt1_" + String(picId)).innerHTML;
			tdPicTxt1.style.width = String(widthZoom / txtCnt) + "px";
		}
		else {
			tdPicTxt1.style.display = "none";
		}
	
		if (document.getElementById("txt2_" + String(picId))) {
			tdPicTxt2.style.display = (browser == "Netscape" ? "table-cell" : "inline");
			tdPicTxt2.innerHTML = document.getElementById("txt2_" + String(picId)).innerHTML;
			tdPicTxt2.style.width = String(widthZoom / txtCnt) + "px";
		}
		else {
			tdPicTxt2.style.display = "none";
		}
	}
	else {
		trPicTxt.style.display = "none";
	}
}

function doClose()
{
	divTrans.style.display = "none";
	tableZoom.style.display = "none";
}

function doPrev()
{
	pictureId--;
	if (pictureId == 0) {
		pictureId = pictureCnt;
	}
	setPic(pictureId);
}

function doNext()
{
	pictureId++;
	if (pictureId > pictureCnt) {
		pictureId = 1;
	}
	setPic(pictureId);
}

function getPicCnt(startId)
{
	var id, picCnt;
	id = startId;
	picCnt = 0;
	while (true) {
		id++;
		if (!document.getElementById("pic" + String(id))) {
			picCnt = id-1;
			break;
		}
		
	}
	return picCnt;
}

function scrollObj(scrollname, div_name, left_name, right_name) {
	this.div_name = div_name;
	this.name = scrollname;
	this.scrollCursor = 0;
	this.speed_normal = 10;
	this.speed_max = 40;
	this.speed = this.speed_normal;
	this.doAcc = false;
	this.accInterval = 1;	// higher number = slower acceleration
	this.accCount = 0;
	this.timeoutID = 0;
	this.div_obj = null;
	this.left_name = left_name;
	this.right_name = right_name;
	
	{
		if (document.getElementById) {
			div_obj = document.getElementById(this.div_name);
			if (div_obj) {
				this.div_obj = div_obj;
				this.div_obj.style.overflow = 'hidden';
			}
			div_left_obj = document.getElementById(this.left_name);
			div_right_obj = document.getElementById(this.right_name);
			if (div_left_obj && div_right_obj) {
				div_left_obj.onmouseover = function() { eval(scrollname + ".scrollLeft();") };
				div_left_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
				div_left_obj.onmousedown = function() { eval(scrollname + ".fasterSpeed();") };
				div_left_obj.onmouseup = function() { eval(scrollname + ".normalSpeed();") };
				
				div_right_obj.onmouseover = function() { eval(scrollname + ".scrollRight();") };
				div_right_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
				div_right_obj.onmousedown = function() { eval(scrollname + ".fasterSpeed();") };
				div_right_obj.onmouseup = function() { eval(scrollname + ".normalSpeed();") };
			}
		}
	}
	
	this.stopScroll = function() {
		clearTimeout(this.timeoutID);
		this.normalSpeed();
	}
	
	this.scrollLeft = function() {
		if (this.div_obj) {
			this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
			this.div_obj.scrollLeft = this.scrollCursor;
			if (this.scrollCursor > 0) {
				this.chkAcc();
				this.timeoutID = setTimeout(this.name + ".scrollLeft()", 60);
			}
		}
	}
	this.scrollRight = function() {
		if (this.div_obj) {
			this.scrollCursor += this.speed;
			this.div_obj.scrollLeft = this.scrollCursor;
			if (this.div_obj.scrollLeft == this.scrollCursor) {
				this.chkAcc();
				this.timeoutID = setTimeout(this.name + ".scrollRight()", 60);
			} else {
				this.scrollCursor = this.div_obj.scrollLeft;
			}
		}
	}
	
	this.resetScroll = function() {
		if (this.div_obj) {
			this.div_obj.scrollLeft = 0;
			this.scrollCursor = 0;
		}
	}

	this.fasterSpeed = function() {
		this.doAcc = true;
	}
	
	this.normalSpeed = function() {
		this.speed = this.speed_normal;
		this.doAcc = false;
		this.accCount = 0;
	}
	
	this.chkAcc= function() {
		if (this.doAcc && this.speed < this.speed_max) {
			this.accCount++;
			if (this.accCount == this.accInterval) {
				this.accCount = 0;
				this.speed++;
			}
		}
	}
}

