/**********************************************
class zoom_1009
Bannertexte werden ein- und ausgeblendet
version 0.2
Stand. 31.05.2011
Anderungen:
	Verzicht auf die definition eines main-Div
	Einbindung des AJAX-Couunters
	
	
**********************************************/
//--- Konstruktion ----------------------------
function Czoom_1009(){
	//--- Konfiguration ---
	this.path='';
	this.max_width= 800;
	this.min_width=50;
	this.boxStyle="rbx_003.css";
	this.low_dir="bilder/low/";
	//--- Basiskonstruktion ---
	this.base=Cdiv; //parent-class definieren
	this.base('zoom'); //parent-konstruktor aufrufen
	//--- Initialisierung ---
	this.laufteit=0;
	this.starttime=0;
	this.aktiv=	null;	
	this.current_width=0;
	this.filename=	""; 
	this.stepval=50;
	this.div.className="zoombox";
	this.is_open=false;
	this.id=null;
	this.autopop = false; //automatisches öffnen 
	this.autoclose = true; //automatisches schliessen bei onmouseout 
	this.go_large= true;
	this.txt=null;
//	this.scrollIntoView = false;
	this.min_top=220;
	this.stict_top=500;
	this.position= "absolute";
	this.mWidth =100;
	this.mHeight =100;
	this.loaded =false;
	this.hinweis = null;
//	if(VERSION=="debug") 	$this->counterAjaxPath = "Kunden/trachtenbenkert/ajax_counter/ajax/";
//	else					$this->counterAjaxPath = "ajax_counter/ajax/";

}
Czoom_1009.prototype=new Cdiv; //parent-class implementieren
Czoom_1009.prototype.show=function(){ //Bereich einblenden
	if(!this.is_appended){ // ggf. bereich für Kalenderausgabe einbinden
		document.body.appendChild(this.div);
	 	this.is_appended=true;
	}
	this.div.innerHTML=this.htm;
}
Czoom_1009.prototype.go=function(id,lowname,maxwidth,large,width,height){ 
	var d=document;
	css = d.createElement('link');
	css.setAttribute('href','inc/ermt_zoom_1009/'+this.boxStyle);
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	d.getElementsByTagName('head')[0].appendChild(css);
	

	this.txt=null;
	this.stict_top=0;
	this.go_large= large || true;
	var date =new Date();
	if(this.autopop && id==this.id){
		var current_time=date.getTime()/1000;
		if(current_time-this.starttime<10)return;
	}
	if(this.is_open){
		this.close();
		return;
	}
	this.id=id;
	if(maxwidth)	this.max_width=maxwidth ;
	else 			this.max_width= 800;
	if(width && this.max_width>width )	this.max_width = width;
	document.body.style.overflow='scroll';
	this.lowname=this.low_dir+lowname;
	this.starttime=date.getTime()/1000;
	this.height(0);
	this.width(0);
	this.top(0);
	this.left(0);
	if(id)	this.pic=document.getElementById(id);
	else	this.pic=0;
	if(width && height)	this.picfaktor=height/width;
	else				 this.picfaktor=this.pic.offsetHeight/this.pic.offsetWidth;
	var _content=document.getElementById("content");
	this.content_top =_content.offsetTop;
	this.content_height =_content.offsetHeight;
	this.content_left =_content.offsetLeft;
	this.content_width =_content.offsetWidth;
	if(this.max_width>this.content_width)this.max_width=this.content_width;
	_site=document.getElementById("site");
	this.site_left =_site.offsetLeft;
	this.mWidth		= window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	this.mHeight	= window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	this.width(this.min_width);
	var BrowserName = navigator.appName;
	var t=0;
	if(BrowserName == "Microsoft Internet Explorer"){
		t=document.body.scrollTop;
	}else{
		t=window.pageYOffset;
	}
	t+=this.mHeight/2;
	this.top(t);
	this.current_width= 1+this.min_width-this.stepval;
	this.get_screensize();
	this.is_open=true;
	this.div.style.visibility="visible";
	this.clear();
	this.write('<img src="'+this.lowname+'"style="width:1px;">'); //preload
	this.show();
	this.hinweis=new Cdiv("Hinweis");	
	var BrowserName = navigator.appName;  // debug ???????? 
		if(BrowserName == "Microsoft Internet Explorer"){
			t=document.body.scrollTop;
			t=document.documentElement.scrollTop
		}else{
			t=window.pageYOffset;
		}
	var tmp=this.path+'ntn/system/shared/javascript/zoom_1012/bilder/loading_black.gif'; 
//	alert(tmp)
	with(this.hinweis){
		clear();
		write('<img src="'+tmp+'">');
		write("Grafik wird geladen");
		div.style.backgroundColor="#FFFFFF";
		div.style.padding="20px";
		div.style.color="#000000";
		div.style.borderStyle="solid";
		div.style.borderWidth="1px";
		div.style.borderColor="blue";
		append();
		var h=this.hinweis.div.offsetHeight;
		var b=this.hinweis.div.offsetWidtht;
		var splus=(this.mHeight-this.hinweis.div.offsetHeight)/2
		top(t+splus);
		splus=(this.mWidth-this.hinweis.div.offsetWidth)/2;
		left(splus);
		hide();
	}
	window.setTimeout("zoom.preload()", 200);
	this.versuch=0;
}
Czoom_1009.prototype.go_txt_std=function(id,lowname,maxwidth,txt,width,height){ 
	//----------- counter --------------
/*
		echo '<script type="text/javascript">';
//		echo 'ajax_execute("'.$_SERVER['HTTP_HOST'].'/'.$this->counterAjaxPath.'","counter.php?name=',$name.'");';
//		("container",path,file,zielfeld)

		echo 'ajax_output("container","'.$_SERVER['HTTP_HOST'].'/'.$this->counterAjaxPath.'","counter.php?name=',$name.'","");';
///		ajax.set_htm(container,file);
		echo '</script>';
	}

*/	
	
	
	
	
	ajax= new Cajax("http://"+NtnAjaxCounterPath);
//	ajax= new Cajax("http://www.trachten-benkert.de/ajax_counter/ajax/");
	var s = txt.replace(/<b>/g,"");
	s = s.replace(/<br>/g,"/");
	s = s.replace(/<\/b>/g,"");
	s = s.replace(/€uro/g,"Euro"); // TEST DEBUG
	s = s.replace(/&euro;uro/g,"Euro"); // TEST DEBUG
	s= s.substr(0,50);
	// var jetzt = vormals.replace(/Hinz/g, "Kunz, geb. Hinz");
	ajax.execute("counter.php?name="+s);
//	alert(NtnAjaxCounterPath);
//	ajax.set_htm("container","counter.php?name="+s)
	delete ajax;

	//----------------------------------
	
	this.go(id,lowname,maxwidth,true,width,height);
	this.txt=txt;
	
}
Czoom_1009.prototype.preload=function(){
	var ok=true;
	
	this.versuch++;
	for (i = 0; i < document.images.length; ++i) {
		if (document.images[i].complete == true) {} else  ok=false;
	}
	if(ok){
		window.clearInterval( this.aktiv);
		this.aktiv=false;
		this.loaded =true;
		var date =new Date();
		this.starttime=date.getTime()/1000;
		this.hinweis.hide();
		this.aktiv=window.setInterval("zoom.step("+this.stepval+")",20); //20
	}else{
		if(this.versuch==1)this.hinweis.show();
//		alert("test");
		window.setTimeout("zoom.preload()", 100);
	} 
}
Czoom_1009.prototype.go_counter=function(id,lowname,maxwidth,countername,large,width,height){ 
	ajax= new Cajax("http://"+NtnAjaxCounterPath);
	//alert(width);
	//----------- counter --------------
//	ajax= new Cajax("http://www.trachten-benkert.de/ajax_counter/ajax/");
	/*
	var s = txt.replace(/<b>/g,"");
	s = s.replace(/<br>/g,"/");
	s = s.replace(/<\/b>/g,"");
	//	
	s= s.substr(0,50);
	*/
	// var jetzt = vormals.replace(/Hinz/g, "Kunz, geb. Hinz");
	ajax.execute("counter.php?name="+countername);
	delete ajax;
	//----------------------------------
	
	this.go(id,lowname,maxwidth,large,width,height);
//	this.txt=txt;
	
}

Czoom_1009.prototype.go_stict_top=function(id,lowname,maxwidth,stict_top){ 
	
	this.go(id,lowname,maxwidth,true);
	this.stict_top=stict_top;
	
}
Czoom_1009.prototype.close=function(){ 
	if(this.aktiv){
		return;
	}
	var date =new Date();
	this.starttime=date.getTime()/1000;
	this.current_width-=this.stepval;
	if(!this.aktiv) this.aktiv=window.setInterval("zoom.step("+((-1)*this.stepval)+")",10);
}
Czoom_1009.prototype.get_screensize=function(){
	this.mWidth		= window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	this.mHeight	= window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
}
Czoom_1009.prototype.step=function(value){
	this.div.style.visibility="hidden";
	var date =new Date();
	var Status = "";
	var ok=true;
	for (i = 0; i < document.images.length; ++i) {
		if (document.images[i].complete == true) {
		} else {
		  ok=false;
		}
	}
	if(!ok){
		this.starttime=date.getTime()/1000;
		this.laufteit=0;
		//alert('bild nicht geladen');
		return;
	 } 
	if(this.laufteit<2){
		this.laufteit=date.getTime()/1000 - this.starttime;
	}
	if(this.laufteit>2){
		if(value>0)this.current_width=this.max_width;
		else		this.current_width=this.min_width;
	}
	this.current_width+=value;
	if(this.current_width<24) this.current_width = 24; // eingefügt: 23.02.2011
	if(this.current_width>this.max_width)		this.current_width=this.max_width;
	
	var h=this.picfaktor*this.current_width;
	var  max_h= this.mHeight*0.95;
	if(this.txt) max_h= this.mHeight*0.8;
	if(h> max_h){
		h=max_h;
		this.current_width=h/this.picfaktor;
		this.div.style.width="auto";
		this.max_width=this.current_width;
	} else	this.div.style.height="auto";
	this.width(this.current_width);
	this.height(h);
	this.clear();
	
	if(this.current_width>=this.max_width){
		this.write('<div style="clear:both;">');
		this.write('<table><tr> ');
		this.write('<td class="rol"></td> ');
		this.write('<td class="ro"></td> ');
		this.write('<td class="ror"></td>');
		this.write('</tr>');
		this.write('<tr>');
		this.write('<td class="rl"></td><td> ');
	}

	var mouseout;
	if(this.autoclose) mouseout=' onmouseout="zoom.close();"'; else mouseout="";
	if(this.current_width<this.max_width){
		if(!this.go_large){
			this.write('<img src="'+this.pic.src+'"  style="width:'+(this.current_width-24)+'px;" onclick="zoom.close();"'+mouseout+' >');
		}else{
			this.write('<img src="'+this.lowname+'"  style="width:'+(this.current_width-24)+'px;" onclick="zoom.close();"'+mouseout+' >');
		}
	}else{ 
		this.write('<img src="'+this.lowname+'"  style="width:'+(this.current_width-24)+'px; " onclick="zoom.close();"'+mouseout+' >');
	}

	if(this.current_width>=this.max_width){
		this.write('<td class="rr"></td> ');
		this.write("</tr></tr>");
		this.write('<td class="rul"></td> ');
		this.write('<td class="ru"></td> ');
		this.write('<td class="rur" ></td> ');
		this.write('</tr>');
		this.write("</table>");
	}
	
	if(this.current_width>=this.max_width && this.txt){
	this.write('<br>');
	this.write('<div class="box_rbt" Style="width:80%;margin-left:10%" >');
	this.write('<div class="top">'
		+'<div class="b1"></div>'
		+'<div class="b2"></div>'
		+'<div class="b3"></div>'
		+'<div class="b4"></div>'
		+'</div>');
	this.write('<div class="boxcontent">');
	this.write(this.txt);
	this.write('</div>');
	this.write('<div class="bottom">'
		+'<div class="b4"></div>'
		+'<div class="b3"></div>'
		+'<div class="b2"></div>'
		+'<div class="b1"></div>'
		+'</div>');
	this.write('</div>');
	}
	/*
	if(this.current_width>=this.max_width && this.txt){
		this.write('<table style="width:80%;margin-left:10%;"><tr> ');
		this.write('<td class="rol"></td> ');
		this.write('<td class="ro"></td> ');
		this.write('<td class="ror"></td>');
		this.write('</tr>');
		this.write('<tr>');
		this.write('<td class="rl"></td> ');
		this.write('<td class="rt" onclick="zoom.close();"'+mouseout+' >'+this.txt+'</td> ');
		this.write('<td class="rr"></td> ');
		this.write('</tr>');
		this.write('<tr>');
		this.write('<td class="rul"></td> ');
		this.write('<td class="ru"></td> ');
		this.write('<td class="rur" ></td> ');
		this.write('</tr>');
		this.write("</table>");
	}
	*/
	if(this.stict_top>0){
		t=this.stict_top;
	}else{
		var BrowserName = navigator.appName;
		if(BrowserName == "Microsoft Internet Explorer"){
			t=document.body.scrollTop;
			t=document.documentElement.scrollTop
		}else{
			t=window.pageYOffset;
		}
		var mh= this.mHeight;
		var splus=(mh-this.div.offsetHeight)/2;
		if(this.txt)splus-= mh*0.1;
		if(mh>this.div.offsetHeight){
		this.autoclose=true;
		}else{
			this.autoclose=false;
		}
		t+=splus;
		if(t<this.min_top)t=this.min_top;
	}
	this.top(t);
	this.left(this.content_left+this.site_left+(this.content_width-this.current_width)/2);
	this.show();
	this.div.style.visibility="visible";
	if(this.current_width>=this.max_width || this.current_width<=this.min_width){
		if(this.aktiv){
			window.clearInterval(this.aktiv);
			this.aktiv=null;
		}
		if(this.current_width<=this.min_width){
			this.hide();
			this.width(0);
			this.height(0);
		this.top(0);
			this.left(0);
			this.is_open=false;
		}
	}
}
zoom=new Czoom_1009();

