
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function getWidth(){
	var width;
	if (self.innerHeight) // all except Explorer
		{width = self.innerWidth;}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
		{width = document.documentElement.clientWidth;}
	else if (document.body) // other Explorers
		{width = document.body.clientWidth;}
	return width;
}

function getHeight(){
	var height;
	if (self.innerHeight) // all except Explorer
		{height = self.innerHeight;}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
		{height = document.documentElement.clientHeight;}
	else if (document.body) // other Explorers
		{height = document.body.clientHeight;}
	return height;
}


function getPos(){
	var pos;
	if (window.innerHeight)
	{
		  pos = window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop;
	}	
	return pos;
}


function Ajax(){
	//	Eigenschaften deklarieren und intialisieren	
	this.url="";
	this.params="";
	this.method="GET";
	this.onSuccess=null;
	this.loadProgress="";
	this.onError=function(msg){alert(msg)}
	}
	
Ajax.prototype.doRequest=function(){
	// Zugriff auf Klasse für readyStateHandler ermöglichen
	var _this=this;
	
	// Überprüfen der Angaben
	if(!this.url){
		this.onError("Es wurde keine URL angegeben!! Der Request wurde abgebrochen.");
		return false;
		};
	if(!this.method){
		this.method="GET";
		}
		else{
			this.method=this.method.toUpperCase();
			}
	
	// XMLHttpRequest-Objekt erstellen
	var xmlHttpRequest=getXMLHttpRequest();
	if(!xmlHttpRequest){
		this.onError("Es konnte kein XMLHttpRequest-Objekt erstellt werden.");
		return false;
		}
		
	
	// Einblenden des Progresszeichens
	if (_this.loadProgress != "" && _this.loadProgress != null){
		var showProgress = document.getElementById(_this.loadProgress).style.visibility = "visible";
	}
	// Fallunterscheidung nach Übertragungsmethode
	switch(this.method){
		
		case "GET":		xmlHttpRequest.open(this.method, this.url+"?"+this.params, true);
						xmlHttpRequest.onreadystatechange=readyStateHandler;
						xmlHttpRequest.send(null);
						break;
		case "POST":	xmlHttpRequest.open(this.method, this.url, true);
						xmlHttpRequest=onreadystatechange=readyStateHandler;
						xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						xmlHttpRequest.send(this.params);
						break;
		}
	
	
	// Private Methode zur Verarbeitung der erhaltenen Daten
	function readyStateHandler(){
		if(xmlHttpRequest.readyState < 4){
			//_this.onError("readyState war fehlerhaft bei Annahme des Response: readyState < 4 -> "+xmlHttpRequest.readyState);
			return false;
			}
		if(xmlHttpRequest.status == 200 || xmlHttpRequest.status == 304){
			if(_this.onSuccess){
				// Ausblenden des Progresszeichens
				if (_this.loadProgress != "" && _this.loadProgress != null){
					var showProgress = document.getElementById(_this.loadProgress).style.visibility = "hidden";
				}
					
				_this.onSuccess(xmlHttpRequest.responseText, xmlHttpRequest.responseXML);
					
					
					
				}
			}
			else{
				if(_this.onError){
					_this.onError("["+xmlHttpRequest.status+" "+xmlHttpRequest.statusText+"] Es trat ein Fehler bei der Datenübertragung auf!");
					}
				}
		}
	}
	
// Gibt browserunabhängig ein XMLHttpRequest-Objekt zurück
function getXMLHttpRequest(){
	if(window.XMLHttpRequest){
		//XMLHttpRequest für Firefox, Opera, Safari & Co
		return new XMLHttpRequest();
		}
		else{
			if(window.ActiveXObject){
				try{
					// XMLHTTP für InternetExplorer (NEU)
					return new ActiveXObject("Msxml2.XMLHTTP");
					}
				catch(e){
					// XMLHTTP für InternetExplorer (ALT)
					try{
						return new ActiveXObject("Microsoft.XMLHTTP");
						}
					catch(e){
						return null;
						}
					}
				}
				return null;
			}
	}
	

//Galerie-Request
function sndPicReq(ajaxid, popupid, mcatid, picid, maxw, maxh){
	var myAjax = new Ajax();
	myAjax.url="index.php";
	myAjax.params="article_id="+ajaxid+"&popupid="+popupid+"&mcatid="+mcatid+"&picid="+picid+"&maxw="+maxw+"&maxh="+maxh+"";
	myAjax.method="GET";
	myAjax.onSuccess = ajaxInsert;
	myAjax.onError=function(msg){alert(msg)}
	//alert(myAjax.params);
	myAjax.doRequest();
	}


function sndPicReq2(ajaxid, mcatid, picid, maxw, maxh){
	var myAjax = new Ajax();
	myAjax.url="index.php";
	myAjax.params="article_id="+ajaxid+"&mcatid="+mcatid+"&picid="+picid+"&maxw="+maxw+"&maxh="+maxh+"&browserwidth="+getWidth()+"&browserheight="+getHeight()+"";
	myAjax.method="GET";
	myAjax.onSuccess = ajaxInsert;
	myAjax.onError=function(msg){alert(msg)}
	//alert(myAjax.params);
	myAjax.doRequest();
	}


	
//Artikel-Request
function sndArticleReq(newartid, hlel, file){
	var myAjax = new Ajax();
	myAjax.url="index.php";
	myAjax.loadProgress = "loading";
	myAjax.params="article_id=9&newartid="+newartid+"";
	myAjax.method="GET";
	myAjax.onSuccess = ajaxInsertArt;
	myAjax.onError=function(msg){alert(msg)}
	document.getElementById('content').innerHTML = "";
	var navlinks = document.getElementById('nav').getElementsByTagName('a');
	for(i=0;i<navlinks.length;i++){
		navlinks[i].className = "off";
	}
	document.getElementById(hlel).getElementsByTagName('a')[0].className = "current";
	document.getElementById('screen').style.backgroundImage = "url("+file+")";
	myAjax.doRequest();
	}
	
function ajaxInsertArt(txt, xml){
	var insert = document.getElementById("content");
	insert.innerHTML = ''+txt+'';		
	}
	
	
function prepareGallery(coreid, mediaid, width, height){
  if( document.getElementById &&
      document.getElementsByTagName ){
    if( document.getElementById( 'ajaxgalsel' ) ){
      var gallery = document.getElementById( 'ajaxgalsel' );
      var links = gallery.getElementsByTagName( 'a' );
	  var piccount=null;
      for( var i=0; i < links.length; i++ ){
        links[i].onclick = function(){
			//alert(i)
			sndPicReq(''+coreid+'', ''+mediaid+'',''+ i +'', ''+width+'', ''+height+'');
			piccount += links[i]+ " ";
		}
		alert(piccount);
      }
    }
  }
}

function sndSongReq(filepath){
	document.getElementById('player').innerHTML = '<span id="loadsong"></span>';
	var so = new SWFObject("./files/mp3.swf", "mp3player", "1", "1", "9", "EECCCC");
		so.addParam("windowmode", "transparent");
		so.addVariable("audiofile", filepath);
		so.write("player");
}

function hilite(a){
	if( document.getElementById &&
      document.getElementsByTagName ){
    if( document.getElementById( 'ajaxgalsel' ) ){
      var gallery = document.getElementById( 'ajaxgalsel' );
      var links = gallery.getElementsByTagName( 'a' );
      for( var i=0; i < links.length; i++ ){
        links[i].className="off";
		
      }
	  a.className="on";
    }
  }
}

function highlite(id, a){
	if( document.getElementById &&
      document.getElementsByTagName ){
    if( document.getElementById( ''+id+'' ) ){
      var gallery = document.getElementById( ''+id+'' );
      var links = gallery.getElementsByTagName( 'a' );
      for( var i=0; i < links.length; i++ ){
        links[i].className="off";
		
      }
	  a.className="on";
    }
  }
}

function showTitle(id){
	if( document.getElementById &&
      document.getElementsByTagName ){
			if( document.getElementById( 'lst'+id+'' ) ){
				var lst = document.getElementById( 'lst'+id+'' );
				var links = lst.getElementsByTagName( 'a' );
				var show = document.getElementById( 'show'+id+'' );
				for( var i=0; i < links.length; i++ ){
        			links[i].onmouseover=function(){
						show.innerHTML = this.title;
						
					}
					links[i].onmouseout=function(){
						show.innerHTML = "";
						
					}
		
      			}
			}
	}
	
	
}

function removePop(){
	var plane = document.getElementById("opspan");
	var pu = document.getElementById("infopop");
	pu.parentNode.removeChild(pu);
	plane.parentNode.removeChild(plane);
}

function showpicpop(picfile, pictitle, pwidth, pheight){
		var opspan = document.createElement("span");
		opspan.id = "opspan";
		opspan.style.width = ""+(getWidth()+20)+"px";
		opspan.style.height = ""+document.getElementById('sizer').scrollHeight+"px";
		opspan.style.backgroundColor = "#fff";
		opspan.style.position = "absolute";
		opspan.style.top = "0";
		opspan.style.left = "0";
		opspan.style.opacity = "0.8";
		opspan.style.filter = "alpha(opacity=80)";
		
		var infopop = document.createElement("div");
		infopop.id = "infopop";
		/*
		infopop.onclick = function(){
				var fadespan = new fx.Opacity('opspan', {duration: 250});
			//fadespan.hide();
			fadespan.custom(0.7, 0);
			setTimeout('removePop()', 350);
		}
		*/
		
		infopop.style.width = ""+(pwidth-3)+"px";
		infopop.style.height = ""+(pheight-2)+"px";
		infopop.style.border = "1px solid #666";
		infopop.style.backgroundColor="#fff";
		infopop.style.position = "absolute";
		infopop.style.zIndex = "15";
		infopop.style.top = ""+(getPos()+15)+"px";
		infopop.style.left = ""+((getWidth()/2)-(pwidth/2))+"px";
		
		
		
		infopop.innerHTML = '<img src="'+picfile+'" alt="'+pictitle+'" />';
		
		document.getElementById("sizer").appendChild(opspan);
		var fadespan = new fx.Opacity('opspan', {duration: 270});
		fadespan.hide();
		fadespan.custom(0, 0.9);
		
		document.getElementById("sizer").appendChild(infopop);
		
		document.getElementById("infopop").onclick = function(){
				var fadespan = new fx.Opacity('opspan', {duration: 250});
				fadespan.custom(0.9, 0);
				setTimeout('removePop()', 350);
		}
	
}


function popup(pic, title, width, height){
	
	var browserwidth = getWidth();
	var browserheight = getHeight();

	var puimg = '';
	var puwidth, puheight, maxw, maxh;
		if(width < (browserwidth-60) && height < (browserheight-70)){
			//kein resize notwendig
			puimg = './files/'+pic;
			puwidth = width;
			puheight = height;
		}
		else{
			//resize nach fenstergroesse
			maxw = browserwidth - 60;
			maxh = browserheight - 60;
			puimg += 'index.php?rex_resize=';
			
			if(width>height){
				//Querformat
				if(((maxw/width)*height)<=maxh){
					puimg += ''+maxw+'w__';
					puwidth = maxw;
					puheight = ((maxw/width)*height);
				}
				else{
					puimg += ''+maxh+'h__';
					puheight = maxh;
					puwidth = ((maxh/height)*width);
				}
			}
			else{
			//Hochformat oder Quadrat
			  if(((maxh/height)*width)<=maxw){
				puimg += ''+maxh+'h__';
				puheight = maxh;
				puwidth = ((maxh/height)*width);
			  }
			  else{
				puimg += ''+maxw+'w__';
				puwidth = maxw;
				puheight = ((maxw/width)*height);
			  }
			}
			
			puimg += pic;
			
		}
              
		var opspan = document.createElement("span");
		opspan.id = "opspan";
		opspan.style.width = ""+(getWidth()+20)+"px";
		opspan.style.height = ""+document.getElementById('sizer').scrollHeight+"px";
		opspan.style.backgroundColor = "#fff";
		opspan.style.position = "absolute";
		opspan.style.top = "0";
		opspan.style.left = "0";
		opspan.style.opacity = "0.8";
		opspan.style.filter = "alpha(opacity=80)";
		
		var infopop = document.createElement("div");
		infopop.id = "infopop";
		infopop.style.width = ""+(puwidth-3)+"px";
		infopop.style.height = ""+(puheight-2)+"px";
		infopop.style.border = "1px solid #666";
		infopop.style.backgroundColor="#fff";
		infopop.style.position = "absolute";
		infopop.style.zIndex = "15";
		infopop.style.top = ""+(getPos()+15)+"px";
		infopop.style.left = ""+((getWidth()/2)-(puwidth/2))+"px";
		
		
		
		infopop.innerHTML = '<img src="'+puimg+'" alt="'+title+'" />';
		
		document.getElementById("sizer").appendChild(opspan);
		var fadespan = new fx.Opacity('opspan', {duration: 270});
		fadespan.hide();
		fadespan.custom(0, 0.9);
		
		document.getElementById("sizer").appendChild(infopop);
		
		document.getElementById("infopop").onclick = function(){
				var fadespan = new fx.Opacity('opspan', {duration: 250});
				fadespan.custom(0.9, 0);
				setTimeout('removePop()', 350);
		}
		
}

function popup2(pic, title, description, width, height){
	
	var browserwidth = getWidth();
	var browserheight = getHeight();

	var puimg = '';
	var puwidth, puheight, maxw, maxh;
		if(width < (browserwidth-60) && height < (browserheight-70)){
			//kein resize notwendig
			puimg = './files/'+pic;
			puwidth = width;
			puheight = height;
		}
		else{
			//resize nach fenstergroesse
			maxw = browserwidth - 60;
			maxh = browserheight - 60;
			puimg += 'index.php?rex_resize=';
			
			if(width>height){
				//Querformat
				if(((maxw/width)*height)<=maxh){
					puimg += ''+maxw+'w__';
					puwidth = maxw;
					puheight = ((maxw/width)*height);
				}
				else{
					puimg += ''+maxh+'h__';
					puheight = maxh;
					puwidth = ((maxh/height)*width);
				}
			}
			else{
			//Hochformat oder Quadrat
			  if(((maxh/height)*width)<=maxw){
				puimg += ''+maxh+'h__';
				puheight = maxh;
				puwidth = ((maxh/height)*width);
			  }
			  else{
				puimg += ''+maxw+'w__';
				puwidth = maxw;
				puheight = ((maxw/width)*height);
			  }
			}
			
			puimg += pic;
			
		}
        var opspanheight;
		if(document.getElementById('sizer').scrollHeight > getHeight()-20){
			opspanheight = document.getElementById('sizer').scrollHeight;
		}
		else{
			opspanheight = getHeight()-20;
		}
		var opspan = document.createElement("span");
		opspan.id = "opspan";
		opspan.style.width = ""+(getWidth())+"px";
		opspan.style.height = ""+opspanheight+"px";
		opspan.style.backgroundColor = "#fff";
		opspan.style.position = "absolute";
		opspan.style.top = "0";
		opspan.style.left = "0";
		opspan.style.opacity = "0.8";
		opspan.style.filter = "alpha(opacity=80)";
		opspan.style.zIndex = "20";
		
		var infopop = document.createElement("div");
		infopop.id = "infopop";
		infopop.style.width = ""+(puwidth-3)+"px";
		//infopop.style.height = ""+(puheight)+"px";
		infopop.style.border = "1px solid #666";
		infopop.style.backgroundColor="#fff";
		infopop.style.position = "absolute";
		infopop.style.zIndex = "25";
		infopop.style.top = ""+(getPos()+15)+"px";
		infopop.style.left = ""+((getWidth()/2)-(puwidth/2))+"px";
		
		
		
		infopop.innerHTML = '<img src="'+puimg+'" alt="'+title+'" /><p><strong>'+title+'</strong><br/>'+description+'</p>';
		
		document.getElementById("sizer").appendChild(opspan);
		var fadespan = new fx.Opacity('opspan', {duration: 270});
		fadespan.hide();
		fadespan.custom(0, 0.9);
		
		document.getElementById("sizer").appendChild(infopop);
		
		document.getElementById("infopop").onclick = function(){
				var fadespan = new fx.Opacity('opspan', {duration: 250});
				fadespan.custom(0.9, 0);
				setTimeout('removePop()', 350);
		}
		
}
