var currentArea = 1;
var currentTab = 0;

// Record the current position of each tab i.e. left = 0, right = 1;
var tab = new Array();
tab[0] = 0; // Leave this empty
tab[1] = 1;
tab[2] = 1;
tab[3] = 1;
tab[4] = 1;
tab[5] = 1;
var tabCount = 5;

// Function to turn homepage buttons on and off
function windowButtons(id,image) {
	document.getElementById(id).src = image;
	}

// Animate the div
function animateWidth(id,width) {
	var attributes = {   
		width: { to: width } 
		};   
	var anim = new YAHOO.util.Anim(id, attributes, 0.5); 
	anim.animate();  
	}
	
function tabMouseOver(id) {
	if (currentTab != id) {
		if (tab[id] == 1) {
			document.getElementById('tab-' + id).src = 'images/tab-' + id + '-right-on.png';
			} else {
			document.getElementById('tab-' + id).src = 'images/tab-' + id + '-left-on.png';
			}
		}
	}
	
function tabMouseOut(id) {
	if (currentTab != id) {
		if (tab[id] == 1) {
			document.getElementById('tab-' + id).src = 'images/tab-' + id + '-right-off.png';
			} else {
			document.getElementById('tab-' + id).src = 'images/tab-' + id + '-left-off.png';
			}
		}
	}
	
function homeTabOnClick(id) {
	divPrefix = 'homeArea-';
	openWidth = '837';
	
	// Where is the tab? left or right?
	if (tab[id] == 1) {
		// It's on the right
		
		// Close the open area
		animateWidth(divPrefix + currentArea,0);
		
		areaToOpen = id + 1;
		
		// Open the new area
		animateWidth(divPrefix + areaToOpen, openWidth);	
		
		// Set the new open div
		currentArea = areaToOpen;
		
		// Set tab to left
		tab[id] = 0;
		currentTab = id;
		
		// Set other tabs if needed
		count = 1;
		while (count < id || count == id) {
			if (count == id) {
				document.getElementById('tab-' + id).src = 'images/tab-' + id + '-selected.png';		
				} else {
				tab[count] = 0;
				tabMouseOut(count);
				}
			count = count + 1
			}
		
		} else {
		// It's on the left
		
		// Close the open area
		animateWidth(divPrefix + currentArea,0);
		
		areaToOpen = id;
		if (areaToOpen < 1) areaToOpen = 1;
		
		// Open the new area
		animateWidth(divPrefix + areaToOpen, openWidth);	
		
		// Set the new open div
		currentArea = areaToOpen;
		
		// Set tab to right
		tab[id] = 1;
		currentTab = id - 1;
		if (currentTab != 0) document.getElementById('tab-' + currentTab).src = 'images/tab-' + currentTab + '-selected.png';
		
		// Set other tabs if needed
		count = id;
		while (count < tabCount  || count == tabCount) {
			tab[count] = 1;
			tabMouseOut(count)
			count = count + 1;
			}
		
		}
	
	
	}