var tabs = new Array(3);

function overTab(tab) {
	sel = tab.getAttribute('selector');
	if (tab.getAttribute('selected') == '1') {
		changeTabBackground(sel, '#7a649c');
		tab.style.color='#ffffff';
	} else {
		changeTabBackground(sel, '#ffeb7a');
		tab.style.color='#5c248f';
	}
}

function outTab(tab) {
	sel = tab.getAttribute('selector');
	if (tab.getAttribute('selected') == '1') {
		changeTabBackground(sel, '#7a649c');
	} else {
		changeTabBackground(sel, '#e0dfe4');
		tab.style.color='#5c248f';
	}
}

function clickTab(tab) {
	isCurrent = tab.getAttribute('selected') || 0;
	if (isCurrent) {
	  return;
	} else {
	  for (i = 0; i < tabs.length; i++) {
		if (tabs[i] == tab) continue;
		x = tabs[i].getAttribute('selected')
		if (x == '1') {
		  deselectTab(tabs[i]);
		}
	  }
	  selectTab(tab);
	}
}

function selectTab(tab) {
	tab.setAttribute('selected', '1')
	sel = tab.getAttribute('selector');
	changeTabBackground(sel, '#7a649c');
	tab.style.color='#ffffff';
}

function deselectTab(tab) {
	tab.setAttribute('selected', '')
	sel = tab.getAttribute('selector');
	changeTabBackground(sel, '#e0dfe4');
	tab.style.color='#5c248f';
}

function changeTabBackground(cssExpr, color) {
	var elems = document.getElementsBySelector(cssExpr)
	for (i = 0; i < elems.length; i++) {
		elems[i].style.background = color;
	}	
}

function init() {
	tabs[0] = document.getElementById('link1');
	tabs[1] = document.getElementById('link2');
	tabs[2] = document.getElementById('link3');
}

function foo() {
	if (tabs[0] == null) {
		init();
	}
	url = frames['toolview'].location.href;
	for (i = 0; i < tabs.length; i++) {
		tab_url = '/' + tabs[i].getAttribute('href');
		s = url.substr(url.length - tab_url.length);
		if (s == tab_url) {
			selectTab(tabs[i]);
			break;
		}
  	}
}
