var segmentList = "homeOffice,smallMedium,largeCorp,reseller,serviceProviders,govt";
var segmentColor = "eb9602,658ac7,726bb0,beb081,a5a49d,67a372";
var aSegList = segmentList.split(",");
var aSegColor = segmentColor.split(",");
var oldSegment = 5;

// add delay before switching tabs
function activateTab(_v,tab) {
if (_v) {
switchID = setTimeout("switchTab('"+tab+"')",500);
}
else {
if (switchID) {
clearTimeout(switchID);
switchID = null;
}
}
}

// switch tabs
function switchTab(tabItem){

var neighbor = parseInt(tabItem)+1;
var totalTabs = aSegList.length-1;

// loop through segment list, set backgrounds and borders for each tab
for(var i=0; i < aSegList.length; i++){
document.getElementById(aSegList[i]+'Button').style.backgroundImage = 'url(/resource/images/homepage/background_home_mainsection.jpg)';
document.getElementById(aSegList[i]+'Button').style.backgroundRepeat= "repeat-x";
document.getElementById(aSegList[i]+'Button').style.backgroundPosition = "left top";
document.getElementById(aSegList[i]+'Link').style.height = '3.6em';
if (i != 0) {
document.getElementById(aSegList[i]+'Link').style.backgroundImage='url(/resource/images/vertBorder.gif)';
document.getElementById(aSegList[i]+'Link').style.backgroundRepeat= "no-repeat";
document.getElementById(aSegList[i]+'Link').style.backgroundPosition = "left 5px";
}	
if (i == tabItem && i != 0 && i != 5) {
document.getElementById(aSegList[i]+'Button').style.backgroundImage='none';
document.getElementById(aSegList[i]+'Link').style.backgroundImage='none';
document.getElementById(aSegList[i]+'Button').style.borderBottom = '1px solid';
document.getElementById(aSegList[i]+'Button').style.borderBottomColor = '#'+aSegColor[tabItem];
document.getElementById(aSegList[i]+'Button').style.borderLeft = '1px solid #ffffff';
document.getElementById(aSegList[i]+'Button').style.borderRight = '1px solid #ffffff';
}

else if (i == tabItem && i == 0) {
document.getElementById(aSegList[i]+'Button').style.backgroundImage='none';
document.getElementById(aSegList[i]+'Button').style.borderLeft = '1px solid';
document.getElementById(aSegList[i]+'Button').style.borderBottom = '1px solid';
document.getElementById(aSegList[i]+'Button').style.borderBottomColor = '#'+aSegColor[tabItem];
document.getElementById(aSegList[i]+'Button').style.borderLeftColor = '#'+aSegColor[tabItem];
document.getElementById(aSegList[i]+'Button').style.borderRight = '1px solid #ffffff';
}
else if (i == tabItem && i == 5) {
document.getElementById(aSegList[i]+'Button').style.backgroundImage='none';
document.getElementById(aSegList[i]+'Link').style.backgroundImage='none';
document.getElementById(aSegList[i]+'Button').style.borderBottom = '1px solid';
document.getElementById(aSegList[i]+'Button').style.borderBottomColor = '#'+aSegColor[tabItem];
document.getElementById(aSegList[i]+'Button').style.borderLeft = '1px solid #ffffff';
document.getElementById(aSegList[i]+'Button').style.borderRight = 'none';
}
}

// remove vert line for neighboring active tab
if (tabItem != totalTabs) {
document.getElementById(aSegList[neighbor]+'Link').style.backgroundImage='none';
}	

// add distinct border bottom color
document.getElementById("segmentArea").style.borderBottom = "4px solid";
document.getElementById("segmentArea").style.borderBottomColor = '#'+aSegColor[tabItem];

// add distinct background color to the tab
document.getElementById(aSegList[tabItem]+'Button').style.backgroundColor = '#'+aSegColor[tabItem];

// reset previous selected tab
if (tabItem != oldSegment) {
document.getElementById(aSegList[oldSegment]+'Button').style.backgroundImage = 'url(/resource/images/homepage/background_home_mainsection.jpg)';
document.getElementById(aSegList[oldSegment]+'Button').style.backgroundRepeat= "repeat-x";
document.getElementById(aSegList[oldSegment]+'Button').style.backgroundPosition = "left top";
document.getElementById(aSegList[oldSegment]+'Button').style.backgroundColor='#'+'767676';
document.getElementById(aSegList[oldSegment]+'Button').style.borderBottom='1px solid #ffffff';
document.getElementById(aSegList[oldSegment]+'Button').style.borderLeft = 'none';
document.getElementById(aSegList[oldSegment]+'Button').style.borderRight = 'none';
}

// display selected tab's content
for(var i=0; i < aSegList.length; i++){
if (i == tabItem) {
document.getElementById(aSegList[i]+'Content').style.visibility = "visible";
}
else {
document.getElementById(aSegList[i]+'Content').style.visibility = "hidden";
}
}

// reset to previous selected tab id
oldSegment = tabItem;
}
