var sections = {};
var buttons = {};
var sliderLocations = {};
var capContent = {};
var capIcons = {};

var benContent = {};
var benIcons = {};

var slider = null;

var aboutLink = null;
var careersLink = null;
var solutionsLink = null;

var targetX = -1;
var easing = .2;
var timerId = 0;
var app = null;
var logoOn = new Image();
logoOn.src = "images/ras_logotype-noshadow3.png";

var directionsMD = null;
var directionsVA = null;
var directionsWindow = null;
var directionsWindowHeader = null;
var dragDirections = false;
var me = null
var mouseX = 0;
var mouseY = 0;
var dragWindowOffsetX = 0;
var dragWindowOffsetY = 0;

function init()
{
		
	slider = document.getElementById("slider");

	sliderLocations["home"] = "105px";
	sliderLocations["about"] = "302px";
	sliderLocations["solutions"] = "407px";
	sliderLocations["careers"] = "522px";
	sliderLocations["contact"] = "627px";

	buttons["about"] = document.getElementById("about");
	buttons["solutions"] = document.getElementById("solutions");
	buttons["careers"] = document.getElementById("careers");
	buttons["contact"] = document.getElementById("contact");

	sections["home"] = document.getElementById("homeContent");
	sections["about"] = document.getElementById("aboutContent");
	sections["solutions"] = document.getElementById("solutionsContent");
	sections["careers"] = document.getElementById("careersContent");
	sections["contact"] = document.getElementById("contactContent");

	capContent["software"] = document.getElementById("softwareContent");
	capContent["systems"] = document.getElementById("systemsContent");
	capContent["network"] = document.getElementById("networkContent");
	capContent["database"] = document.getElementById("databaseContent");
	capContent["intelligence"] = document.getElementById("intelligenceContent");
	capContent["information"] = document.getElementById("informationContent");
	capContent["forensics"] = document.getElementById("forensicsContent");

	benContent["retirement"] = document.getElementById("retirementContent");
	benContent["health"] = document.getElementById("healthContent");
	benContent["leave"] = document.getElementById("leaveContent");
	benContent["college"] = document.getElementById("collegeContent");
	benContent["training"] = document.getElementById("trainingContent");
	benContent["insurance"] = document.getElementById("insuranceContent");
	benContent["bonus"] = document.getElementById("bonusContent");
	benContent["masters"] = document.getElementById("mastersContent");

	
	benIcons["retirement"] = document.getElementById("retirementIcon");
	benIcons["health"] = document.getElementById("healthIcon");
	benIcons["leave"] = document.getElementById("leaveIcon");
	benIcons["college"] = document.getElementById("collegeIcon");
	benIcons["training"] = document.getElementById("trainingIcon");
	benIcons["insurance"] = document.getElementById("insuranceIcon");
	benIcons["bonus"] = document.getElementById("bonusIcon");
	benIcons["masters"] = document.getElementById("mastersIcon");

	
	capIcons["software"] = document.getElementById("softwareIcon");
	capIcons["systems"] = document.getElementById("systemsIcon");
	capIcons["network"] = document.getElementById("networkIcon");
	capIcons["database"] = document.getElementById("databaseIcon");
	capIcons["intelligence"] = document.getElementById("intelligenceIcon");
	capIcons["information"] = document.getElementById("informationIcon");
	capIcons["forensics"] = document.getElementById("forensicsIcon");


	targetX = parseInt(sliderLocations["home"]);
	timerId = setInterval("renderLoop()", 10);

	selectAboutSubLink(document.getElementById("philosophyLink"));
	selectCareersSubLink(document.getElementById("whyRedArchLink"));
	selectSolutionsSubLink(document.getElementById("strategyLink"));	

	
	//slider.style.left = sliderLocations["home"];
	directionsWindow = document.getElementById("directionsWindow");
	directionsMD = document.getElementById("directionsMD");
	directionsVA = document.getElementById("directionsVA");

	directionsWindowHeader = document.getElementById("directionsWindowHeader");

	//want to not disable text selection
	//	document.onselectstart= function(e){return false;}
	document.onmousemove = function(e){

if (window.event)
		{
			window.event.cancelBubble = true;
		}
		else if (e)
		{
			e.cancelBubble = true;
		}

		//document.getElementById("directionsWindow").innerHTML = getMouseX(e);
		mouseX = getMouseX(e);
		mouseY = getMouseY(e);
	}	
	
	directionsWindowHeader.onmousedown = function(e)
	{
		//self.startDrag(e);
		//alert("start drag");
		dragDirections = true;
		var mX = getMouseX(e);
		var left = findLeftOfObj(directionsWindow);
		var mY = getMouseY(e);
		var top = findTopOfObj(directionsWindow);
		dragWindowOffsetY = mY - top;
		dragWindowOffsetX = mX - left;
		return false;
	}
	document.onmouseup = function(e){
		dragDirections = false;
	}
	directionsWindowHeader.onselectstart= function(){return false;};
}
getMouseX = function(e)
{
	var x = 0;
	if (window.event)
	{
	 	x = window.event.clientX + document.body.scrollLeft;
	}		
	else if (e)
	{
		x = e.clientX + document.body.scrollLeft;	
	}	
	return x;
}
getMouseY = function(e)
{		
	var y = 0;
	if (window.event)
	{
		y = window.event.clientY + document.body.scrollTop;
	}		
	else if (e)
	{
		y = e.clientY + document.body.scrollTop;
	}	
	return y;
}

findTopOfObj = function(obj)
	{
		if(obj == null)
		{
			return;	
		}
		//app.console.printInfo(this, "in findTopOfObj");
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
findLeftOfObj = function(obj)
	{
		if(obj == null)
		{
			return;	
		}
		//app.console.printInfo(this, "in findLeftOfObj");
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
this.getBrowserWidth = function()
	{
		var x,y;
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return x;
	}
	this.getBrowserHeight = function()
	{
		var x,y;
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return y;
	}
function overLink(link)
{
	if(link != careersLink && link != solutionsLink && link != aboutLink)
	{
		link.className="rasLinkOver";
	}
}
function outLink(link)
{
	if(link != careersLink && link != solutionsLink && link != aboutLink)
	{
		link.className="rasLink";
	}
}
function selectAboutSubLink(link)
{
	if(aboutLink != null)
	{
		aboutLink.className = "rasLink";
	}
	aboutLink = link;
	link.className="rasLinkSelected";
}
function selectCareersSubLink(link)
{
	if(careersLink != null)
	{
		careersLink.className = "rasLink";
	}
	careersLink = link;
	link.className="rasLinkSelected";
}
function selectSolutionsSubLink(link)
{
	if(solutionsLink != null)
	{
		solutionsLink.className = "rasLink";
	}
	solutionsLink = link;
	link.className="rasLinkSelected";
}
function highlight(section)
{
	//buttons[section].style.backgroundColor = "#F1F1F1";
	//buttons[section].style.color = "#666666";
	
}
function unHighlight(section)
{
	//buttons[section].style.backgroundColor = "#FFFFFF";
	//buttons[section].style.color = "#666666";
}
function nav(section)
{
	hideAll();
	sections[section].style.display="block";
	if(section!="home")
	{
		buttons[section].style.color="#ED1C24";
		
	}

	targetX = parseInt(sliderLocations[section]);
	//timerId = setInterval("renderLoop()", 10);
	//alert(timerId);
	//slider.style.left = sliderLocations[section];

}
function hideAll()
{
	directionsWindow.style.display = "none";

	for(var i in sections)
	{
		
		sections[i].style.display="none";
	}
	for(var i in buttons)
	{
		
		buttons[i].style.color = "#666666";
		buttons[i].style.backgroundColor = "#FFFFFF";
	}
}
function scroll(div, dir)
{
	var obj = document.getElementById(div);
	obj.scrollTop += 5;
}
function renderLoop()
{
	if(dragDirections)
	{
		
		//alert(getMouseX(me));
		directionsWindow.style.left = mouseX - dragWindowOffsetX + "px";
		directionsWindow.style.top = mouseY - dragWindowOffsetY + "px";
		//directionsWindow.style.top = mouseY + "px";
	}

	var left = parseInt(slider.style.left);
	//alert("targetX:" + targetX + ", left:" + left);
	if(left != targetX )
	{
		var dx = targetX - left;
		var vx = dx * easing;
		left += Math.ceil(vx);
		slider.style.left = (left + "px");			
	}
	else
	{
		//alert("clearInterval: " + timerId);
		
		//clearInterval(timerId);
	}
}
function navSolutions(section)
{	
	document.getElementById("solutionsList").style.display = "none";
	document.getElementById("strategy").style.display = "none";

	document.getElementById(section).style.display = "block";
	selectSolutionsSubLink(document.getElementById(section+"Link"));
}
function navAbout(section)
{	
	document.getElementById("philosophy").style.display = "none";
	document.getElementById("leadership").style.display = "none";
	document.getElementById("vm").style.display = "none";
	
	document.getElementById(section).style.display = "block";
	selectAboutSubLink(document.getElementById(section+"Link"));
}
function capNav(cap)
{
	hideAllCapabilities();
	capContent[cap].style.display = "block";
	capIcons[cap].src = "images/colorlogo.jpg";
}
function hideAllCapabilities()
{
	for(var i in capContent)
	{
		
		capContent[i].style.display="none";
	}
	for(var i in capIcons)
	{
		capIcons[i].src = "images/bwlogo.jpg";
	}
}
function benNav(ben)
{
	hideAllBenefits();
	benContent[ben].style.display = "block";
	benIcons[ben].src = "images/colorlogo.jpg";
}
function hideAllBenefits()
{
	for(var i in benContent)
	{
		
		benContent[i].style.display="none";
	}
	for(var i in benIcons)
	{
		benIcons[i].src = "images/bwlogo.jpg";
	}
}
function navCareers(section)
{	
	document.getElementById("whyRAS").style.display = "none";
	document.getElementById("benefits").style.display = "none";
	document.getElementById("opportunities").style.display = "none";

	document.getElementById(section).style.display = "block";
}
function showDirections(loc)
{
	directionsWindow.style.display = "block";
	directionsWindow.style.left = getBrowserWidth()/2 - 225 + "px";
directionsWindow.style.top = "75px";

	directionsVA.style.display = "none";
	directionsMD.style.display = "none";

	

	if(loc == "md")
	{
		directionsMD.style.display = "block";
		directionsWindowHeader.innerHTML = "<b>red arch solutions, MD</b>";
	}
	else
	{
		directionsVA.style.display = "block";
		directionsWindowHeader.innerHTML = "<b>red arch solutions, VA</b>";
	}
}
function navDirections(d)
{
	document.getElementById("mdFromNorthLink").className = "rasLink";

	document.getElementById("directionsMDFromNorth").style.display = "none";
	document.getElementById("directionsMDFromSouth").style.display = "none";
	
	document.getElementById(d).style.display = "block";
	
		
}
function navVADirections(d)
{
	document.getElementById("vaFromNorthLink").className = "rasLink";
	document.getElementById("directionsVAFromNorth").style.display = "none";
	document.getElementById("directionsVAFromSouth").style.display = "none";

	document.getElementById(d).style.display = "block";

}
function closeDirections(){
	directionsWindow.style.display = "none";
}
