/* SVN FILE:   $Id: System.js 26 2009-04-15 13:05:24Z a.rouel $
 * SVN HEADER: 1.0
 ***
 * $title           Core/System
 *
 * $description
 *    Schnittstelle zwischen einem Dokument und deren JavaScript-Funktionen.
 *    Angepasst für Babiel-Internet.
 *
 *    Verwendung:
 *      <body onload="System.load()" onunload="System.unload()">
 *      Hinweis: Alternative Verwendung siehe virtuellen Konstruktor (__construct)!
 *
 *
 * $classname       System
 * $author          a.rouel
 * $copyright       $Copyright$
 * $version         $Revision: 26 $
 * $lastrevision    $Date: 2009-04-15 15:05:24 +0200 (Mi, 15 Apr 2009) $
 * $modifiedby      $LastChangedBy: a.rouel $
 * $lastmodified    $LastChangedDate: 2009-04-15 15:05:24 +0200 (Mi, 15 Apr 2009) $
 * $filesource      $URL: http://svn.babiel.com/Babiel/trunk/Projekte/Internet/Projekte/GoogleMap/NPS-Content/htdocs/includes/script/System.js $
 * $keywords        Schnittstelle, JavaScript, Dokument, Funktionen
 * $require
 *
 */

var Controller = function() {
  
  /**
   * Attribut für Funktionen die wärend der Laufzeit von dieser 
   * Instanz kreiert werden und Zugriff auf andere Methoden 
   * benötigen (z.B. EventHandler-Funktionen).
   */
  var I;
    
  /**
   * Instanz einer GoogleMap in einem Dokument
   */
  this.GMap;
  
  
  /**
   * (Virtueller) Konstruktor der Klasse
   */
  this.__construct = function() {
    // Google Maps API laden
    this.includeGoogleMapsAPI();
    // Event-Handler des body-Tags setzen
    window.onload = function() {
      I.load();
    };
    window.onunload = function() {
      I.unload();
    };
    I = this;
  };
    
  this.includeGoogleMapsAPI = function () {
    if( location.hostname == 'www.babiel.com' ) {
      // host-spezifische Variablen (Webserver/Produktivsystem)
      var key = "ABQIAAAAT-Xrx8Bwz0bVch_JS_6hNxSNBtEz0qV2YKVDU31ZZ-xLLpIo2RQ9ZenzhKySutKNOjOsg8Rd6Xz5Ew";
    } else if( location.hostname == '217.79.215.152' ) {
      // host-spezifische Variablen (NPS/Produktivsystem)
      var key = "ABQIAAAAYY4iByjsATuLzqhvLQ3ukhQBDCZNtTeAKfYSeUx3eJbejIW_vxSvNSX_tJId9HG3_BjGvHHdH7cXag";	  
    } else {
      var key = 'none';
    }
    document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=' + key + '" type="text/javascript"></script>');
  };
  
  this.appUri = function () {
    if(location.hostname=='cms.babiel.com') {
  return'../../../'
  }else if(location.hostname=='www.babiel.com') {
  return'../../../'
  }else if(location.hostname=='217.79.215.152') {
  return '../../../' }else{return'../../../'}
  };

  
  this.load = function () {
    
    // Karte laden    
  try
  {
  if(configuration['GoogleMap'] != null)
       this.GMap = new GoogleMap(configuration['GoogleMap']);
    else
       this.GMap = new GoogleMap(null);      
          
    this.GMap.loadMap();
  }
catch(err)
  {
  alert("JavaScript Konfiguration konnte nicht geladen werden");
  //Handle errors here
  }             
   
  };
  
  
  this.unload = function () {
    // GoogleMap-Kram entladen
    GUnload();
  };
   
  this.__construct(); // Aufruf des virtuellen Konstruktors
};  
var System = new Controller();
