function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
   var ua = window.navigator.userAgent;
   var msie = ua.indexOf ( "MSIE " );

   if ( msie > 0 )      // If Internet Explorer, return version number
      return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
   else                 // If another browser, return 0
      return 0;
}

var panelID = "p1";
var numDiv = 4;
var numRows = 1;
var tabsPerRow = 4;
var numLocations = numRows * tabsPerRow;
var tabWidth = 60;
var tabHeight = 30;
var vOffset = 6;
var hOffset = 10;

var divLocation = new Array(numLocations);
var newLocation = new Array(numLocations);
   
for(var i=0; i<numLocations; ++i)
{
 divLocation[i] = i;
 newLocation[i] = i;
}
   
function getDiv(s,i)
{
	var div;
	if ( getInternetExplorerVersion() > 0 && getInternetExplorerVersion < 5)
	{
		div = document.all.item(panelID+s+i);
	}
	else div = document.getElementById(panelID+s+i);
	return div;
}
function setZIndex( div, zIndex)
{
	div.style.zIndex = zIndex;
}

function getLocation(i)
{
 return divLocation[i];
}

function setLocation(i, j)
{
 divLocation[i] = j;
}

function getNewLocation(i)
{
 return newLocation[i];
}

function setNewLocation(i, j)
{
 newLocation[i] = j;
}

function updatePosition(div, newPos)
{
 div.style.top = (numRows-(Math.floor(newPos/tabsPerRow) + 1)) * (tabHeight - vOffset);
}
   
function selectTab(n)
{
	var firstTab = Math.floor(getLocation(n) / tabsPerRow) * tabsPerRow;
	for(var i=0; i<numDiv; ++i)
	{
		var loc = getLocation(i);
		if(loc >= firstTab && loc < (firstTab + tabsPerRow)) setNewLocation(i, loc - firstTab)
		else if(loc < tabsPerRow) setNewLocation(i,firstTab+(loc % tabsPerRow))
		else setNewLocation( i, loc);
		loc=null;
	}

	for ( var i=0; i<numDiv; ++i)
	{
		var div = getDiv("tab",i);
		var loc = getNewLocation(i);
		updatePosition(div, loc);
		if ( i == n)
		{
			div.className = "tabactive";
			setZIndex(div, numLocations +1);
		}
		else
		{
			div.className = "tab";
			setZIndex(div, numLocations - loc);
		}
		div = getDiv("panel",i);
		if(i == n) setZIndex(div, numLocations +1)
		else setZIndex(div, numLocations - loc);
		setLocation(i, loc);
		div=null; loc=null;
	}
}
