﻿/*
File Name:  tabSet.js
Created By:  Andrew Marks
Created:  2/05/08

Dynamically creates a tab set based on the lists of IDs passed in and provides a method to switch between them.

Constructor parameters:
    -- tabAreasList: A pipe-delimited list of the tab content area div IDs
    -- tabIconsList: A pipe-delimited list of the tab icon div IDs
    -- activeTabIconCSSClass: The CSS class applied to a tab icon when it is currently selected
    -- inactiveTabIconCSSClass: The CSS class applied to a tab icon when it is not currently selected
*/

//TabSet class & constructor

//TabSet properties
TabSet.prototype._tabAreas;
TabSet.prototype._tabIcons;
TabSet.prototype._tabactiveList;
TabSet.prototype._tabinactiveList;

function TabSet(tabAreasList, tabIconsList,tabactiveList,tabinactiveList) {
    this._tabAreas = tabAreasList.split("|");
    this._tabIcons = tabIconsList.split("|");
    this._tabactiveList = tabactiveList.split("|");
    this._tabinactiveList = tabinactiveList.split("|");
   }



//TabSet methods
TabSet.prototype.switchTab = function(inTabId, divId,newcss) {
    //The switchTab method is used to automatically switch the currently displaying tab (<div>) and
    //the CSS class of the currently selected tab icon.
    var totalTime = 400;	//Approximate time in milliseconds (varies by browser and CPU speed)
	var FPS = 30;		//Approximate frame rate for the animation (varies by browser and CPU speed)
	var delay = Math.round(1000 / FPS);
	var numFrames = Math.round(totalTime / delay * 1000) / 1000;
	
	var divFrom, divTo;
	var tabFrom, tabTo;
	
	//Find the div that's currently displaying
	for (i = 0; i < this._tabAreas.length; i++) {
		if (document.getElementById(this._tabAreas[i]).style.display == "block") {
			divFrom = document.getElementById(this._tabAreas[i]);
			break;
		}
	}
	
	//Find the div about to be displayed
	divTo = document.getElementById(divId);
	
	//Find the tab that's currently active
	for (i = 0; i < this._tabAreas.length; i++) {
		if (document.getElementById(this._tabIcons[i]).className == this._tabactiveList[i]) {
			tabFrom = document.getElementById(this._tabIcons[i]);
			var inactiveclass=this._tabinactiveList[i];
			break;
		}
	}
	
	//Find the tab about to be displayed
	tabTo = document.getElementById(inTabId);
	
	var currentOpacity
	var opacityIncrement
	if (navigator.appName == "Netscape") {
		opacityIncrement = 1 / numFrames;
		currentOpacity = 1;
	}
	if (navigator.appName == "Microsoft Internet Explorer") {
		opacityIncrement = 100 / numFrames;
		currentOpacity = 100;
	}
	
	//Hide the div currently displaying
	divFrom.style.display = "none";
	//Show the content div for the active tab
	if (divTo != null) {
		divTo.style.display = "block";
		
		//Start with div faded out all the way
		if (navigator.appName == "Netscape") {
			var currentOpacity = 0;
			
			divTo.style.opacity = currentOpacity + 'px';
			
			//fadeIn(divId, currentOpacity, opacityIncrement, delay);
			
			
		}
		if (navigator.appName == "Microsoft Internet Explorer") {
			var currentOpacity = 0;
		}
	}
	
    if (navigator.appName == "Microsoft Internet Explorer") {
	//Deactivate the icon for the tab we came from
	tabFrom.className = inactiveclass;
	//Activate the icon for the tab that was clicked
	tabTo.className =newcss;
	}
	else{
	tabFrom.setAttribute("Class",inactiveclass);
	tabTo.setAttribute("Class",newcss);
	}
	
	for(i=0; i< frames.length; i++)
	{	    	    
	    frames[i].location.reload(true);
	}
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();