// DFS Homepage JavaScript
var currentPane = 1;

function initHomepageTabs(){
	if(document.getElementById('homepage-tabs')){
		var tabs = document.getElementById('homepage-tabs');
		var li = tabs.getElementsByTagName('li');
		var tabCount = 0;
		var tabWidth = 0;
		var tabNumber = 0;
		while(li[tabCount]){
			if(li[tabCount].id != ''){
				li[tabCount].onmouseover = tabOver;
				li[tabCount].onmouseout = tabOut;
				li[tabCount].onclick = tabOn;
				li[tabCount].tabNum = tabNumber + 1;
				tabNumber++;
			}
			tabWidth += li[tabCount].offsetWidth;
			tabCount++;
		}
		var availablePixels = tabs.offsetWidth - tabWidth;
		var chunk = Math.floor(availablePixels/tabNumber);
		availablePixels = availablePixels % tabNumber;
		tabCount = 0;
		while(li[tabCount]){
			if(li[tabCount].id != ''){
				innerDivs = li[tabCount].childNodes;
				if(availablePixels){
					innerDivs[0].style.width = innerDivs[0].offsetWidth + chunk + 1 + 'px';
					availablePixels--;
				}
				else{
					innerDivs[0].style.width = innerDivs[0].offsetWidth + chunk + 'px';
				}
			}
			tabCount++;
		}
	}
	if(document.getElementById('tab-overlay')) {
		document.getElementById('tab-overlay').style.display ='none'; //fixes the width adjustment of the homepage tabs
	}
	
}

function tabOver(){
	var nodeChildren;
	if(this.className != 'on'){
		nodeChildren = this.childNodes;
		nodeChildren[1].className = 'right-hover';
		this.className = 'hover';
	}
}
function tabOut(){
	var nodeChildren;
	if(this.className != 'on'){
		nodeChildren = this.childNodes;
		nodeChildren[1].className = 'right';
		this.className = '';
	}
}
function tabOn(){
	var nodeChildren;
	if(this.className != 'on'){
		var i = 0;
		var t = document.getElementById('homepage-tabs').getElementsByTagName('li');
		while(t[i]){
			if(t[i].id != ''){
				if((t[i].id != this.id) && (t[i].className == 'on')){
					t[i].className = '';
					t[i].firstChild.nextSibling.className = 'right';
				}
			}
			i++;
		}
		nodeChildren = this.childNodes;
		nodeChildren[1].className = 'right-on';
		this.className = 'on';
		if(document.getElementById('pane'+this.tabNum)){
			if(document.getElementById('pane'+currentPane)){
				document.getElementById('pane'+currentPane).className = 'pane hide';
				document.getElementById('pane'+this.tabNum).className = 'pane';
				currentPane = this.tabNum;
			}
		}
	}
	return false;
}


function initOverlays(){
	var popups = document.getElementsByTagName('a');
	for(var i = 0; i < popups.length; i++){
		if(popups[i].className == 'question-popup'){
			popups[i].onclick = showOverlay;
		}
	}
	if(document.getElementById('homepage-overlay-close')){
		document.getElementById('homepage-overlay-close').onclick = function(){
			document.getElementById('homepage-overlay').style.display = 'none';
			return false;
		}
	}
}
function showOverlay(){
	if(document.getElementById('homepage-overlay')){
		var overlay = document.getElementById('homepage-overlay');
		var pos = findPos(this);
		var content = overlayArray[this.id];
		if(document.getElementById('overlay-content')){
			document.getElementById('overlay-content').innerHTML = content;
			overlay.style.left = pos[0] + 13 + 'px';
			overlay.style.top = pos[1] - 2 + 'px';
			overlay.style.display = 'block';
		}
	}
	return false;
}

 


addLoadEvent(initHomepageTabs);
addLoadEvent(initOverlays);