﻿// start things up!
window.onload = initialize;

function initialize() {

    var currentTabOn = "";

	// find tab elements to change
	var allTabNodes = 
	    document.getElementsByClassName("tabLink");

    // loop elements
	for(i = 0; i < allTabNodes.length; i++){
	
	    // assign a click listener to each tab
		Event.observe(allTabNodes[i],'click',function(e){
		
		    // switch off old tab
		    if (currentTabOn != "") {
                Element.setStyle(currentTabOn, 
                    {background: 'url(\'/App_Themes/Default/Images/tabOff.gif\') no-repeat'});		    
                    
                Element.setStyle(currentTabOn, 
                    {color: '#a73c3b'});                    
		    }
		
		    // start switch
		    switchTab(Event.element(e).id);
		    Event.stop(e); // abort the href link
            currentTabOn = Event.element(e).id;                
            
		    
	
		},false);
		
		// do a mouseover for the tab switch
		Event.observe(allTabNodes[i],'mouseover',function(e){
		
            Element.setStyle(Event.element(e), 
                {background: 'url(\'/App_Themes/Default/Images/tabOn.gif\') no-repeat'});
                
            Element.setStyle(Event.element(e), 
                {color: '#FFFFFF'});                

	
		},false);		
		
		// do a mouseout event for the tab switch
		// note that we skip this if the current tab is rolled over!
		Event.observe(allTabNodes[i],'mouseout',function(e){
		
		    if (currentTabOn != Event.element(e).id) {
		    
                Element.setStyle(Event.element(e), 
                    {background: 'url(\'/App_Themes/Default/Images/tabOff.gif\') no-repeat'});
                    
                Element.setStyle(Event.element(e), 
                    {color: '#a73c3b'});                    
                    
            }                    
	
		},false);		

	};				
	
}

function switchTab(tabToSwitch) {

    // what file are we getting?  base it on the ID passed from the tab clicked on
    // and add .html to it.
    var urlToGet = tabToSwitch + ".html";
		
    // prototype.js AJAX fetcher..get the HTML and yam it into the
    // dynamicBlock
    new Ajax.Updater(dynamicBlock, 
        urlToGet, { method: 'get' });
        
    // switchout the graphical tab        

}