var References = new Object();
window.addListener(References);
References.regions = new Object();
References.buildings = [];
References.onload = function()
{
 if (document.getElementById)
 {
  for (prop in regions)
  {
   References.regions[prop] = [];
   var maxNums = regions[prop].length;
   for (var i = 0; i < maxNums; i++)
   {
    References.regions[prop][regions[prop][i]] = true;
   }
  }
  this.addBuildings();
  this.addRegions();
 }
};
References.addBuildings = function()
{
 var buildings = document.getElementsByClassName('interactive')[0].getElementsByTagName('a');
 var nrOfBuildings = buildings.length;
 var refs = document.getElementById('references').getElementsByTagName('div');
 for (var i = 0; i < nrOfBuildings; i++)
 {
  var building = new Building(buildings[i]);
  building.setName(typesOfBuildings[i]);
  this.buildings.push(building);
  if (refs[i] && refs[i].className.indexOf(buildings[i].className) != -1)
  {
   building.setRef(refs[i]);
  }
 }
};
References.addRegions = function()
{
 for (var prop in this.regions)
 {
  var region = new Region(document.getElementById(prop));
  var available = this.regions[prop];
  var nrOfAvailables = typesOfBuildings.length;
  for (var k = 0; k < nrOfAvailables; k++)
  {
   if (available[k])
   {
    var building = this.buildings[k];
    if (building)
    {
     building.addRegion(region);
     region.addBuilding(building);
    }
   }
  }
 }
};
References.hideBuildings = function()
{
 var i = this.buildings.length;
 while (i--)
 {
  this.buildings[i].hide();
 }
};
References.showBuildings = function()
{
 var i = this.buildings.length;
 while (i--)
 {
  this.buildings[i].show();
 }
};
var Building = function(link)
{
 this._link = link;
 this._link._obj = this;
 this._regions = [];
 this._ref = null;
 this._headline = document.getElementById('building');
 this._img = this._link.getElementsByTagName('img')[0];
 this._outSrc = this._img.src;
 var outID=this._img.id;
 if(document.getElementById(outID+'over')){
     var overIMG=document.getElementById(outID+'over');
     this._overSrc = overIMG.src;
 }else{
 this._overSrc = this._outSrc;
 }
 if(document.getElementById(outID+'notavail')){
     var notavailIMG=document.getElementById(outID+'notavail');
     this._notavailSrc = notavailIMG.src;
 }else{
 this._notavailSrc = this._outSrc;
 }
 var overImg = new Image();
 overImg.src = this._overSrc;
 this._link.onmouseover = this._hilite;
 this._link.onmouseout = this._clear;
};
Building.prototype.setName = function(name)
{
 this._name = name;
};
Building.prototype.addRegion = function(region)
{
 this._regions.push(region);
};
Building.prototype.setRef = function(ref)
{
 this._ref = ref;
};
Building.prototype.show = function()
{
 this._link.style.visibility = 'visible';
 this._img.src = this._outSrc;
};
Building.prototype.hide = function()
{
 this._link.style.visibility = 'hidden';
 this._img.src = this._notavailSrc;
};
Building.prototype._hilite = function()
{
 this._obj._img.src = this._obj._overSrc;
 this._obj._clearHeadline();
 var text = document.createTextNode(this._obj._name);
 if(!modus)this._obj._headline.appendChild(text);
 var regions = this._obj._regions;
 var i = regions.length;
 while(i--)
 {
  regions[i].setClassName('over');
 }
 if (this._obj._ref)
 {
  this._obj._ref.style.display = 'block';
 }
};
Building.prototype._clear = function()
{
 this._obj._img.src = this._obj._outSrc;
 this._obj._clearHeadline();
 var regions = this._obj._regions;
 var i = regions.length;
 while(i--)
 {
  regions[i].unsetClassName();
 }
 if (this._obj._ref)
 {
  this._obj._ref.style.display = 'none';
 }
};
Building.prototype._clearHeadline = function()
{
 var headline = this._headline;
 if (headline.childNodes.length && !modus)
 {
  headline.removeChild(headline.childNodes[0]);
 }
};
var Region = function(item)
{
 this._item = item;
 this._item._obj = this;
 this._buildings = [];
 this._link = this._item.getElementsByTagName('a')[0];
 this._name = this._link.childNodes[1].nodeValue;
 this._headline = document.getElementById('region').getElementsByTagName('span')[0];
 this._item.style.cursor = 'hand';
 if (!this._item.style.cursor)
 {
  this._item.style.cursor = 'pointer';
 }
 this._item.onmouseover = this._hilite;
 this._item.onmouseout = this._clear;
 this._item.onclick = this._go;
};
Region.prototype.addBuilding = function(building)
{
 this._buildings.push(building);
};
Region.prototype.setClassName = function(className)
{
 this._item.className = className;
};
Region.prototype.unsetClassName = function()
{
 this._item.className = '';
};
Region.prototype._hilite = function()
{
 this.className = 'over';
 this._obj._clearHeadline();
 var text = document.createTextNode(this._obj._name);
 this._obj._headline.appendChild(text);
 References.hideBuildings();
 var buildings = this._obj._buildings;
 var i = buildings.length;
 while(i--)
 {
  buildings[i].show();
 }
};
Region.prototype._clear = function()
{
 this.className = '';
 this._obj._clearHeadline();
 References.showBuildings();
};
Region.prototype._clearHeadline = function()
{
 var headline = this._headline;
 if (headline.childNodes.length)
 {
  headline.removeChild(headline.childNodes[0]);
 }
};
Region.prototype._go = function()
{
 location.href = this._obj._link;
 return false;
};
