/*
	Genereller JavaScript Code für dynamische funktionen der Website.
*/


/*
	Folgender Code sorgt für die Möglichkeit weitere Funktionen genau dann ablaufen zu lassen, 
	wenn jeweils die Grundstruktur der Seite geladen ist (wie bspw. das Anpassen des Inhalts 
	an die Größe des Browserfensters.
*/

window.onDomReady = initReady;

window.onDomReady(adjustCenter);	//execute as soon as DOM is loaded
//window.onDomReady(adjustContentHeight);

function initReady(fn) // Initialize event depending on browser
{
	//W3C-compliant browser
	if(document.addEventListener) {
	  document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else {
		  document.onreadystatechange = function(){readyState(fn)}
		}
	}

	//IE execute function
	function readyState(func)
	{
		// DOM is ready
		if(document.readyState == "interactive" || document.readyState == "complete")
	{
		func();
	}
}


/*
	Folgender Code Passt den Inhalt der Webseite an die Größe des Browserfensters an.
	Dies passiert automatisch sobald die Größe des Fensters verändert wird.
*/

window.onresize = adjustCenter;
//window.onresize = adjustContentHeight;

function adjustContentHeight()
{
	return;// // to deactivate this function
	
	// when no object is passed, the html element with the id "content" is used
	if(typeof(obj)=='undefined') obj = MM_findObj('frame'); 
	if(typeof(cnt)=='undefined') cnt = MM_findObj('content'); 

	// when no percentage is passed this value generally influences the height
	if(typeof(percent)=='undefined') percent = 85;
	
	// arbitrary value that respects the other content's height
	subtranhend = 300;
	
	totalHeight = getWindowHeight();
	contentMinimumHeight = 265;
	contentMaximumHeight = 500;
	contentHeight = Math.round((totalHeight-subtranhend) * (percent/100));
	contentHeight = Math.max(Math.min(contentHeight, contentMaximumHeight), contentMinimumHeight);
	
	if(obj){
		obj.style.height = contentHeight+'px';
	}
	if(cnt){
		//alert("content height:"+cnt.offsetHeight+", frame height:"+obj.offsetHeight);
		if(cnt.offsetHeight<contentHeight){
			cnt.style.height = (contentHeight-2)+'px'; // mind the 2px hack
		}
	}

}

function adjustCenter()
{
    var totalWidth = getWindowWidth();
    var contentWidth = 686;
    var fromLeft = (totalWidth/2) - (contentWidth/2);
   
    var totalHeight = getWindowHeight();
    var contentHeight = 600;
    var fromTop = totalHeight/2-contentHeight/2

    var navDiv = MM_findObj('nav');
    var cnt = MM_findObj('content');
    var mnav = MM_findObj('mnav');
       
    var homeBtn = MM_findObj('home');
   
    if(homeBtn){
        var homeLeft = fromLeft - (homeBtn.offsetWidth);
        homeBtn.style.left = (fromLeft-homeBtn.offsetWidth)+'px';
        homeBtn.style.top = (fromTop+1)+'px';
    }
   
    document.getElementById('head').style.left = fromLeft+'px';
    navDiv.style.left = fromLeft+'px';
    cnt.style.left = fromLeft+'px';
    mnav.style.left = fromLeft+'px';
   
    document.getElementById('head').style.marginTop = (fromTop+80)+'px';
   
    document.body.style.backgroundPosition = (fromLeft-107)+'px '+(fromTop-0)+'px';
    navDiv.style.backgroundPosition = (fromLeft-107)+'px '+fromTop+'px';
    cnt.style.backgroundPosition = (fromLeft-107)+'px '+fromTop+'px';



}

function adjustContentHeight(){
	return; // deactivates this function
	cnt = MM_findObj('content');
	frm = MM_findObj('frame');
	frm.style.height = cnt.offsetHeight+'px';
	//window.status = cnt.offsetHeight+'px';
}

function getWindowHeight(win) {    
    if (win == undefined) win = window;    
    if (win.innerHeight) {    
        return win.innerHeight;    
    }    
    else {    
        if (win.document.documentElement    
            && win.document.documentElement.clientHeight) {    
            return win.document.documentElement.clientHeight;    
        }    
        return win.document.body.offsetHeight;    
    }    
}
function getWindowWidth(win) {    
    if (win == undefined) win = window;    
    if (win.innerWidth) {    
        return win.innerWidth;    
    }    
    else {    
        if (win.document.documentElement    
            && win.document.documentElement.clientWidth) {    
            return win.document.documentElement.clientWidth;    
        }    
        return win.document.body.offsetWidth;    
    }    
}


/*
	Dieser Code gehört zum IE6 position:fixed -Hack. 
	Er wird über eine css-expression im Stylesheet aufgerufen.
*/

// Part of an IE < 7 position fixed hack
function correctPosition(oElement,oPos,oWhich) {
  while( oElement.offsetParent ) {
    oPos -= oElement['offset'+oWhich];
    oElement = oElement.offsetParent;
  }
  oPos += document.documentElement['scroll'+oWhich] ? document.documentElement['scroll'+oWhich] : document.body['scroll'+oWhich];
  return oPos;
}


/*
	Popups
*/
 
function openSlide(pDir, pTitle){
	var breite = 480;
	var hoehe = 540;
	var hor = (screen.width/2)-(breite/2);
	var ver = (screen.height/2)-(hoehe/2);
	foto = window.open('slideshow.php?gal='+pDir+'&pic='+pTitle, 'foto', "status=yes, toolbar=no, menubar=no, location=no, resizable=yes, titlebar=no, scrollbars=no, width="+breite+", height="+hoehe+", top="+ver+", left="+hor);
	foto.focus();
	//alert('foo');
}


/*
	Code um die Rollovers des Menüs zu realisieren.
*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
	Dieser auskommentierte Code zeigt alternative Anwendungsmöglichkeiten des eingesetzten 
	IE6 PNG -Hacks auf. Momentan unbenutzt.
*/


//<![CDATA[

 // If you don't want to put nonstandard properties in your stylesheet, here's yet
 // another means of activating the script. This assumes that you have at least one
 // stylesheet included already in the document above this script.
 // To activate, delete the CSS rules above and uncomment below (remove /* and */ ).

 /*
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
  document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {
  document.styleSheets[0].addRule('*', 'behavior: url(inc/iepngfix.htc)');
  // Feel free to add rules for specific elements only, as above.
  // You have to call this once for each selector, like so:
  //document.styleSheets[0].addRule('img', 'behavior: url(iepngfix.htc)');
  //document.styleSheets[0].addRule('div', 'behavior: url(iepngfix.htc)');
 }
 */

 // Here's another script that disables all PNGs in IE when the page is printed.
 /*
 if (window.attachEvent  && /MSIE (5\.5|6)/.test(navigator.userAgent))
 {
  function printPNGFix(disable)
  {
   for (var  i = 0; i < document.all.length; i++)
   {
    var e = document.all[i];
    if (e.filters['DXImageTransform.Microsoft.AlphaImageLoader'] || e._png_print)
    {
     if (disable)
     {
      e._png_print = e.style.filter;
      e.style.filter = '';
     }
     else
     {
      e.style.filter = e._png_print;
      e._png_print = '';
     }
    }
   }
  };
  window.attachEvent('onbeforeprint',  function() { printPNGFix(1) });
  window.attachEvent('onafterprint',  function() { printPNGFix(0) });
 }
 */

 //]]>




