var boxtop = 0;
var t;
var a;
var x;
var z;

var box = new Array();
box[0] = 'slide0';
box[1] = 'slide1';
box[2] = 'slide2';
box[3] = 'slide3';
box[4] = 'slide4';

var content = new Array();
content[0] = 'slide-content0';
content[1] = 'slide-content1';
content[2] = 'slide-content2';
content[3] = 'slide-content3';
content[4] = 'slide-content4';

var slideLink = new Array();
slideLink[0] = 'slide-link0';
slideLink[1] = 'slide-link1';
slideLink[2] = 'slide-link2';
slideLink[3] = 'slide-link3';
slideLink[4] = 'slide-link4';


//adds CSS stylesheet that hides the elements. Gets rid of flicker before page loads!
(function () {
	var head = document.getElementsByTagName("head")[0];
	if (head) {
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = "/templates/employment/stylesheet/flicker.css";
		head.appendChild(scriptStyles);
	}
}());


//main function, determines which function is next
function menuSwitch(a) { 
	boxtop = 0;
	//reset heights of boxes
	for (i in box){
		document.getElementById(box[i]).style.height= boxtop + 'px' ;
		document.getElementById(box[i]).style.overflow = 'hidden';
	}
	//rest color of links
	for (i in slideLink){
		document.getElementById(slideLink[i]).firstChild.style.color = '#000000';
	}
		
	//find height of content, lets text be resized and it will adjust
	z = document.getElementById(content[a]).offsetHeight;
	//change link color to green
	document.getElementById(slideLink[a]).firstChild.style.color = '#156570';
	slideDown(a);
}

function slideDown(a){
	if(boxtop <= z){
		//clears the setTimeout, keeps motion from sticking
		clearTimeout(t);
		boxtop = boxtop + 10;
		document.getElementById(box[a]).style.height=boxtop + 'px';
		//reset the variable so when slideDown is called again, it tells itself what it is
		x = a;
		t = window.setTimeout('slideDown(x)', 1);
	}
	if(boxtop>=z){
		document.getElementById(box[a]).style.overflow = 'visible';
		document.getElementById(box[a]).style.height = 'auto';
	}
}



function closeBox(a){
	slideUp(a);	
}


//called by main function menuSwitch
//slideUp moves picture up and hides blank div
function slideUp(a) {
	document.getElementById(box[a]).style.overflow = 'hidden';
	//reset link color
	document.getElementById(slideLink[a]).firstChild.style.color = '#000000';
	if(boxtop >= 10) {
		clearTimeout(t);
		boxtop = boxtop - 10;
		document.getElementById(box[a]).style.height=boxtop + 'px';	
		x = a;
		t = window.setTimeout('slideUp(x)', 1);
	}
}
