var SecondFloor = {
  // Our onload interface. A page adds as many onload actions by using
  // the addLoader API call. We take care of calling all of these
  // actions at page load time.
  Loaders : [],
  // Add a function to be called at page load.
  addLoader : function(f) {
    this.Loaders.push(f);
  },
  // Our singular onload action.
  load : function() {
    for (var i=0; i<this.Loaders.length; i++) {
      this.Loaders[i]();
    }
    this.Loaders = [];
  },

  // Our onunload interface. A page adds as many onunload actions by
  // using the addUnloader API call. We take care of calling all of
  // these actions at page unload time.
  Unloaders : [],
  // Add a function to be called at page load.
  addUnloader : function(f) {
    this.Unloaders.push(f);
  },
  // Our singular onunload action.
  unload : function() {
    for (var i=0; i<this.Unloaders.length; i++) {
      this.Unloaders[i]();
    }
    this.Unloaders = [];
  },

  markup : function(tag,options,content) {
    var parts = [];
    for (var option in options) {
      parts.push(option + "='" + (options[option]) + "'");
    }
    if (content.constructor == Array) {
      content = content.join('');
    }
    // Alternative: Use DOM calls.
    return "<" + tag + ' ' + parts.join(' ') + ">" + content + "</" + tag + ">";
  },

  // Helper: Write an email address to the document.
  write_email : function(addr,txt) {
    document.write(this.markup('a', { href : "mailto:" + addr }, txt));
  },

  // Helper: Write an email address to the document using some known domain/tld.
  email : function(username,realname) {
    var domain = "gweep";
    var tld      = "net";
    var addr     = username + '@' + domain + '.' + tld;
    this.write_email(addr,realname);
  },

  email_addr : function(username) {
    var hostname = "gweep";
    var tld      = "net";
    var addr     = username + '@' + hostname + '.' + tld;
    this.write_email(addr,addr);
  },

  // coerce generic_email_addr(['first','last'],['domain','tld'])
  // to first.last@domain.tld
  generic_email_addr : function(user_parts,host_parts) {
    var addr = user_parts.join('.') + "@" + host_parts.join('.')
    this.write_email(addr,addr);
  },

  // Array of sidebar images which will be randomly selected.
  sidebarImages : ['Driving', 'ParisEiffel', 'Vienna',
		   'GrandCanyon', 'Performing', 
		   'MonumentValley', 'SanDiegoFlower'],
  
  imageRoot : '/~aron/images/',
  // imageRoot : 'images/',

  // Generate an image tag referencing a random image.
  sidebarImage : function() {
    var randImgIdx  = Math.round(Math.random()*(this.sidebarImages.length-1));
    var chosenImage = this.sidebarImages[randImgIdx];
    document.write('<img id="vanity" src="' + this.imageRoot + chosenImage + '.jpg" alt="random banner image" />');
  }
};

getViewportWidth = function() {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
};

getViewportHeight = function() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
  
};
