function lib_bwcheck() {
	this.ver    = navigator.appVersion;
	this.agent  = navigator.userAgent;
	this.dom    = document.getElementById?1:0;
	this.opera5 = this.agent.indexOf("Opera 5")>-1;
	this.ie4    = (document.all && !this.dom && !this.opera5)?1:0;
	this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7    = (this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie     = this.ie4||this.ie5||this.ie6||this.ie7;
	this.mac    = this.agent.indexOf("Mac")>-1;
	this.ns6    = (this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4    = (document.layers && !this.dom)?1:0;
	this.bw     = (this.ie4 || this.ie5 || this.ie6 || this.ie7 || this.ns4 || this.ns6 || this.opera5);
	return this;
}

var tim         = 'null';
var noScroll    = true;
var bw          = new lib_bwcheck()
var ScrollSpeed = 750;

function showElement(obj) {
	if (obj && obj.style && obj.style.display ) {
		obj.style.display = "block";
	}
}

function hideElement(obj) {
	if (obj && obj.style && obj.style.display ) {
		obj.style.display = "none";
	}
}

function initGallery(gallery) {
	var obj;
	if (bw.ie) {
		obj = document.getElementById(gallery);
		if (obj && obj.hasChildNodes()) {
			for (var i=0; i<showCount; i++) {
				showElement(obj.childNodes[i]);
			}
		}
	} else {
		obj = document.getElementsByName(gallery);
		for (var i=0; i<showCount; i++) {
			showElement(obj[i]);
		}
	}
}

function moveRight(gallery) {
	if (bw.ie) {
		elemente = document.getElementById(gallery).childNodes;
	} else {
		elemente = document.getElementsByName(gallery);
	}
	if (!noScroll) {
		var count = elemente.length - 1;
		if (count>=(showCount-1)) {
			for (var i = 0; i <= count; i++) {
				if (elemente[i].style.display == "block") {
					if (i+showCount > count) { noScroll = true; break; }
					hideElement(elemente[i]);
					i = i + showCount;
					showElement(elemente[i]);
					break;
				}
			}
			countPixel();
		} else {
			noScroll = true;
		}
//		tim = window.setTimeout('moveRight("'+gallery+'")', ScrollSpeed);
	}
}

function moveLeft(gallery) {
	if (bw.ie) {
		elemente = document.getElementById(gallery).childNodes;
	} else {
		elemente = document.getElementsByName(gallery);
	}
	if (!noScroll) {
		var count = elemente.length - 1;
		if (count>=(showCount-1)) {
			for (var i = count; i >= 0; i--) {
				if (elemente[i].style.display == "block") {
					if (i-showCount < 0) { noScroll = true; break; }
					hideElement(elemente[i]);
					i = i - showCount;
					showElement(elemente[i]);
					break;
				}
			}
			countPixel();
		} else {
			noScroll = true;
		}
//		tim = window.setTimeout('moveLeft("'+gallery+'")', ScrollSpeed);
	}
}

function countPixel() {
	var temp = window.location.href.lastIndexOf('regid');
	var region = window.location.href.substr(temp+6, 1);
	var box = '';
	if (region == 2) {
		box = 'giessen';
	} else if (region == 3) {
		box = 'wetterau';
	} else {
		box = 'giessen';
	}
	var ivw	= new Image();
	ivw.src = "http://"+box+".ivwbox.de/cgi-bin/ivw/CP/bildgalsc?&d="+(Math.random()*100000);
}

function moveNone() {
	noScroll = true;
	if (Number(tim)) {
		window.clearTimeout(tim);
		tim = 'null';
	}
}
