// Simple tab switcher
var Tabs = {
  start: function(element){
    if (!element) return false;
    if (element.id) {
	    this.switch_uls = $$('div#' + element.id + ' ul.tabs')
	    this.activate_switches();
	}
  },

  activate_switches : function(){
    if (!this.switch_uls) return false;
    for(i=0;i<this.switch_uls.length;i++){
      switches = this.switch_uls[i].getElementsByTagName('a');
      for (j=0;j<switches.length;j++){
        if (Element.hasClassName(switches[j], 'active')){ // currently selected
          this.active_switch = switches[j];
          this.active_tab = this.get_tab(this.active_switch);

        }
        switches[j].onclick = function(){
          Tabs.switch_to(this);
          return false;
        }
      }// end switches loop
    }// end switch_uls loop
  },

  get_tab : function(switch_element){
    pattern = /#([a-z][\w.:-]*)$/i
		matches = pattern.exec(switch_element.href);
    return $(matches[1]);
  },

  switch_to : function(switch_element){
    switch_tab = this.get_tab(switch_element);
		this.hide_tab(this.active_tab);
    this.deactivate_switch(this.active_switch);

    this.show_tab(switch_tab);
    this.activate_switch(switch_element);
  },

  hide_tab : function(element){
    element.style.display = 'none';
  },

  deactivate_switch : function(element){ 
    Element.removeClassName(element, 'active');
  },

  show_tab : function(element){
    element.style.display = 'block';
    this.active_tab = element;
  },

  activate_switch : function(element){
    Element.addClassName(element, 'active');
    this.active_switch = element;
  }
}

/* Zebra tables */
var Tables = {
	stripe : function(){
		var tables = document.getElementsByTagName('table');
		
		for(var i=0;i<tables.length;i++){ if (Element.hasClassName(tables[i], 'data')){
				trs = tables[i].getElementsByTagName('tr');
				even = false;
				for(j=0;j<trs.length;j++){ if(even = !even){ Element.addClassName(trs[j], 'even'); }else{ Element.addClassName(trs[j], 'odd') } }
		} }
		
	} 
}


/*	Image Rollovers */
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}
