var sites = new Array();

var Site = Class.create({
  initialize: function(_name, _contentfilename, _linkurl) {
    this.name = _name;
    this.linkurl = _linkurl;
    this.contentfilename = _contentfilename;
    if (_contentfilename == null || _contentfilename.strip().length == 0){
      this.contentfilename = _name.toLowerCase(); 
    }
    this.contenturl = "content/" + this.contentfilename + ".html";
    this.navigation = this.createNavigation();
    this.active = false;
  } 
  ,loadContent: function(){
    showWait(true);
    $("content").update("");
    new Ajax.Updater("content", this.contenturl, {
      onComplete: function(transport){
        transport.responseText.evalScripts(); 
        showWait(false);
      }
      ,onFailure: function(){
        $("content").update("Fehler beim Laden der Seite!");
        showWait(false);
      }
      ,onException: function(requester, exception){
        $("content").update("Die Seite konnte nicht gefunden werden!<br/>"+exception.message);
        showWait(false);
      }
    });
  }
  ,activate: function(activate){
    if (activate == null) activate = true;
    if (activate){
      // Alle anderen Seiten deaktivieren
      for (var i = 0; i < sites.length; i++)
        if (sites[i].name != this.name) sites[i].activate(false);
        
      // Die aktuelle Seite aktivieren
      this.loadContent();
      this.navigation.setStyle({backgroundImage:"url(./images/navigationActive.jpg)","color":"yellow"});
      this.active = true;
    }
    else{
      this.navigation.setStyle({backgroundImage:"url(./images/navigationInactive.jpg)","color":"white"});
      this.active = false;
    }
  }
  ,mouseover: function(){
    if (!this.active){
      this.navigation.setStyle({backgroundImage:"url(./images/navigationMouse.jpg)","color":"yellow"});
    }
  }
  ,mouseout: function(){
    if (!this.active){
      this.navigation.setStyle({backgroundImage:"url(./images/navigationInactive.jpg)","color":"white"});
    }
  }
  ,click: function(){
    if (this.linkurl == null) this.activate();
    else window.open(this.linkurl);
  }
  ,createNavigation: function(){
    var div = new Element("div");
    div.addClassName("navitem");
    var text = new Element("div");
    text.update(this.name);
    div.insert({top:text});
    div.observe("mouseover", this.mouseover.bind(this));
    div.observe("mouseout", this.mouseout.bind(this));
    div.observe("click", this.click.bind(this));
    $("navigation").insert({bottom:div});
    return div;
  }
});

