/**
 * Megaputer.com Javascript Library
 * Copyright 2007 Megaputer Intelligence, Inc. All rights reserved
 * Author: Josh Froelich (jfroelich AT megaputer DOT com)
 */

////////////////////////////////////////////////////////////////////////////////////////////////
// Globals

// True if its Internet Explorer
var ie = document.all?true:false;

////////////////////////////////////////////////////////////////////////////////////////////////
// Element Class
// If the id is not found, other functions will cause javascript errors
// XXX: Only tested on MSIE 7+ on WinXP and Firefox
// XXX: The assignment of ID condition is wrong
// XXX: Determine whether to do func prototypes externally
function El(id) {
 
 this.id = ie ? document.getElementById(id): eval('document.all.' + id);

 if(this.id == null) return;

 // Whether the designated element was found
 El.prototype.exists = function exists() {
  return this.id != null && this.id != '';
 }

 // Shows the element
 El.prototype.show = function show() {
  this.id.style.visibility = 'visible';
 }

 // Hides the element
 El.prototype.hide = function hide() {
  this.id.style.visibility = 'hidden'
 }

 // Returns true if the element is visible or the visibility was never changed in which
 // case it was assumed to be visible
 El.prototype.isVisible = function isVisible() {
  return this.id.style.visibility == 'visible' || this.id.style.visibility == '';
 }
 
 // Tests for element equality using each element's ID
 El.prototype.equals = function equals(obj) {
  if(obj == null) return false;
  if(!obj.id) return false;
  if(!obj.id.id) return false;
  return this.id.id == obj.id.id;
 }

 // Sets the innerHTML contents of the element
 El.prototype.setContent = function setContent(html) {
  this.id.innerHTML = html;
 }
 
 // Sets the background of the element
 El.prototype.setBackground = function setBackground(bg) {
  this.id.style.background = bg;
 }
 
 // Returns the DOM element object
 El.prototype.getEl = function getEl() {
  return this.id;
 }

 // Sets the 'src' property for the element
 El.prototype.setSource = function setSource(source) {
  this.id.src = source;
 }
 
 // Returns a string descriptor for this element
 El.prototype.toString = function toString() {
  var name = (this.id && this.id.id) ? this.id.id : '[element]';
  return 'El [id=' + name + ']';
 }
 
 // Sets the property. Enclose the value in quotes if its a string
 El.prototype.setProperty = function setProperty(name,value) {
  if(name == null || name == '') return;
  eval('this.id.' + name + '=' + value + ';');
 }
}

////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////
// IMAGE UTILITIES

// Periodically rotates images in the slides array
function rotateImage(idx,offset) {
 if(idx >= slides.length) idx = 0;
 var s = new El("slide"+offset);
 s.setSource(slides[idx]);
 idx++;
 offset++;
 if(offset == 4) offset = 1;
 setTimeout("rotateImage("+idx+","+offset+")",2000);
}

// Given the element id, finds it and sets its source property to the given path
// Fails if the element was not found
// Returns true if successful
function swapImage(elementId, path) {
 var el = new El(elementId);
 if(!el.exists()) return false;
 el.setSource(path);
 return true;
}


////////////////////////////////////////////////////////////////////////////////////////////////
// Miscellaneous funcs

// Writes an email link via Javascript so normal crawlers cannot grab it to avoid spam
function email(user,domain) {
 if (document != null) {
	document.write("<a href=\"mailto:"+user+"@"+domain+"\">"+user+"@"+domain+"</a>");
 }
}