function initIeHover( navElements ) { 
  for (var i=0; i<navElements.length; i++) {
    navElements[i].onmouseover=function(e) {
      this.className+=" iehover";
    }
    navElements[i].onmouseout=function(e) {
      this.className=this.className.replace(new RegExp(" iehover\\b"), "");
    }
  }
}

function Popup(element) {
  for ( var c in this.dom_classes ) {
    if (element.className.match(c)) {
      var object  = this,
          options = this.dom_classes[c],
          numeric = ['width', 'height'],
          toggles = ['scrollbars','resizable'];
      this.popup_class = c;
      this.element = element;
      this.params = [];
      this.href   = options['template'] || this.element.getAttribute('href')
      this.target = options['target'] || '_blank';
      if (options['title']) this.title = options['title'];
      
      if      (options['width'] > 0)      this.params.push( ['width', options['width']].join('=') );
      else if (options['width']=='auto')  this.width = 'auto';
      if      (options['height'] > 0)     this.params.push( ['height', options['height']].join('=') );
      else if (options['height']=='auto') this.height = 'auto';
      
      for ( b=0; b<toggles.length; b++ ) {
        b = toggles[b];
        if (typeof(options[b]) != 'undefined' ) {
          this.params.push( [b, options[b]].join('=') );
        }
      }
      
      this.params = this.params.join(',');
    	this.element.title = [this.element.title, this.notice].join(' ');
      this.element.onclick = function() { 
        return object.onclick.apply(object, arguments); 
      };
      break; // take the first class
    }
  }
}

Popup.prototype = {
  
  notice: "(opens in a new window)",
  
  dom_classes: { 
    'offsite':    {},
    'external':   {},
    'pdf': {},
    'video': { 
        'width':    480, 
        'height':   380, 
        'scrollbars': 'no', 
        'resizable':  'no', 
        'toolbar':  'no',
        'menubar':  'no',
        'location': 'no',
        'status':   'no',
        'target':   'video_window' }
  },
    
  set: function( name, params ) {
    this.dom_classes[name] = params;
  },
  
  initialize: function() {
    var links = document.getElementsByTagName('a');
    for ( a=0; a < links.length; a++ ) {
      links.a = new Popup( links[a] );
    }
  },
  
  onclick: function(event) {
  	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
  		return true;
  	} else {
  	  var new_window = window.open(this.href, this.target, this.params );
  		if (new_window) {
  		  var remote_onload = [];
  		  
  			if (this.width == 'auto') {
  			  remote_onload.push( function() { this.innerWidth = this.document.body.width; });
  			}
  			if (this.height == 'auto') {
  			  remote_onload.push( function() { this.innerHeight = this.document.body.height; });
  			}
  			if (new_window.focus) new_window.focus();
  			return false;
  		}
  		return false;
  		// return true;
  	}
  }
  
};

window.onload = function() {
  Popup.prototype.initialize();
  if (window.attachEvent) {
    navElements = document.getElementById("nav").getElementsByTagName("LI");
    initIeHover( navElements );
  }
};


