/*
var itemsOn = new Array("<span class=\"access\">The current list is </span>All Stops","<span class=\"access\">The current list is </span>Timed Stops <img src=\"/images/fixedImages/ttc-icon-timed-stops.gif\" width=\"15\" height=\"15\" alt=\"Timed stops\"/>","<span class=\"access\">The current list is </span>Accessible Stops <img src=\"/images/fixedImages/ttc-icon-route-access.gif\" width=\"15\" height=\"15\" alt=\"Accessible stops\"/>");
var itemsOff = new Array("<a href=\"#allstops\">All Stops</a>","<a href=\"#timedstops\">Timed Stops  <img src=\"/images/fixedImages/ttc-icon-timed-stops.gif\" width=\"15\" height=\"15\" alt=\"Timed stops\"/></a>","<a href=\"#accessiblestops\">Accessible Stops <img src=\"/images/fixedImages/ttc-icon-route-access.gif\" width=\"15\" height=\"15\" alt=\"Accessible stops\"/></a>");
*/
var tabClass = new Array("",""," last");

var itemsOn = new Array("<span class=\"access\">The current list is </span>Timed Stops","<span class=\"access\">The current list is </span>All Stops","<span class=\"access\">The current list is </span>Accessible Stops");
var itemsOff = new Array("<a href=\"#timedstops\">Timed Stops</a>","<a href=\"#allstops\">All Stops</a>","<a href=\"#accessiblestops\">Accessible Stops</a>");

function Accordian(target) {
   	typeof target == "object" ? this.element = target : this.element = document.getElementById(target); if (!this.element) return false;  
   	this.ul = this.element.getElementsByTagName("ul")[0]; 
   	this.tabs = this.ul.getElementsByTagName("li");
   	this.tabContent = this.getTabContent();
   	this.bind();
   }

   Accordian.prototype.getTabContent = function() {
   	tabContent= new Array();    
   	this.divs = this.element.getElementsByTagName("div");
   	for(var i = 0; i < this.divs.length; i++) {
           if (/tabContent/i.test(this.divs[i].className)) {
           tabContent.push(this.divs[i]);                        
   		}
   	}
   	return tabContent;
   }


   Accordian.prototype.bind = function() {    
   	var o = this;
   	for(var i = 0; i < this.tabs.length; i++) {
   		this.tabs[i].onclick = function() { 
   		   if (this.className != 'selected') {
   		      o.open(this); return false;
   		      var a = this.getElementsByTagName("a")[0];
   		      if (a) a.onclick = function() { 
                    return false; 
               }
   		   }
   		} 
   	}
   }

   Accordian.prototype.open = function(caller) {    
   	for(var i = 0; i < this.tabs.length; i++) {
   		var tab = this.tabs[i]; 
   		if (tab == caller) {  
   			this.collapse();
   			tab.className = "selected";
   			this.tabContent[i*4].style.display = "block";
   		}
   	}
   }

   Accordian.prototype.collapse = function() {
   	for(var i = 0; i < this.tabs.length; i++) {    
   		this.tabs[i].className = "";
   		this.tabContent[i*4].style.display = "none";                 
   	}                                                                
   }
   
 /* for sub tabs - attempt to update script */


function AccordianSub(target) {
   	typeof target == "object" ? this.element = target : this.element = document.getElementById(target);
      if (!this.element) return false;  
   	this.ul = this.element.getElementsByTagName("ul")[0]; 
   	this.tabs = this.ul.getElementsByTagName("li");
   	this.tabContent = this.getTabContent();
   	this.bind();
	toggleContent(this.tabs[0],0,true);
   }

   AccordianSub.prototype.getTabContent = function() {
   	tabContent= new Array();    
   	this.divs = this.element.getElementsByTagName("div");
   	for(var i = 0; i < this.divs.length; i++) {
           if (/tabContent/i.test(this.divs[i].className)) {
           		tabContent.push(this.divs[i]);                        
   		}
   	}
   	return tabContent;
   }


   AccordianSub.prototype.bind = function() {    
   	var o = this;
   	for(var i = 0; i < this.tabs.length; i++) {
   		this.tabs[i].onclick = function() { 
   		   if (this.className != 'selected') {
   		      o.open(this); return false;
   		      var a = this.getElementsByTagName("a")[0];
   		      if (a) a.onclick = function() { 
                    return false; 
               	}
   		   }
   		} 
   	}
   }

   AccordianSub.prototype.open = function(caller) {    
   	for(var i = 0; i < this.tabs.length; i++) {
   		var tab = this.tabs[i]; 
   		if (tab == caller) {  
   			this.collapse();
   			tab.className = "selected"+tabClass[i];
   			this.tabContent[i].style.display = "block";
			toggleContent(tab,i,true);
   		}
   	}
   }

   AccordianSub.prototype.collapse = function() {
   	for(var i = 0; i < this.tabs.length; i++) {    
   		this.tabs[i].className = tabClass[i];
   		this.tabContent[i].style.display = "none";     
   		 //var a = this.tabs[i].getElementsByTagName("a")[0];
		 toggleContent(this.tabs[i],i,false);
   	}                                                                
   }

function toggleContent(obj, tabIndex,enable) {
  if (enable) {
	obj.innerHTML=itemsOn[tabIndex];
  } else {
      obj.innerHTML=itemsOff[tabIndex];
  }
}


function redirect(loc) {
  document.location = loc;
}
     
function changeBackground(obj, className) {
  obj.className = className;
}
