/*******************************************************************************
 * 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; };
}

// position for msie 8 and the aktionsbox-class

// Popup fuer Kontaktfomular
function kontakt ()
{
  window.open('/mailform.php',"Kontaktformular","width=586,height=425,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0")
}

// Popup fuer Kontaktfomular
function kontakt_en ()
{
  window.open('/mailform_en.php',"Kontaktformular","width=586,height=418,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0")
}

// Popup fuer Sitemap width = 274 + scrollbar (16) = 290
function sitemap ()
{
  window.open('/sitemap.html',"Sitemap","width=290,height=418,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0")
}

// Popup fuer Sitemap width = 274 + scrollbar (16) = 290 - englisch
function sitemap_en ()
{
  window.open('/sitemap_en.html',"Sitemap","width=290,height=418,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0")
}

// Popup fuer GIS
function gis ()
{
  window.open('http://www.duisburg.de/gis/stadtplan/hrclient/stadtplan.php',"Stadtplan","width=980,height=725,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1")
}

// Popup fuer GIS - englisch
function gis_en ()
{
  window.open('http://www.duisburg.de/gis/stadtplan/hrclient/stadtplan.php?lang=en',"Stadtplan","width=980,height=725,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1")
}

// Popup fuer Internet Policy und Impressum
function policyimpressum (anchor)
{
  var jump;
  jump = '';
  if (anchor == 'impressum') { jump = '#' + anchor; }
  window.open('/policy.html' + jump,"Impressum","scrollbars=1,toolbar=0,menubar=0,status=0,location=0,directories=0,resizable=0,width=568,height=418")
}

// Popup fuer Internet Policy und Impressum - englisch
function policyimpressum_en (anchor)
{
  var jump;
  jump = '';
  if (anchor == 'impressum') { jump = '#' + anchor; }
  window.open('/policy_en.html' + jump,"Impressum","scrollbars=1,toolbar=0,menubar=0,status=0,location=0,directories=0,resizable=0,width=568,height=418")
}

zeigen     = "block";
verstecken = "none";

function machauf(id1,id2)
{
  if (document.getElementById)
  {
    document.getElementById(id1).style.display=zeigen;
    document.getElementById(id2).style.display=verstecken;
  }
  else
  {
    eval(id1+".style.display=zeigen");
    eval(id2+".style.display=verstecken");
  }
}

// farbwechsel bei aenderungen in eingabefelder
function changed(id)
{
  id.style.color = "#BB0000";
  changeAlert = true;
}


function movieSummary(movID)
{
   lastID = "";
   prevID = "";
   nextID = "";
   
   for (var movieID in arrMovSummary)
   {
       tempID = movieID.substr(2);
       if (tempID == movID) prevID = lastID;
       if (lastID == movID) nextID = tempID;
       lastID = tempID;
   }
   
   var imgUrl     = (arrMovSummary['id'+movID]['imgUrl']   != null) ? arrMovSummary['id'+movID]['imgUrl']    : "";
   var imgWidth   = (arrMovSummary['id'+movID]['imgWidth'] != null) ? arrMovSummary['id'+movID]['imgWidth']  : "";
   var imgHeight  = (arrMovSummary['id'+movID]['imgHeight']!= null) ? arrMovSummary['id'+movID]['imgHeight'] : "";
   var movTitle   = (arrMovSummary['id'+movID]['title']    != null) ? arrMovSummary['id'+movID]['title']     : "";
   var movSummary = (arrMovSummary['id'+movID]['summary']  != null) ? arrMovSummary['id'+movID]['summary']   : "";
   var movCopyr   = (arrMovSummary['id'+movID]['copyr']    != null) ? arrMovSummary['id'+movID]['copyr']     : "";
   
   zWndWidth  = 640;
   zWndHeight = 600;
   
   if (obj = document.getElementById('overlay'))
   {
      var prevLink   = (prevID) ? "<a href=\"javascript:void(0)\" onclick=\"movieSummary('" + prevID + "')\" class=\"prev\">«</a>" : "<span class=\"prev\">«</span>";
      var nextLink   = (nextID) ? "<a href=\"javascript:void(0)\" onclick=\"movieSummary('" + nextID + "')\" class=\"next\">»</a>" : "<span class=\"next\">»</span>";
      var strSummary = "<div class=\"background\"></div>"
                     + "<div id=\"summary\">"
                     + "<div class=\"navi\">"
                     + prevLink
                     + nextLink
                     + "<a href=\"javascript:void(0)\" onclick=\"document.getElementById('overlay').style.display='none'\" class=\"close\">x</a>"
                     + "</div>"
                     + "<div class=\"content\">"
                     + "<div class=\"wrapper\">"
                     + ((imgUrl) ? "<div class=\"image image-left\"><div class=\"image-wrapper\"><img src=\"" + imgUrl + "\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" alt=\"" + movTitle + "\" /></div></div>" : "")
                     + ((movTitle) ? "<h2>" + movTitle + "</h2>" : "")
                     + ((movSummary) ? "<div class=\"paragraph\">" + movSummary + "</div>" : "")
                     + "</div>";
                     + "</div>";
                     + "</div>";
      
      obj.innerHTML = strSummary;
      zWndHeight    = Math.min(zWndHeight,Sitepark.Common.Geometry.getViewportHeight());
      contentHeight = 0;
      
      for (i=0; i<document.getElementById('wrapper').childNodes.length; i++)
      {
         tmpH = document.getElementById('wrapper').childNodes[i].offsetHeight;
         if(typeof tmpH == 'number') contentHeight += tmpH;
      }

      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,contentHeight);
      intXPos   = Math.round(0.5*(intWidth-zWndWidth));
      intYPos   = Math.round(0.5*(Sitepark.Common.Geometry.getViewportHeight()-zWndHeight)+Sitepark.Common.Geometry.getVerticalScroll());
      
      if (obj.lastChild != null)
      {
         obj.lastChild.style.width  = zWndWidth + "px";
         obj.lastChild.style.top    = Math.max(0,intYPos) + "px";
         window.setTimeout("resizePopup()", 500);
      }
      
      obj.style.height  = intHeight + "px";
      obj.style.display = "block";
   }
}
