// JavaScript Document

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;
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

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, 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+"&browserwidth="+getWidth()+"&browserheight="+getHeight()+"";
	myAjax.method="GET";
	myAjax.onSuccess = ajaxInsert;
	myAjax.onError=function(msg){alert(msg)}
	//alert(myAjax.params);
	myAjax.doRequest();
	}


	
//Galerie-Request
function sndArticleReq(ajaxid, newartid){
	var myAjax = new Ajax();
	myAjax.url="index.php";
	myAjax.params="article_id="+ajaxid+"&newartid="+newartid+"";
	myAjax.method="GET";
	myAjax.onSuccess = ajaxInsert;
	myAjax.onError=function(msg){alert(msg)}
	//alert(myAjax.params);
	myAjax.doRequest();
	}
	
function ajaxInsert(txt, xml){
	var insert = document.getElementById("ajaxdisplay");
	//alert(txt);
	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 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";
		
		//alert(''+coreid+','+mediaid+', '+i+', '+width+', '+height+'');
      }
	  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('wrap').scrollHeight+"px";
		opspan.style.backgroundColor = "#000";
		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+"px";
		infopop.style.height = ""+pheight+"px";
		infopop.style.backgroundColor="#fff";
		infopop.style.border = "2px solid #fff";
		infopop.style.position = "absolute";
		infopop.style.zIndex = "15";
		infopop.style.top = ""+(getPos()+15)+"px";
		infopop.style.left = ""+((getWidth()/2)-(pwidth/2))+"px";
		
		infopop.onmouseover = function(){
			document.getElementById("closetip").style.display = "inline";	
		}
		infopop.onmouseout = function(){
			document.getElementById("closetip").style.display = "none";	
		}
		
		infopop.innerHTML = '<img src="'+picfile+'" alt="'+pictitle+'" /><p>'+pictitle+'<span id="closetip">Fenster schließen</span></p>';
		
		document.getElementById("wrap").appendChild(opspan);
		var fadespan = new fx.Opacity('opspan', {duration: 270});
		fadespan.hide();
		fadespan.custom(0, 0.7);
		
		document.getElementById("wrap").appendChild(infopop);
		
		document.getElementById("closetip").onmouseover = function(){
				document.getElementById("closetip").style.cursor = "pointer";
		}
		document.getElementById("closetip").onmouseout = function(){
				document.getElementById("closetip").style.cursor = "auto";
		}
		document.getElementById("closetip").onclick = function(){
				var fadespan = new fx.Opacity('opspan', {duration: 250});
				fadespan.custom(0.7, 0);
				setTimeout('removePop()', 350);
		}
	
}


function init()
{
lnks = document.getElementsByTagName("a");
for(i=0; i<lnks.length; i++) {
lnks[i].onfocus = new Function("if(this.blur)this.blur()");
}
}