function DOMGetElement(o) {
  if (document.getElementById) return document.getElementById(o);
  else if (document.all)             return document.all[o];
  else if (document.layers)          return document.layers[o];
  return null;
}
// var dom = (!document.all && document.getElementById);
var dom = DOMGetElement('o');
var swap_index = 0;
var num = 0;
var randomnumber = 0;
var last_randomnumber = 0;
var news_swap_index = 0;
var news_num = 0;
var news_randomnumber = 0;
var news_last_randomnumber = 0;

var imgObj;
var urlObj;
var detailsObj;
clientArray = new Array();
newsArray = new Array();
dataPreLoadArray = new Array();

function ajaxManager()
	{
	var args = ajaxManager.arguments;
	switch (args[0])
		{
		case "client_array_setup":
		// Arrays | Ajax database add on here
			clientArray[0] = new Array('36.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[1] = new Array('34.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[2] = new Array('33.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[3] = new Array('32.gif', 'http://wwwnn.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[4] = new Array('31.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[5] = new Array('30.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[6] = new Array('29.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[7] = new Array('28.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[8] = new Array('27.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[9] = new Array('26.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[10] = new Array('25.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[11] = new Array('24.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[12] = new Array('23.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[13] = new Array('21.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[14] = new Array('20.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[15] = new Array('19.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[16] = new Array('18.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[17] = new Array('17.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[18] = new Array('16.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[19] = new Array('15.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[20] = new Array('14.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[21] = new Array('13.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[22] = new Array('12.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[23] = new Array('11.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[24] = new Array('10.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[25] = new Array('9.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[26] = new Array('8.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[27] = new Array('7.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[28] = new Array('6.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[29] = new Array('5.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[30] = new Array('4.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[31] = new Array('3.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[32] = new Array('2.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[33] = new Array('1.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[34] = new Array('35.gif', 'http://www.engineeringsys.com/Clients.html', '<B>DC</B>', 'DC');
			clientArray[35] = new Array('37.gif', 'http://www.engineeringsys.com/Clients.html', '<B>Federal Aviation Administration</B>', 'FAA');
			clientArray[36] = new Array('38.gif', 'http://www.engineeringsys.com/Clients.html', '<B>State of Maryland, Department of Information Technology</B>', 'FAA');
			clientArray[37] = new Array('39.gif', 'http://www.engineeringsys.com/Clients.html', '<B>District of Colubia, Geographic Information System</B>', 'FAA');
			clientArray[38] = new Array('40.gif', 'http://www.engineeringsys.com/Clients.html', '<B>State of Louisiana</B>', 'LA');
			clientArray[39] = new Array('41.gif', 'http://www.engineeringsys.com/Clients.html', '<B></B>', 'SAIC');
			clientArray[40] = new Array('42.gif', 'http://www.engineeringsys.com/Clients.html', '<B>CSOSA</B>', 'CSOSA');
			clientArray[41] = new Array('43.gif', 'http://www.engineeringsys.com/Clients.html', '<B>State of Louisiana</B>', 'VirtualLouisiana');
			clientArray[42] = new Array('44.gif', 'http://www.engineeringsys.com/Clients.html', '<B>Metropolitan Police Department</B>', 'DCMPD');
			clientArray[43] = new Array('45.gif', 'http://www.engineeringsys.com/Clients.html', '<B>State of Alabama</B>', 'VirutalAlabama');
			clientArray[44] = new Array('46.gif', 'http://www.engineeringsys.com/Clients.html', '<B>Department of Homeland Security</B>', 'DHS');
			
			// Preload all the Image
			for (var i = 0; i < clientArray.length; i++) {
				var loadImage = new Image();
//				loadImage.onerror = 'no_image'
				loadImage.src = 'images/clients/' + clientArray[i][0];
				dataPreLoadArray[i] = loadImage.src;
			}

			break;

		case "news_array_setup":
		// Arrays | Ajax database add on here
			newsArray[0] = new Array('<b>Celebrating over 19 years of excellence in GIS & IT Services to<br>Municipal, Utility, Commercial & Healthcare Sectors.</b>');
			newsArray[1] = new Array('Sucessfully deploys Southern California Gas Company natural gas network flow application<br> to manage over 44,000 miles of distribution mains supporting 5 million customers.');
			newsArray[2] = new Array('Engineering Systems helps Washington DC customize & deploy Google Earth Enterprise<br> Solution as a visualization portal for all GIS/ESRI 200+ data layers.');
			newsArray[3] = new Array('Develops an GIS/GPS based solution for Washington DC Office of the Chief<br> Technology Officer to deploy a real-time tracking and IT Mangement through-out the district.');
			newsArray[4] = new Array('Creates Bicycle GIS Soltuion for Coachella Valley and surrounding areas<br> to accurately identify existing bikeways, trails, golf cart paths and pedestrian ways.');
			newsArray[5] = new Array('Developed an Internet-Based Commercial and Industrial Real Estate Property mapping solution for<br> Magnum Properties using the Microsoft Virtual Earth, and GOOGLE Mashup for access to ownership data.');
			newsArray[6] = new Array('Develops a Real-Estate Mapping Solution covering the continental U.S. with<br> 15 market characteristics for 31 biggest and highest performing areas.');
			newsArray[7] = new Array('Completes the Bikeway Guide project for the City of Los Angeles, Department of Transportation<br>with integrated GPS Surveys, and automated map generation.');
			newsArray[8] = new Array('Develops Town of Vienna GIS-Based Utility Management System to inventory<br> and model water distribution and sanitary sewer collection.');
			newsArray[9] = new Array('Wins project with Town of Vienna, Planning & Zoning department<br>to develop a real-time permiting application to using Esri/ArcIMS, Google Maps,  & Microsoft Virtual Earth.');
			newsArray[10] = new Array('Wins project with the District of Columbia<br>to customize and deploy Google Earth Enterprise for all departments.');
			newsArray[11] = new Array('Wins project with FAA (Federal Aviation Administration)<br>to customize Google Earth Enterprise for all departments.');
			break;

		case "image_cycle":
			if (args[1] == 'forw' && swap_index != clientArray.length - 1) {
				swap_index++;
			}
			else if (args[1] == 'rev' && swap_index != 0)	{
				swap_index--;
			}
			else {
			  swap_index = 0;
			}
			ajaxManager('load_client', clientArray[swap_index]);
			break;

		case "load_client":
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			pageWidth = (dom) ? innerWidth : document.body.clientWidth;
//			preload = document.getElementById("cycleLyr");
//			gallery = document.getElementById("changeLyr");
				setOpacity(0, 'logoLocation');
			if (x)
				{
				x.onreadystatechange = function()
					{
					if (x.readyState == 0)
						{
//						preload.innerHTML = "4";
						}
					else if (x.readyState == 1)
						{
//						preload.innerHTML = "3";
						}
					else if (x.readyState == 2)
						{
//						preload.innerHTML = "2";
						}
					else if (x.readyState == 3)
						{
//							 alert(clientArray[swap_index][1]);
//						preload.innerHTML = "1";
/*
							imgObj = new getObj('imageLocation');
							urlObj = new getObj('urlLocation');
							detailsObj = new getObj('detailsLyr');
							imgObj.src = 'images/clients/' + clientArray[swap_index][0]; 
							urlObj.href = clientArray[swap_index][1];
							detailsObj.innerHTML = clientArray[swap_index][2];
*/
//						document.getElementById('TEST').innerHTML = dataPreLoadArray[swap_index];
						document.getElementById('logoLocation').src = dataPreLoadArray[swap_index];
//						document.getElementById('logoLocation').alt = clientArray[swap_index][1];
//						document.getElementById('urlLocation').href = clientArray[swap_index][1];
//						document.getElementById('detailsLyr').innerHTML = clientArray[swap_index][2];
//						document.getElementById('detailsLyr').href = clientArray[swap_index][1];							
						setTimeout("fadeIn('logoLocation', 0, '99.99')", 1300);

						}
					else if (x.readyState == 4 && x.status == 200)
						{
/*
						preload.innerHTML = "Loading...";
						getImageSize = document.getElementsByTagName("img")[0].getAttribute("width");
*/
						}
					}
				x.open("GET", args[1], true);
				x.send(null);
				}
			break;

		case "load_news":
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			if (x)
				{
				x.onreadystatechange = function()
					{
					if (x.readyState == 0){}
					else if (x.readyState == 1){}
					else if (x.readyState == 2){}
					else if (x.readyState == 3)
						{
	 					setOpacity(0, 'newsLyr');
 // 				  alert(newsArray[news_swap_index][0]);
						document.getElementById('newsLyr').innerHTML = newsArray[news_swap_index][0];
						setTimeout("fadeIn('newsLyr', 0, '99.99')", 1300);
						}
					else if (x.readyState == 4 && x.status == 200){}
					}
				x.open("GET", args[1], true);
				x.send(null);
				}
			break;


		case "start_up":
			ajaxManager('client_array_setup');
			rotate_client();
			ajaxManager('news_array_setup');
			setTimeout("",15000); 
			rotate_news();
			break;
		}
	}

function fadeIn(id, startfade, endfade)
	{
	timer = 0;
	if (startfade < endfade)
		{
		for (i = startfade; i <= endfade; i++)
			{
			setTimeout("setOpacity(" + i + ",'" + id + "')", (timer * 20));
			timer++;
			}
		}
	}

function fadeOut(id, startfade, endfade)
	{
	timer = 0;
	if (startfade > endfade)
		{
		for (i = startfade; i <= endfade; i--)
			{
	//		document.getElementById('TEST').innerHTML = i;
			setTimeout("setOpacity(" + i + ",'" + id + "')", (timer * 20));
			timer++;
			}
		}
	}

function setOpacity(opacity, id)
	{
	var el = document.getElementById(id).style;
	el.opacity = (opacity / 100);
	el.MozOpacity = (opacity / 100);
	el.KhtmlOpacity = (opacity / 100);
	el.filter = "alpha(opacity=" + opacity + ")";
	}

function rotate_client() { 
  do {
		num++; if (num > clientArray.length) {num = 1} 
		randomnumber=Math.floor(Math.random()*clientArray.length);
		swap_index = randomnumber;
		last_randomnumber = randomnumber;
	} 
	while (last_randomnumber != randomnumber);

	ajaxManager('load_client', clientArray[randomnumber]);
	setTimeout("rotate_client()",10000); 
}


function rotate_news() { 
  do {
		news_num++; if (news_num > newsArray.length) {news_num = 1} 
		news_randomnumber=Math.floor(Math.random()*newsArray.length);
		news_swap_index = news_randomnumber;
		news_last_randomnumber = news_randomnumber;
	} 
	while (news_last_randomnumber != news_randomnumber);
	ajaxManager('load_news', newsArray[news_randomnumber]);
	setTimeout("rotate_news()",16000); 
}