viewerid='';
viewertitel='';
viewerbeschreibung='';
viewerbilder=Array();
viewerwhere='';
viewerpicno=0;

var submenuitem='';

function strip_tags(str) {
   return str.replace(/<\/?[^>]+>/gi, "");
}

function trim(str){
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '')
}

function setSubmenuItem(si) {
	if (submenuitem!=si){
		switchOff(submenuitem);
	}
	submenuitem=si;
	switchOn(submenuitem);
}

function initSwitchOff(si) {
	submenuitem='';
	if (document.getElementById(si)){
		document.getElementById(si).style.zIndex='199';
		window.setTimeout('switchOff("'+si+'");', 500);
	}
}

function switchOff(si) {
	if (submenuitem!=si){
		if (document.getElementById(si)){
			document.getElementById(si).style.display='none';
		}
	}
}

function switchOn(si) {
	if (document.getElementById(si)){
		document.getElementById(si).style.zIndex='200';
		document.getElementById(si).style.display='block';
	}
}



// Klapp -------------------------------------------------------------------------------------------
klapp = function (id) {
	this.id=id;
	this.status='eingeklappt';
	this.margintop=0;
	this.steps=10;
	this.time=10;
	
	this.margintop=(document.getElementById(id+'klappi').clientHeight*(-1))-this.steps;
	document.getElementById(id+'klappi').style.margin=this.margintop+'px 0px 0px 0px';

    this.klappEin = function() {
	  if (document.getElementById(id+'switch')) {
		this.status='einklappend';
		document.getElementById(id+'switch').className='klappswitchB';
		this.margintop=this.margintop-this.steps;
		if (document.getElementById(id+'klappi').clientHeight+this.margintop<0) {
			this.status='eingeklappt';
			this.margintop=(document.getElementById(id+'klappi').clientHeight*(-1))-this.steps;
			window.clearInterval(this.interval);
			document.getElementById(id+'switch').className='klappswitch';
		}
		document.getElementById(id+'klappi').style.margin=this.margintop+'px 0px 0px 0px';
	  } else {
	    window.clearInterval(this.interval);
	  }
	};

    this.klappAus = function() {
	  if (document.getElementById(id+'switch')) {
		this.status='ausklappend';
		document.getElementById(id+'switch').className='klappswitch';
		this.margintop=this.margintop+this.steps;
		if (this.margintop>0) {
			this.status='ausgeklappt';
			this.margintop=0;
			window.clearInterval(this.interval);
			document.getElementById(id+'switch').className='klappswitchB';
		}
		document.getElementById(id+'klappi').style.margin=this.margintop+'px 0px 0px 0px';
	  } else {
	    window.clearInterval(this.interval);
	  }
	};

    this.klapp = function() {
        window.clearInterval(this.interval);
		var self=this;
		if (this.status=='ausgeklappt' || this.status=='ausklappend')
			this.interval = window.setInterval(function() { self.klappEin(); }, this.time);
		else
			this.interval = window.setInterval(function() { self.klappAus(); }, this.time);
	};

    this.forceKlappEin = function() {
        window.clearInterval(this.interval);
		var self=this;
		this.interval = window.setInterval(function() { self.klappEin(); }, this.time);
	};

    this.forceKlappAus = function() {
        window.clearInterval(this.interval);
		var self=this;
		this.interval = window.setInterval(function() { self.klappAus(); }, this.time);
	};

}

// Viewer ------------------------------------------------------------------------------------------
//global
visdiv=null;

function getscroll() {
	document.getElementById('div'+visdiv).style.top=document.documentElement.scrollTop + document.body.scrollTop+'px';
}

function startscroll() {
	if (document.addEventListener) { document.addEventListener("scroll", getscroll, true); }
	else { window.onscroll = getscroll; document.body.onscroll = getscroll; }
}

function stopscroll() {
	if (document.addEventListener) { document.removeEventListener("scroll", getscroll, true); }
	else { window.onscroll = null; document.body.onscroll = null; }
}


cpviewer = function (id) {
	pics = new Array();
	this.picTimer = null;
	this.picno=0;
	this.interval;
	this.interval2;
	this.scroll;
	this.occ=0;
	this.id=id;
	this.xmlHttp = null;
	// Mozilla, Opera, Safari sowie Internet Explorer 7
	if (typeof XMLHttpRequest != 'undefined') {
		try  {this.xmlHttp = new XMLHttpRequest();} catch(e) {}
	}
	if (!this.xmlHttp) {
	    // Internet Explorer 6 und älter
	    try { this.xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");  }
		  catch(e) { try { this.xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP"); }
		    catch(e) { this.xmlHttp  = null; }
		  }
	}

	tmpheight=0;
	tmptop=20;
	if(document.body)(tmpheight=document.body.offsetHeight);
	if(window.innerHeight) (tmpheight=window.innerHeight);
	if(tmpheight>0)
		tmptop=Math.round((tmpheight-528)/2);

	document.write('<div id="div'+this.id+'" style="position:absolute; top:0px; left:0px; z-index:50; height:100%; width:100%; display:none;" >');
	document.write('<div title="zurück" onClick="cpviewer1.clear();" id="divblack'+this.id+'" style="z-index:50;position:absolute; display:block; width:100%;height:100%;background:#000000; filter:alpha(opacity:95); MozOpacity:0.95; KHTMLOpacity:0.95; opacity:0.95; ">');
	document.write('</div><div class="prv_frame" id="divb'+this.id+'" style="margin-top:'+tmptop+'px;">');
	document.write('	<div class="prv_framebg">'+
				'	<div id="scrollrighto" onMouseover="cpviewer1.autoscrollPlus(\'scrollpanel\');" onMouseout="cpviewer1.autoscrollStop();" onClick="cpviewer1.switchNext()" >'+
				'	<div id="scrollright" class="rightOff"></div>'+
				'	</div>'+
				'	<div id="scrolllefto" onMouseover="cpviewer1.autoscrollMinus(\'scrollpanel\');" onMouseout="cpviewer1.autoscrollStop();" onClick="cpviewer1.switchPrior()" >'+
				'	<div id="scrollleft" class="leftOff"></div>'+
				'	</div>'+
				'	<div id="viewerinfodiv" onMouseover="cpviewer1.infoon();" onMouseout="cpviewer1.infooff();" >'+
				'	<div id="viewerinfodivB" class="viewerinfodivoff"></div>'+
				'	</div>'+
				'	<div id="viewerpics" style="text-align:center;padding:18px 4px 0px 0px;"></div>'+
				'	<div style="position:absolute;top:487px;right:25px;"><h2 id="viewertitel" style="color:#000000;font-size:18px;"></h2></div>'+
				'	<div style="position:absolute;top:487px;left:25px;"><h2 id="viewerpiccounter" style="color:#000000;font-size:18px;"></h2></div>'+
				'	</div>');
	document.write('</div>');
	document.write('</div>');

	this.setData = function(){
		window.clearInterval(this.interval2);
		document.getElementById('viewertitel').innerHTML=viewertitel;
		document.getElementById('viewerpics').innerHTML='<img src="dbpics/'+viewerbilder[0]+'" />';
		if(viewerbilder.length>1) document.getElementById('viewerpiccounter').innerHTML='Bild 1/'+viewerbilder.length;
		else document.getElementById('viewerpiccounter').innerHTML='';
		if(trim(strip_tags(viewerbeschreibung))!='') {
			document.getElementById('viewerinfodiv').style.display='block';
			createHintWidth('viewerinfodiv','<div style=\"text-align:center;\">'+viewerbeschreibung+'</div>',450);
		}
		else {
			document.getElementById('viewerinfodiv').style.display='none';
		}
		viewerpicno=0;
		if(viewerbilder.length>1) {
			this.interval2=window.setInterval(function(){
				viewerpicno++;
				if(viewerpicno>(viewerbilder.length-1)) viewerpicno=0;
				document.getElementById('viewerpics').innerHTML='<img src="dbpics/'+viewerbilder[viewerpicno]+'" />';
				document.getElementById('viewerpiccounter').innerHTML='Bild '+(viewerpicno+1)+'/'+viewerbilder.length;
			},2000);
		}
	}
	
	this.setOcc = function(value,name) {
		// IE/Win
		if (value>98) {
			document.getElementById(name).style.filter = "";
		} else {
			document.getElementById(name).style.filter = "alpha(opacity:"+value+")";
		}		
		// Safari<1.2, Konqueror
		document.getElementById(name).style.KHTMLOpacity = value/100;
		// Older Mozilla and Firefox
		document.getElementById(name).style.MozOpacity = value/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		document.getElementById(name).style.opacity = value/100;
	};

	this.view = function(src) {
		var self=this;
		visdiv=this.id;
		this.occ=0;
		startscroll();
		var i=0;
		document.getElementById('div'+this.id).style.top=document.documentElement.scrollTop + document.body.scrollTop+'px';
		self.setOcc(this.occ,'divblack'+this.id);
		self.setOcc(this.occ*2,'divb'+this.id);
		document.getElementById('div'+self.id).style.display='block';
		while (document.getElementsByTagName("object")[i]){
			document.getElementsByTagName("object")[i].style.display='none';
			i++;
		}
		var i=0;
		while (document.getElementsByTagName("select")[i]){
			document.getElementsByTagName("select")[i].style.display='none';
			i++;
		}
		self.setInner(src);
		this.interval = window.setInterval(function() {
			self.occ=self.occ+10;		
			self.setOcc(self.occ,'divblack'+self.id);
			self.setOcc(self.occ*2,'divb'+self.id);
			if (self.occ>50) {
				window.clearInterval(self.interval);				
			}
		}, 10);
	}
//	this.nextPic= function(){
//		document.getElementById('pics').innerHTML='<img src="'+pics[this.picno]+'"></img>';
//		if (pics.length>1) {
//			this.picno++;
//			if(this.picno==pics.length) this.picno=0;
//			var self=this;
//			this.picTimer=window.setTimeout(function() {self.nextPic();},5000);
//		}
//	}

//	this.waitforload = function(){	
//		if(!document.getElementById('pics')) {
//			var self=this;
//			window.setTimeout(function() {self.waitforload();},20);
//		}
//		else {
//			clearTimeout(this.picTimer);
//			this.picno=0;
//			this.nextPic();
//		}
//	}

	this.setInner = function(src) {
	  if (this.xmlHttp) {
	    this.xmlHttp.open('GET', src, true);
		var self=this;
		//document.getElementById('divb'+self.id).innerHTML='';
	    this.xmlHttp.onreadystatechange = function () {
	        if (self.xmlHttp.readyState == 4 && self.xmlHttp.status == 200) {
				//document.getElementById('divb'+self.id).innerHTML+=self.xmlHttp.responseText;
				eval(self.xmlHttp.responseText);
				self.setData();
	        }
	    };
	    this.xmlHttp.send(null);
	  }
//  	  this.waitforload();
	}

	this.clear = function() {
		var self=this;
		//window.clearInterval(self.interval2);
		//document.getElementById('divb'+visdiv).innerHTML='';
		self.occ=80;
		this.interval = window.setInterval(function() {
			self.occ=self.occ-10;
			self.setOcc(self.occ*2,'divb'+visdiv);
			self.setOcc(self.occ,'divblack'+visdiv);
			if (self.occ<1) {
				stopscroll();
				window.clearInterval(self.interval);
				document.getElementById('div'+visdiv).style.display='none';
				var i=0;
				while (document.getElementsByTagName("object")[i]){
					document.getElementsByTagName("object")[i].style.display='block';
					i++;
				}
				var i=0;
				while (document.getElementsByTagName("select")[i]){
					document.getElementsByTagName("select")[i].style.display='inline';
					i++;
				}
			}
		}, 25);
	}
	
	this.infooff = function() {
		document.getElementById('viewerinfodivB').className='viewerinfodivoff';
	}

	this.infoon = function() {
		document.getElementById('viewerinfodivB').className='viewerinfodivon';
	}

	this.autoscrollMinus = function(id) {
		document.getElementById('scrollleft').className='leftOn';
	}

	this.autoscrollPlus = function(id) {
		document.getElementById('scrollright').className='rightOn';
	}

	this.autoscrollStop = function() {
		document.getElementById('scrollright').className='rightOff';
		document.getElementById('scrollleft').className='leftOff';
		//	window.clearInterval(this.interval2);
	}

//	this.switchPrior = function(id,where) {
	this.switchPrior = function() {
		id=viewerid;
		where=viewerwhere;
		if(where!=''){
			this.setInner('viewer.php?id='+id+'&prior=prior&where='+where);
		}
		else this.setInner('viewer.php?id='+id+'&prior=prior');
	}

//	this.switchNext = function(id,where) {
	this.switchNext = function() {
		id=viewerid;
		where=viewerwhere;
		if(where!=''){
			this.setInner('viewer.php?id='+id+'&next=next&where='+where);
		}
		else this.setInner('viewer.php?id='+id+'&next=next');
	}

}

//--------------------------------------------
viewertext='';
cptexviewer = function (id) {
	this.interval;
	this.scroll;
	this.occ=0;
	this.id=id;
	this.xmlHttp = null;
	// Mozilla, Opera, Safari sowie Internet Explorer 7
	if (typeof XMLHttpRequest != 'undefined') {
		try  {this.xmlHttp = new XMLHttpRequest();} catch(e) {}
	}
	if (!this.xmlHttp) {
	    // Internet Explorer 6 und älter
	    try { this.xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");  }
		  catch(e) { try { this.xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP"); }
		    catch(e) { this.xmlHttp  = null; }
		  }
	}

	tmpheight=0;
	tmptop=20;
	if(document.body)(tmpheight=document.body.offsetHeight);
	if(window.innerHeight) (tmpheight=window.innerHeight);
	if(tmpheight>0)
		tmptop=Math.round((tmpheight-528)/2);

	document.write('<div id="div'+this.id+'" style="position:absolute; top:0px; left:0px; z-index:50; height:100%; width:100%; display:none;" >');
	document.write('<div title="zurück" onClick="cpviewer1.clear();" id="divblack'+this.id+'" style="z-index:50;position:absolute; display:block; width:100%;height:100%;background:#000000; filter:alpha(opacity:95); MozOpacity:0.95; KHTMLOpacity:0.95; opacity:0.95; ">');
	document.write('</div><div class="prv_frame" id="divb'+this.id+'" style="margin-top:'+tmptop+'px;">');
	document.write('	<div class="xprv_framebg">'+
				'	<iframe id="cpv2'+this.id+'" style="width:815px; height:528px;border:1px solid #000000;" ></iframe>'+
				'	</div>');
	document.write('</div>');
	document.write('</div>');

	
	this.setOcc = function(value,name) {
		// IE/Win
		if (value>98) {
			document.getElementById(name).style.filter = "";
		} else {
			document.getElementById(name).style.filter = "alpha(opacity:"+value+")";
		}		
		// Safari<1.2, Konqueror
		document.getElementById(name).style.KHTMLOpacity = value/100;
		// Older Mozilla and Firefox
		document.getElementById(name).style.MozOpacity = value/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		document.getElementById(name).style.opacity = value/100;
	};

	this.view = function(src) {
		document.getElementById('cpv2'+this.id).src=src;
		var self=this;
		visdiv=this.id;
		this.occ=0;
		startscroll();
		var i=0;
		document.getElementById('div'+this.id).style.top=document.documentElement.scrollTop + document.body.scrollTop+'px';
		self.setOcc(this.occ,'divblack'+this.id);
		self.setOcc(this.occ*2,'divb'+this.id);
		document.getElementById('div'+self.id).style.display='block';
		while (document.getElementsByTagName("object")[i]){
			document.getElementsByTagName("object")[i].style.display='none';
			i++;
		}
		var i=0;
		while (document.getElementsByTagName("select")[i]){
			document.getElementsByTagName("select")[i].style.display='none';
			i++;
		}
//		self.setInner(src);
		this.interval = window.setInterval(function() {
			self.occ=self.occ+10;		
			self.setOcc(self.occ,'divblack'+self.id);
			self.setOcc(self.occ*2,'divb'+self.id);
			if (self.occ>50) {
				window.clearInterval(self.interval);				
			}
		}, 10);
	}


	this.clear = function() {
		var self=this;
		self.occ=80;
		this.interval = window.setInterval(function() {
			self.occ=self.occ-10;
			self.setOcc(self.occ*2,'divb'+visdiv);
			self.setOcc(self.occ,'divblack'+visdiv);
			if (self.occ<1) {
				stopscroll();
				window.clearInterval(self.interval);
				document.getElementById('div'+visdiv).style.display='none';
				var i=0;
				while (document.getElementsByTagName("object")[i]){
					document.getElementsByTagName("object")[i].style.display='block';
					i++;
				}
				var i=0;
				while (document.getElementsByTagName("select")[i]){
					document.getElementsByTagName("select")[i].style.display='inline';
					i++;
				}
			}
		}, 25);
	}

}

