/*******************************************************************************
 * Sitepark.Common.Geometry
 *
 * object, containing PORTABLE functions for querying window
 * and document geometry
 *
 * getWindowX/Y(): return the position of the window on the screen
 * getViewportWidth/Height(): return the size of the browser viewport area
 * getDocumentWidth/Height(): return the size of the document.
 * getHorizontalScroll(): return the position of the horizontal scrollbar
 * getVerticalScroll(): return the position of the vertical scrollbar
 *
 * Note that there is no portable way to query the overall size of the
 * browser window, so there are no getWindowWidth/Height() functions.
 *
 * IMPORTANT: This object must be defined in the <body> of a document
 *            instead of the <head> of the document.
 ******************************************************************************/
if (typeof Sitepark == 'undefined') {
	Sitepark = {};
}
if (typeof Sitepark.Common == 'undefined') {
	Sitepark.Common = {};
}

Sitepark.Common.Geometry = {};

if (window.screenLeft) { // IE and others
  Sitepark.Common.Geometry.getWindowX = function() { return window.screenLeft; };
  Sitepark.Common.Geometry.getWindowY = function() { return window.screenTop; };
} else if (window.screenX) { // Firefox and others
  Sitepark.Common.Geometry.getWindowX = function() { return window.screenX; };
  Sitepark.Common.Geometry.getWindowY = function() { return window.screenY; };
}

if (window.innerWidth) { // All browsers but IE
  Sitepark.Common.Geometry.getViewportWidth = function() { return window.innerWidth; };
  Sitepark.Common.Geometry.getViewportHeight = function() { return window.innerHeight; };
  Sitepark.Common.Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
  Sitepark.Common.Geometry.getVerticalScroll = function() { return window.pageYOffset; };
} else if (document.documentElement && document.documentElement.clientWidth) { // These functions are for IE6 when there is a DOCTYPE
  Sitepark.Common.Geometry.getViewportWidth = function() { return document.documentElement.clientWidth; };
  Sitepark.Common.Geometry.getViewportHeight = function() { return document.documentElement.clientHeight; };
  Sitepark.Common.Geometry.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
  Sitepark.Common.Geometry.getVerticalScroll = function() { return document.documentElement.scrollTop; };
} else if (document.body.clientWidth) { // These are for IE4, IE5, and IE6 without a DOCTYPE
  Sitepark.Common.Geometry.getViewportWidth = function() { return document.body.clientWidth; };
  Sitepark.Common.Geometry.getViewportHeight = function() { return document.body.clientHeight; };
  Sitepark.Common.Geometry.getHorizontalScroll = function() { return document.body.scrollLeft; };
  Sitepark.Common.Geometry.getVerticalScroll = function() { return document.body.scrollTop; };
}

// These functions return the size of the document. They are not window
// related, but they are useful to have here anyway.
if (document.documentElement && document.documentElement.scrollWidth) {
  Sitepark.Common.Geometry.getDocumentWidth = function() { return document.documentElement.scrollWidth; };
  Sitepark.Common.Geometry.getDocumentHeight = function() { return document.documentElement.scrollHeight; };
} else if (document.body.scrollWidth) {
  Sitepark.Common.Geometry.getDocumentWidth = function() { return document.body.scrollWidth; };
  Sitepark.Common.Geometry.getDocumentHeight = function() { return document.body.scrollHeight; };
}
      
var iframeWidth  = 299;
var iframeHeight = 370;

function openPopupInPage(url)
{
   if (obj = document.getElementById('overlay'))
   {
      strIframe     = "<div class=\"background\"></div><iframe src=\"" + url + "\" style=\"width:" + iframeWidth + "px; height=" + iframeHeight + "px;\" frameborder=\"0\"></iframe>";
      obj.innerHTML = strIframe;
      iframeHeight  = Math.min(iframeHeight,Sitepark.Common.Geometry.getViewportHeight());
      
      intWidth  = Math.max(Sitepark.Common.Geometry.getViewportWidth(),document.getElementsByTagName('html')[0].offsetWidth,document.getElementsByTagName('body')[0].offsetWidth);
      intHeight = Math.max(Sitepark.Common.Geometry.getViewportHeight(),document.getElementsByTagName('html')[0].offsetHeight,document.getElementsByTagName('body')[0].offsetHeight);
      intXPos   = Math.round(0.5*(intWidth-iframeWidth));
      intYPos   = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-iframeHeight)+Sitepark.Common.Geometry.getVerticalScroll());
      
      if (obj.lastChild != null)
      {
         obj.lastChild.style.width  = iframeWidth + "px";
         obj.lastChild.style.height = iframeHeight + "px";
         obj.lastChild.style.left   = Math.max(0,intXPos) + "px";
         obj.lastChild.style.top    = Math.max(0,intYPos) + "px";
         //obj.lastChild.contentWindow.document.getElementById('popupContent').style.height = (Math.min(iframeHeight,Sitepark.Common.Geometry.getViewportHeight())-19) + "px";
         window.setTimeout("resizePopupInPage()", 1250);
      }
      
      obj.style.height  = intHeight + "px";
      obj.style.display = "block";
   }
}

function resizePopupInPage()
{
   if (obj = document.getElementById('overlay'))
   {
      var reset = false; 
      iframeHeight = Math.min(iframeHeight,Sitepark.Common.Geometry.getViewportHeight());
      if(obj.lastChild) {
        if(obj.lastChild.contentWindow) {
          if(obj.lastChild.contentWindow.document) {
            if(obj.lastChild.contentWindow.document.getElementById('PopUpBanner')) {
              if(obj.lastChild.contentWindow.document.getElementById('PopUpBanner').getElementsByTagName("img")[0]) {
                iframeWidth  = obj.lastChild.contentWindow.document.getElementById('PopUpBanner').getElementsByTagName("img")[0].offsetWidth+20;
                iframeHeight = obj.lastChild.contentWindow.document.getElementById('PopUpBanner').getElementsByTagName("img")[0].offsetHeight;
                reset        = true;
              }
            }
          }
        }
      }

      intWidth  = Math.max(Sitepark.Common.Geometry.getViewportWidth(),document.getElementsByTagName('html')[0].offsetWidth,document.getElementsByTagName('body')[0].offsetWidth);
      intHeight = Math.max(Sitepark.Common.Geometry.getViewportHeight(),document.getElementsByTagName('html')[0].offsetHeight,document.getElementsByTagName('body')[0].offsetHeight);
      intXPos   = Math.round(0.5*(intWidth-iframeWidth));
      intYPos   = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-iframeHeight)+Sitepark.Common.Geometry.getVerticalScroll());
      
      obj.style.height  = intHeight + "px";
      
      if (obj.lastChild != null && obj.lastChild.contentWindow != null)
      {
         if(reset) {
           obj.lastChild.style.height = (iframeHeight+44) + "px";
           obj.lastChild.style.width  = (iframeWidth+20)  + "px";
           obj.lastChild.style.left   = Math.max(0,intXPos) + "px";
           obj.lastChild.style.top    = Math.max(0,intYPos) + "px";
           obj.lastChild.contentWindow.document.getElementById('popup').style.height        = (iframeHeight+24) + "px";
           obj.lastChild.contentWindow.document.getElementById('popup').style.width         = (iframeWidth)     + "px";
           obj.lastChild.contentWindow.document.getElementById('popupContent').style.height = (iframeHeight+4)  + "px";
           obj.lastChild.contentWindow.document.getElementById('popupContent').style.width  = (iframeWidth)     + "px";
           if(document.all) {
             obj.lastChild.style.height = (iframeHeight+44) + "px";
             obj.lastChild.style.width  = (iframeWidth+10)  + "px";
             obj.lastChild.contentWindow.document.getElementById('popup').style.height        = (iframeHeight+34) + "px";
             obj.lastChild.contentWindow.document.getElementById('popup').style.width         = (iframeWidth)     + "px";
             obj.lastChild.contentWindow.document.getElementById('popupContent').style.height = (iframeHeight+14) + "px";
             obj.lastChild.contentWindow.document.getElementById('popupContent').style.width  = (iframeWidth+1)   + "px";
           }
         } else {
           obj.lastChild.style.height = iframeHeight + "px";
           obj.lastChild.style.left   = Math.max(0,intXPos) + "px";
           obj.lastChild.style.top    = Math.max(0,intYPos) + "px";
           obj.lastChild.contentWindow.document.getElementById('popupContent').style.height = (iframeHeight-71) + "px";
         }
      }

   }
}

function scrollPopupInPage()
{
   if (obj = document.getElementById('overlay'))
   {
      intYPos = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-Math.min(iframeHeight,Sitepark.Common.Geometry.getViewportHeight()))+Sitepark.Common.Geometry.getVerticalScroll());
      if(obj.lastChild != null) obj.lastChild.style.top = Math.max(0,intYPos) + "px";
   }
}

function closePopupInPage()
{
   if (obj = document.getElementById('overlay'))
   {
      obj.style.display = "none";
      obj.innerHTML     = "";
   }
}

window.onresize = function() { resizePopupInPage(); }
window.onscroll = function() { scrollPopupInPage(); }

function openPopup (url,w,h)
{
  popup =window.open (url,"window","width="+w+",height="+h+",scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1");
}

function popup (url, pid, w, h, scroll)
{
  popup =window.open (url,pid,"width="+w+",height="+h+",scrollbars="+scroll+",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1");
}

function personCard(persID) {
   lastID = "";
   prevID = "";
   nextID = "";
   
   for (var personID in arrPerson)
   {
       tempID = personID.substr(2);
       if (tempID == persID) prevID = lastID;
       if (lastID == persID) nextID = tempID;
       lastID = tempID;
   }
   
   var imgUrl       = (typeof arrPerson['id'+persID]['imgUrl']       != "undefined") ? arrPerson['id'+persID]['imgUrl']       : "";
   var imgWidth     = (typeof arrPerson['id'+persID]['imgWidth']     != "undefined") ? arrPerson['id'+persID]['imgWidth']     : "100";
   var imgHeight    = (typeof arrPerson['id'+persID]['imgHeight']    != "undefined") ? arrPerson['id'+persID]['imgHeight']    : "100";
   var persName     = (typeof arrPerson['id'+persID]['persName']     != "undefined") ? arrPerson['id'+persID]['persName']     : "";
   var persNameUrl  = (typeof arrPerson['id'+persID]['persNameUrl']  != "undefined") ? arrPerson['id'+persID]['persNameUrl']  : "";
   var persEmail    = (typeof arrPerson['id'+persID]['persEmail']    != "undefined") ? arrPerson['id'+persID]['persEmail']    : "";
   var persEmailImg = (typeof arrPerson['id'+persID]['persEmailImg'] != "undefined") ? arrPerson['id'+persID]['persEmailImg'] : "";
   var persPhone    = (typeof arrPerson['id'+persID]['persPhone']    != "undefined") ? arrPerson['id'+persID]['persPhone']    : "";
   var persClaim    = (typeof arrPerson['id'+persID]['persClaim']    != "undefined") ? arrPerson['id'+persID]['persClaim']    : "";
   var persText     = (typeof arrPerson['id'+persID]['persText']     != "undefined") ? arrPerson['id'+persID]['persText']     : "";
   var scope        = (typeof arrPerson['id'+persID]['scope']        != "undefined") ? arrPerson['id'+persID]['scope']        : "";
   
   zWndWidth  = 280;
   zWndHeight = 200;
   
   if (obj = document.getElementById('overlay'))
   {
      var prevLink   = (prevID) ? "<a href=\"javascript:void(0)\" onclick=\"personCard('" + prevID + "')\" class=\"prev\" title=\"vorherige Person\">«</a>" : "<span class=\"prev\">«</span>";
      var nextLink   = (nextID) ? "<a href=\"javascript:void(0)\" onclick=\"personCard('" + nextID + "')\" class=\"next\" title=\"nächste Person\">»</a>" : "<span class=\"next\">»</span>";
      var strContent = "<div class=\"background\"></div>"
                     + "<div id=\"detail\">"
                     + "<div class=\"navi\">"
                     + prevLink
                     + nextLink
                     + "<a href=\"javascript:void(0)\" onclick=\"document.getElementById('overlay').style.display='none'\" class=\"close\" title=\"schließen\">x</a>"
                     + "</div>"
                     + "<div class=\"content\">"
                     + ((imgUrl) ? "<div class=\"imgLeft\"><img src=\"" + imgUrl + "\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" alt=\"" + persName + "\" /></div>" : "")
                     + "<div>"
                     + "<p><strong>" + persName + "</strong></p>"
                     + ((persPhone) ? "<p>Telefon: <span style=\"white-space:nowrap\">" + persPhone + "</span><br>" : "")
                     + ((persEmail) ? "<!--htdig_noindex-->E-Mail: <a href=\"/de/script/mailform.php?to=spc:" + persEmail + "&amp;name=" + persNameUrl + ((scope) ? "&amp;scope=" + scope : "") + "\" onclick=\"window.open(this.href,'kontakt','width=451,height=615,scrollbars=yes');return false;\"><img src=\"" + persEmailImg + "\" alt=\"E-Mail-Adresse\" class=\"email\" onmouseover=\"this.style.borderBottom='1px solid #333333';this.style.marginBottom='-1px'\" onmouseout=\"this.style.borderBottom='0';this.style.marginBottom='0'\"></a><!--/htdig_noindex--></p>" : "")
                     + ((persClaim) ? "<br><p>" + persClaim + "</p>" : "")
                     + "</div>";
                     + ((persText) ? "<div>" + persText + "</div>" : "")
                     + "</div>";
                     + "</div>";
      
      obj.innerHTML = strContent;
      zWndHeight    = Math.min(zWndHeight,Sitepark.Common.Geometry.getViewportHeight());
      
      intWidth  = Math.max(Sitepark.Common.Geometry.getViewportWidth(),document.getElementsByTagName('html')[0].offsetWidth,document.getElementsByTagName('body')[0].offsetWidth);
      intHeight = Math.max(Sitepark.Common.Geometry.getViewportHeight(),document.getElementsByTagName('html')[0].offsetHeight,document.getElementsByTagName('body')[0].offsetHeight);
      intXPos   = Math.round(0.5*(intWidth-zWndWidth));
      intYPos   = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-zWndHeight)+Sitepark.Common.Geometry.getVerticalScroll());
      intYPos   = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-Math.min(iframeHeight,Sitepark.Common.Geometry.getViewportHeight()))+Sitepark.Common.Geometry.getVerticalScroll());
      
      if (obj.lastChild != null)
      {
         obj.lastChild.style.width  = zWndWidth + "px";
         obj.lastChild.style.top    = Math.max(0,intYPos) + "px";
         obj.lastChild.style.left   = "250px";
         obj.lastChild.style.margin = "0";
         //window.setTimeout("resizePopup()", 500);
         window.setTimeout("scrollPopupInPage()", 50);
      }
      
      obj.style.height  = intHeight + "px";
      obj.style.display = "block";
   }
}

function closePopup()
{
   if (obj = document.getElementById('overlay'))
   {
      obj.style.display = "none";
      obj.innerHTML     = "";
   }
}

//### showContent Script  START ###

function showContent(id, obj)
{
  oDiv = document.getElementById("content").firstChild;
  while (oDiv != null) {
    if (oDiv.nodeType == 1) oDiv.style.display="none";
    oDiv = oDiv.nextSibling;
  }
  document.getElementById("c"+id).style.display="block";
  setActive(obj);
}

//Checken ob ein Objekt übergeben wurde, wenn nicht auf ersten Listenpunkt setzen
function checkObj(obj, submenu)
{
  var classPath = null;
  
  if(obj == null)
  {
    classPath = submenu[0];
  }
  else
  {
    classPath = obj.parentNode;
  }
  return classPath;
}

//Alle Listen zurücksetzen auf bestimmte Klassen
function resetList(submenu)
{
  for(nI=0; nI<submenu.length; nI++)
    {
      if(nI==0)
      {
        submenu[nI].className = 'leaf first';
      }
    
      if(nI>0 && nI<submenu.length)
     {
       submenu[nI].className = 'leaf';
     }

      if(nI==submenu.length)
     {
       submenu[nI].className = 'leaf last';
     }
    }
}

 //Klasse vom classPath abfragen und auf active setzen
function setListpoint(classPath)
{
  //Wenn erster Listenpunkt..
  if(classPath.className == 'leaf first')
  {
    classPath.className = 'leaf first active';
  }
  //Wenn normaler Listenpunkt..
  if(classPath.className == 'leaf')
  {
    classPath.className = 'leaf active';
  }
  //Wenn letzter Listenpunkt..
  if(classPath.className == 'leaf last')
  {
    classPath.className = 'leaf last active';
  }
}

function setActive(obj)
{
  //Zeiger auf das Submenu setzen
  var submenu = document.getElementById("submenu").getElementsByTagName("li");
  
  classPath = checkObj(obj, submenu);
  resetList(submenu);
  setListpoint(classPath);  
}

//### showContent Script ENDE ###