var currentMenu = '';
var currentLeftHandNav = '';
var selectedMenu = '';
var menuTimeout = '';
var mediaTimeout = '';

var eventSlide = '';

var currentNewsPanel = 1;

var map = null;

var currentLocationID = 0;
var mapMarkers = [];

var staffSlides = [];
var mediaYearSlide = '';
var mediaItems;
var currentVideoID = 0;

var servicesScrubStart;
var servicesScrubEnd;
var servicesCategoryDiv;
var servicesScrubStarted = false;
var servicesScrubTimeout;

var scrollTimeout;


/*
Prevent JS error from appearing on the client browser
*/
function stopErrors() {
	return true;
}
//window.onerror = stopErrors;


/*
Trim a string from leading and trailing spaces
*/
function Trim(iString) {
  iString = iString.replace( /^\s+/g, "" );
  return iString.replace( /\s+$/g, "" );
}


/*
Pre-load image functions
*/
function preloadBaseImages() {
	var imageArray = new Array('loading.gif', 
							   'toolbar/about_btn_active.gif', 
							   'toolbar/events_btn_active.gif', 
							   'toolbar/services_btn_active.gif', 
							   'toolbar/news_btn_active.gif', 							   
							   'left_navs/left_border_active.gif', 
							   'left_navs/right_border_active.gif');
							   
    preloadImages(imageArray, '/images/');	
}


/*
Pre-load the image array
*/
function preloadImages(imageArray, dirPrefix) {
	for(i = 0; i < imageArray.length; i++) {
		var imageName = new Image();
        imageName.src = dirPrefix + imageArray[i];
	}
}


/*
Set a cookie for the specified length
*/
function setCookie(name, value, ex) {
	var prefix = window.location.hostname;
	var expDate  = new Date();
  	expDate.setMinutes(expDate.getMinutes() + ex * 60);
  	document.cookie = name +"=" + value + "; expires=" + expDate.toGMTString() + "; path=/; domain=" + prefix;
}


/*
Find an object on the page
*/
function findObj(objName) {
	var theObj = document.getElementById(objName);
	
	if (!theObj) {
		//theObj = document.all[objName];
	}
	
	return theObj;
}


/*
Find an object that is contained within an object
*/
function findContainedObj(objName, objContainer) {
	var theObj = objContainer.elements[objName];
	
	if ((!theObj) && (objContainer.all)) {
		theObj = objContainer.all[objName];
	}
	
	// If no object found, search through layers
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("div");
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
	
	// If we still haven't found the object, look for table cells
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("td");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
		
	// If we still haven't found the object, look for spans
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("span");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}	

	// If we still haven't found the object, look for tables
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("table");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
	
	return theObj;	
}


/*
Replaces text with by in string
*/
function replace(string, text, by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


/*
Find the X position of the specified object
*/
function findPosX(obj) {
	if (!obj.id) { obj = findObj(obj); }
	if (!obj) { return false; }
	
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	
	return curleft;
}


/*
Find the Y position of the specified object
*/
function findPosY(obj) {
	if (!obj.id) { obj = findObj(obj); }
	if (!obj) { return false; }
	
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	
	return curtop;
}


/*
Show/hide a layer
*/
function toggleLayer(iLayer, iState) {
	hideLayer = false;
	
	if (document.getElementById) {
        if (!iLayer.id) {
			var obj = document.getElementById(iLayer);
			obj.style.visibility = iState ? "visible" : "hidden";
        } else {
        	iLayer.style.visibility = iState ? "visible": "hidden";
        }        
		
	} else if (document.layers) {
		if (!iLayer.id) {
       		document.layers[iLayer].visibility = iState ? "show" : "hide";
		} else {
			iLayer.visibility = iState ? "show" : "hide";
		}
    
	} else if (document.all) {
		if (!iLayer.id) {
        	document.all[iLayer].style.visibility = iState ? "visible" : "hidden";
		} else {
			iLayer.style.visibility = iState ? "visible" : "hidden";
		}
    }
    
	if (iState == 1) { setTimeout('hideLayer = true;', 25); }
}


/*
Position a layer based on the coords of the mouse
*/
function moveLayerToMouse(obj, e) {
	var tempX = 0;
	var tempY = 0;
	var offset = 5;

	if (!obj.id) { obj = findObj(obj); }
	if (!obj) { return false; }

	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
    	tempX = e.pageX;
    	tempY = e.pageY;
  	}

	if (tempX < 0) { tempX = 0; }
 	if (tempY < 0) { tempY = 0; }
 	
	// Determine the max width and height that we have to work with
 	if (self.innerWidth) {
		var maxWidth = self.innerWidth;
		var maxHeight = self.innerHeight;
	
 	} else if (document.documentElement && document.documentElement.clientWidth) {
		var maxWidth = document.documentElement.clientWidth;
		var maxHeight = document.documentElement.clientHeight;
	
 	} else if (document.body) {
		var maxWidth = document.body.clientWidth;
		var maxHeight = document.body.clientHeight;		
	}

	// Adjust max vars based on scroll position
	if (document.body.scrollTop) { maxHeight = maxHeight + document.body.scrollTop; }
	if (document.body.scrollLeft) { maxWidth = maxWidth + document.body.scrollLeft; }	
	
	if (tempX + obj.offsetWidth + 30 > maxWidth) {
		obj.style.left = (tempX - obj.offsetWidth) + 'px';
	} else {
		obj.style.left = (tempX + offset) + 'px';
	}
	
	if (tempY + obj.offsetHeight + 30 > maxHeight) {
		obj.style.top = (tempY - obj.offsetHeight) + 'px';
	} else {
		obj.style.top = (tempY + offset) + 'px';
	}
}


/*
"width=480,height=350,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0"
*/
function launchWin(urlPath, winName, params) {	
	var paramArray = params.split(",");
	var windowWidth = Trim(paramArray[0].split("=")[1]);
	var windowHeight = Trim(paramArray[1].split("=")[1]);

	var windowLeft = (self.screen.width-windowWidth) / 2;
	var windowTop = (self.screen.height-windowHeight) / 2;
	
	params = params + ',top=' + windowTop + ',left=' + windowLeft;
	//alert(params);
	
	var winName = window.open(urlPath,winName,params);
	
	//winName.moveTo((self.screen.width-windowWidth) / 2, (self.screen.height-windowHeight) / 2);
	winName.focus();

	/*
	var paramArray = params.split(",");
	var windowWidth = Trim(paramArray[0].split("=")[1]);
	var windowHeight = Trim(paramArray[1].split("=")[1]);	
	
	winDialog = window.showModalDialog(urlPath, winName,"dialogHeight:" + windowHeight + "px;dialogWidth=" + windowWidth + "px;status:0;help:0;center:1");
	*/
}


/*
Open a window maximized
*/
function openWinMax(aURL, aWinName, params) {
   var wOpen;
   var sOptions;

   sOptions = params;
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open('', aWinName, sOptions);
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo(0, 0);
   wOpen.resizeTo(screen.availWidth, screen.availHeight);
   return wOpen;
}


/*
Reload the current window after a set time
*/
function reloadWindowTimeout() {
	setTimeout('window.location.reload();', 250);
}


/*
Redirect the current window after a set time
*/
function redirectWindowTimeout(iLocation) {
	setTimeout('window.location.href=\'' + iLocation + '\'', 250);
}


/*
Make sure the current menu item is in the currentMenu var (to prevent hiding)
*/
function activateToolbarMenu(iMenuItem) {
	if ((currentMenu != '') && (currentMenu != iMenuItem.id)) {
		findObj(currentMenu).src = '/images/toolbar/' + currentMenu + '_btn.gif';
	}

	currentMenu = iMenuItem.id;	
	findObj(iMenuItem.id).src = '/images/toolbar/' + iMenuItem.id + '_btn_active.gif';	
}


/*
Deactivate any active toolbar menus
*/
function deactivateToolbar() {
	document.menuTimeout = setTimeout('findObj(\'' + currentMenu + '\').src = \'/images/toolbar/' + currentMenu + '_btn.gif\';', 360);
}


/*
Bind and add events for the news panels on the landing page
*/
function initNewsPanels() {
	jQuery('.newsPanelBtn').bind('click', function() {
		var tmpIndex = jQuery(this).attr('id').replace('news_img_', '');
		
		if (jQuery('#news_panel_' + tmpIndex).is(':hidden')) {
			jQuery('.newsPanel').find('> div').hide();
			
			jQuery('#news_panel_' + currentNewsPanel).slideUp(250);
			jQuery('#news_panel_' + tmpIndex).slideDown(250, function() { 
				jQuery('#news_panel_' + tmpIndex).find('> div').show(); 
				
				if (jQuery('#news_panel_' + tmpIndex).find('> div').attr("scrollHeight") > 300) {
					jQuery('#news_panel_' + tmpIndex).css({'overflow-y': 'scroll'});
				} else {
					jQuery('#news_panel_' + tmpIndex).css({'overflow-y': 'hidden'});
				}
				
				if (tmpIndex == 1) {
					jQuery('#news_calendar_div').slideshow('force_draw');
				}
				
				if (tmpIndex == 2) {
					jQuery('#news_media').slideshow('force_draw');
				}
			});
						
			setCookie("news_panel", tmpIndex, 720);
			currentNewsPanel = tmpIndex;
		}
	});	
}


/*

*/
function initMediaNews() {
	jQuery('#news_media').slideshow({
		delay: 350,
		width: 240,
		height: 195,
		type: 'verticle'
	});
	
	jQuery('.newsMediaBtn').bind('mouseenter', function() {
		jQuery('.newsMediaBtn').addClass('newsMediaInactive');
		jQuery('#news_media').slideshow('jumpto', 'news_media_' + jQuery(this).attr('id'));
		jQuery(this).removeClass('newsMediaInactive');
	});
	
	jQuery('.newsMediaVideo').each(function() {
		var tmpIndex = jQuery(this).attr('id').replace('news_video_', '');
		
		swfobject.embedSWF(
			"/mediaplayer.swf",
			"news_video_" + tmpIndex,
			"240", 
			"180",
			"9.0.1",
			false,
			{file: "/media/" + tmpIndex + ".flv", image: "/media/" + tmpIndex + "_thumb.jpg", width: 240, height: 180},
			{allowscriptaccess: "always", allowfullscreen: "true", wmode: "transparent"},
			{bgcolor: "#FFFFFF"}
		);
	});	
}









/*
Highlight the specified left hand nav item
*/
function selectLeftNav(iNavItem) {
	if (iNavItem.className.indexOf('Current') == -1) { 
		iNavItem.className = 'leftHandNavActive';
		findObj(iNavItem.id + '_left').src = '/images/left_navs/left_border_active.gif';
		findObj(iNavItem.id + '_right').src = '/images/left_navs/right_border_active.gif';
	}
}


/*
Un-Highlight the specified left hand nav item
*/
function deSelectLeftNav(iNavItem) {
	if (iNavItem.className.indexOf('Current') == -1) { 
		iNavItem.className = 'leftHandNav';
		findObj(iNavItem.id + '_left').src = '/images/left_navs/left_border.gif';
		findObj(iNavItem.id + '_right').src = '/images/left_navs/right_border.gif';
	}
}


/*
Set the current left hand nav item
*/
function setCurrentLeftNav(iNavItem) {
	if (currentLeftHandNav.id) {
		currentLeftHandNav.className = 'leftHandNav';
		findObj(currentLeftHandNav.id + '_left').src = '/images/left_navs/left_border.gif';
		findObj(currentLeftHandNav.id + '_right').src = '/images/left_navs/right_border.gif';
	}
	
	currentLeftHandNav = iNavItem;
	
	if (iNavItem.className.indexOf('Current') == -1) { 
		iNavItem.className = 'leftHandNavCurrent';
		findObj(iNavItem.id + '_left').src = '/images/left_navs/left_border_active.gif';
		findObj(iNavItem.id + '_right').src = '/images/left_navs/right_border_active.gif';
	}
}


/*
Build the top tier slide arrays for the staff page
*/
function initTopTierSlides(iCount) {
	var fxOps = {duration: 1000, transition: Fx.Transitions.Back.easeOut, wait: false};
	
	if (navigator.userAgent.indexOf("Firefox") > -1) {
		fxOps = {duration: 0, wait: false};
	}

	staffSlides[0] = new noobSlide({
		mode: 'vertical',
		box: $('tier_1'),
		items: $$('#tier_1 div'),
		size: 365,
		button_event: 'click',		
		fxOptions: fxOps,
		onWalk: function(currentItem, currentHandle) {
			for (i = 1; i <= iCount; i ++) {
				staffSlides[i].walk(0, false, true);
			}
			
			$$(this.handles).removeClass('active');
			$$(currentHandle).addClass('active');
		}
	});
	
	staffSlides[0].walk(1, false, true);
}


/*
Build the slide arrays for the staff page
*/
function initStaffSlides(iCount) {
	var fxOps = {duration: 1000, wait: false};
	
	/*
	if (navigator.userAgent.indexOf("Firefox") > -1) {
		fxOps = {duration: 0, wait: false};
	}
	*/
	
	for (i = 1; i <= iCount; i ++) {
		staffSlides[i] = new noobSlide({
			box: $('initiative_staff_' + i),
			items: $$('#initiative_staff_' + i + ' div'),
			size: 595,
			fxOptions: fxOps,			
			addButtons: {previous: $('back_btn_' + i), next: $('next_btn_' + i) },
			onWalk: function(currentItem, currentHandle) {				
				if (currentItem.id.indexOf('landing_slide_') > -1) {
					var tmpID = currentItem.id.replace('landing_slide_', '');
					if (findObj('staff_buttons_' + tmpID)) { setTimeout('toggleLayer(\'staff_buttons_' + tmpID + '\', 0);', 250); }
				
				} else {
					var tmpID = currentItem.id.replace('staff_details_', '');
					if (findObj('staff_buttons_' + tmpID)) { setTimeout('toggleLayer(\'staff_buttons_' + tmpID + '\', 1);', 250); }
				}
				
				$$(this.handles).removeClass('active');
				$$(currentHandle).addClass('active');
			}
		});

		staffSlides[i].walk(0, false, true);
	}	
}


/*
Perform the staff search
*/
function searchStaff() {
	findObj('staffUpdateMsg').innerHTML = 'Searching Staff...';
	performAjax(Array(findObj('search_name').value), '/staff.php?action=SEARCH_STAFF', '', '');
}


/*
Pan to the staff profile of the specified column index
*/
function showStaffProfile(iIndex, iColumnIndex) {
	staffSlides[iIndex].walk(iColumnIndex, false, false);
}


/*
Init the multimedia slides
*/
function initMediaRoomSlides() {
	if (navigator.userAgent.indexOf("Firefox") == -1) {
		//initMediaPlayer(2, 360, 240);
	}

	var multiMediaSlide = new noobSlide({
		box: $('mediaRoomDiv'),
		items: mediaItems,
		size: 370,
		handles: $$('#media_right div'),
		handle_event: 'mouseenter',
		button_event: 'click',
		fxOptions: {
			duration: 1000,
			transition: Fx.Transitions.Back.easeOut,
			wait: false
		},
		onWalk: function(currentItem, currentHandle){
			this.handles.set('opacity', 0.3);
			currentHandle.set('opacity', 1);

			if (navigator.userAgent.indexOf("Firefox") != -1) {
				clearTimeout(mediaTimeout);
				if (currentVideoID > 0) {
					findObj('video_' + currentVideoID).innerHTML = '<img src="/media/' + currentVideoID + '_full.jpg">';
					currentVideoID = 0;
				}
				
				if (currentItem.video == 't') {
					mediaTimeout = setTimeout('initMediaPlayer(' + currentItem.video_id + ', 360, 240);', 750);
					currentVideoID = currentItem.video_id;					
				}
				
			} else {
				if (currentItem.video == 't') {
					initMediaPlayer(currentItem.video_id, 360, 240);
				}
			}

			//findObj('more_info').innerHTML = '<a href="javascript:void(0);" onclick="' + currentItem.link + '" target="_blank"><b>' + currentItem.title + '</b></a><br>' + currentItem.description;
			findObj('mm_title').innerHTML = '<a href="javascript:void(0);" onclick="' + currentItem.link + '" target="_blank"><b>' + currentItem.title + '</b></a>';
			findObj('more_info').innerHTML = currentItem.description;
		}
	});
}


/*
Init the media player
*/
function initMediaPlayer(iVideoID, iWidth, iHeight) {
	currentVideoID = iVideoID;
	var s1 = new SWFObject("/mediaplayer.swf", "mediaplayer", iWidth, iHeight, "7");
	s1.addParam("allowfullscreen", "true");
	
	s1.addVariable("width", iWidth);
	s1.addVariable("height", iHeight);

	s1.addVariable("file", "/media/" + iVideoID + ".flv");
	s1.addVariable("image", "/media/" + iVideoID + ".jpg");
	
	s1.write("video_" + iVideoID);
}


/*
Popup the services contact info
*/
function popupServicesContact(iServiceID, e) {
	moveLayerToMouse('serviceContactDiv', e);
	
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
    	tempX = e.pageX;
    	tempY = e.pageY;
  	}

  	if (findPosY('serviceContactDiv') < tempY) {
  		findObj('serviceContactDiv').style.top = tempY;
  	}
  	
	findObj('contact_img').src = "/images/blank.gif";  	
  	
	findObj('serviceContactDiv').style.left = (findPosX('serviceContactDiv') - 285) + 'px';
	findObj('serviceContactDiv').style.top = (findPosY('serviceContactDiv') - 238) + 'px';	
	
	findObj('contact_info').innerHTML = '<br><br><br><br><center><span class="btext14">Loading...</span></center>';
	toggleLayer('serviceContactDiv', 1);
	
	setTimeout('performAjax(Array(\'' + iServiceID + '\'), \'/index.php?action=GET_SERVICES_CONTACT\', \'\', \'\');', 500);
}


/*
Show the services contact information
*/
function showServicesContact(iServiceName, iName, iEmail, iPhone, iImage) {
	if (iImage) {
		findObj('contact_img').src = iImage;
		findObj('contact_img').style.width = '95px';
	}
	
	//findObj('contact_info').innerHTML = '<span class=\"btext14\">' + iServiceName + '</span><br><br>';	
	findObj('contact_info').innerHTML = '<br><span class=\"btext14\">Contact Information:</span><br><br>';
	findObj('contact_info').innerHTML = findObj('contact_info').innerHTML + '<span class=\"btext13\">' + iName + '</span><br>';	
	if (iEmail) { findObj('contact_info').innerHTML = findObj('contact_info').innerHTML + '<a href=\"mailto:' + iEmail + '\">' + iEmail + '</a><br>'; }
	if (iPhone) { findObj('contact_info').innerHTML = findObj('contact_info').innerHTML + iPhone; }
	
	toggleLayer('serviceContactDiv', 1);
}


/*
Init the services panel
*/
function initServicesPage() {
	var tmpLeft = 0;
	
	var tmpObj = findObj('servicesMask').getElementsByTagName("div");
	for (var i = 0; i < tmpObj.length; i++) {
		var tmpX = tmpObj[i].offsetWidth;
		
		if (tmpLeft > 0) {
			tmpObj[i].style.left = tmpLeft + 'px';
		}
		
		tmpLeft = tmpLeft + tmpObj[i].offsetWidth;
		tmpLeft = tmpLeft + 20;
	}
	
	parent.window.dd.elements['servicesScrubDiv'].moveBy(14, 201);
	parent.window.dd.elements['servicesScrubDiv'].maxoffl = -14;
	parent.window.dd.elements['servicesScrubDiv'].show();
}


/*
The toolbar itself was clicked
*/
function serviceToolbarClick(e) {
	$("#servicesCaption").fadeOut(5);
	$("#" + servicesCategoryDiv).fadeOut(5);
	
	dd.obj = dd.elements['servicesScrubDiv'];
	
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;

	} else {
    	tempX = e.pageX;
  	}

  	tempX = tempX - (dd.elements['servicesScrubDiv'].w / 2);
  	if (tempX < dd.elements['servicesScrubDiv'].defx + 14) {
  		tempX = dd.elements['servicesScrubDiv'].defx + 14;
  	}
  	
  	if (tempX > (dd.elements['servicesScrubDiv'].maxoffr + dd.elements['servicesScrubDiv'].defx)) {
  		tempX = (dd.elements['servicesScrubDiv'].maxoffr + dd.elements['servicesScrubDiv'].defx);
  	}

	if (!servicesScrubStart) {
		servicesScrubStart = dd.obj.x;
		servicesScrubEnd = servicesScrubStart + 611;
	}
  	
  	dd.elements['servicesScrubDiv'].moveTo(tempX, dd.elements['servicesScrubDiv'].y);
	my_DropFunc();
}


/*
Started draging the services scrub
*/
function my_PickFunc() {
	if (!servicesScrubStart) {
		servicesScrubStart = dd.obj.x;
		servicesScrubEnd = servicesScrubStart + 611;
	}
	
	servicesScrubStarted = true;
	//$("#servicesCaption").fadeOut("fast");
	//$("#" + servicesCategoryDiv).fadeOut("fast");
}


/*
Scroll the iframe accordingly
*/
function my_DragFunc() {
	if (servicesScrubStarted = true) {
		$("#servicesCaption").fadeOut("fast");
		$("#" + servicesCategoryDiv).fadeOut("fast");
		servicesScrubStarted = false;
	}
	
	var currentX = (dd.obj.x - servicesScrubStart);
	var tmpPercentage = (currentX / (servicesScrubEnd - servicesScrubStart));
	
	var scrollWidth = parent.frames['services_scroller'].document.body.scrollWidth;
	var clientWidth = parent.frames['services_scroller'].document.body.clientWidth;
	var scrollMod = 0;
	
	var moveTo = ((scrollWidth - clientWidth - scrollMod) * tmpPercentage);
	parent.frames['services_scroller'].window.scrollTo(moveTo, 0);
}


/*
Services scrub has been dropped
*/
function my_DropFunc() {
	var currentX = (dd.obj.x - servicesScrubStart);
	var tmpPercentage = (currentX / (servicesScrubEnd - servicesScrubStart));
	
	var scrollWidth = parent.frames['services_scroller'].document.body.scrollWidth;
	var clientWidth = parent.frames['services_scroller'].document.body.clientWidth;
	var scrollMod = 0;
		
	var moveTo = ((scrollWidth - clientWidth - scrollMod) * tmpPercentage);
	parent.frames['services_scroller'].window.scrollTo(moveTo, 0);
	
	$("div.servicesIndDiv").show();
	
	showServiceContent();
}


/*

*/
function showServiceContent() {
	var tmpX = dd.elements['servicesScrubDiv'].x - (dd.elements['servicesScrubDiv'].defx + 14);
	//alert(tmpX);
	
	// 1: 0 - 66
	// 2: 67 - 140
	// 3: 141 - 210
	// 4: 211 - 308
	// 5: 309 - 416
	// 6: 417 - 502
	// 7: 503 - 584
	// 8: 585 - 611

	if ((tmpX >= 0) && (tmpX <= 66)) {
		findObj('servicesCaption').innerHTML = 'One of CCAT\'s core goals is help companies to improve efficiencies in their day-to-day operations, and as part of that goal CCAT offers clients a range of services aimed at assisting companies in that mission.';		
		var categoryID = 3;
	
	} else if ((tmpX >= 67) && (tmpX <= 140)) {
		findObj('servicesCaption').innerHTML = 'CCAT helps to build the workforce of the future by helping to improve training and education for students, teachers and working professionals.';		
		var categoryID = 8;
	
	} else if ((tmpX >= 141) && (tmpX <= 210)) {
		findObj('servicesCaption').innerHTML = 'CCAT offers a range of services aimed at helping companies find grants and matching funds to improve efficiencies in their operations, as well as assist with development and commercialization of new technology.';
		var categoryID = 4;
	
	} else if ((tmpX >= 211) && (tmpX <= 308)) {
		findObj('servicesCaption').innerHTML = 'CCAT\'s facilities offer clients access to an advanced imaging theater, high-end conference and collaborative space, and in-house business incubator and a laser laboratory.';
		var categoryID = 5;
	
	} else if ((tmpX >= 309) && (tmpX <= 416)) {
		findObj('servicesCaption').innerHTML = 'CCAT offers a range of services geared toward helping improve energy efficiency for the state\'s businesses; a significant portion of these efforts is targeted at advancing the use of energy technology such as fuel cells and biodiesel.';		
		var categoryID = 1;
		
	} else if ((tmpX >= 417) && (tmpX <= 502)) {
		findObj('servicesCaption').innerHTML = 'CCAT can help manufacturing companies use new and emerging technology to improve their operations.';		
		var categoryID = 6;
		
	} else if ((tmpX >= 503) && (tmpX <= 584)) {
		findObj('servicesCaption').innerHTML = 'CCAT is engaged in a number of activities aimed at evaluating, prototyping and field-testing new technology for manufacturers, high tech businesses and other organizations.';		
		var categoryID = 7;
		
	} else if ((tmpX >= 585) && (tmpX <= 611)) {
		findObj('servicesCaption').innerHTML = 'CCAT can help companies to improve top line growth through marketing assistance, partnership building and evaluating potential markets for technology innovation.';			
		var categoryID = 2;
	}
	
	$("#servicesCaption").fadeIn("fast");
	$("#service_category_" + categoryID).fadeIn("fast");
	
	servicesCategoryDiv = "service_category_" + categoryID;	
}


/*

*/
function scrollServices(iDirection) {
	var addModified = 10;
	var timeoutLength = 40;
	
	if (iDirection == 'right') {
		var tempX = dd.elements['servicesScrubDiv'].x + addModified;
		
		if (tempX > (dd.elements['servicesScrubDiv'].maxoffr + dd.elements['servicesScrubDiv'].defx)) {
			tempX = (dd.elements['servicesScrubDiv'].maxoffr + dd.elements['servicesScrubDiv'].defx);
		
			clearTimeout(servicesScrubTimeout);
			
		} else {
			servicesScrubTimeout = setTimeout('scrollServices(\'' + iDirection + '\');', timeoutLength);
		}
		
	} else {
		var tempX = dd.elements['servicesScrubDiv'].x - addModified;
		
		if (tempX < (dd.elements['servicesScrubDiv'].defx + 14)) {
			tempX = dd.elements['servicesScrubDiv'].defx + 14;
		
			clearTimeout(servicesScrubTimeout);
			
		} else {
			servicesScrubTimeout = setTimeout('scrollServices(\'' + iDirection + '\');', timeoutLength);
		}
	}
	
	dd.elements['servicesScrubDiv'].moveTo(tempX, dd.elements['servicesScrubDiv'].y);
	dd.obj = dd.elements['servicesScrubDiv'];
	my_DragFunc();
}


/*
Show just the specified service
*/
function showServiceID(iServiceID) {
	$("div.servicesIndDiv").show();
	$("div.servicesIndDiv").not('#service_div_' + iServiceID).hide();
}


/*
User changed a newsletter preference
*/
function newsletterPreference() {
	var tmpValue = findObj('preferences').value;
	
	if (tmpValue == 'Yes') {
		findObj('preferences_label').innerHTML = 'I Want Occasional News And Updates.';
	} else {
		findObj('preferences_label').innerHTML = 'I Don\'t Want Occasional News And Updates.';
	}
}


/*
The user has successfully signed up for the newsletter
*/
function newsletterDone() {
	findObj('updateMsg').innerHTML = '<center><b>Thank you for submitting your preferences</b></center>';
	//setTimeout('toggleLayer(\'newsletterPopUp\', 0);', 4000);
	setTimeout('window.location.href=\'/\'', 4000);
}


/*
Scroll the specified div up
*/
function scrollDivUp(iDiv) {
	if (!iDiv.id) { iDiv = findObj(iDiv); }
	if (!iDiv) { clearTimeout(scrollTimeout); return false; }

	if (iDiv.scrollTop == 0) { clearTimeout(scrollTimeout); return false; }

	scrollTimeout = setTimeout('performDivUp(\'' + iDiv.id + '\');', 25);
}


/*
Scroll the specified div down
*/
function scrollDivDown(iDiv) {
	if (!iDiv.id) { iDiv = findObj(iDiv); }
	if (!iDiv) { clearTimeout(scrollTimeout); return false; }

	if ((iDiv.scrollTop + iDiv.offsetHeight) == iDiv.scrollHeight) { clearTimeout(scrollTimeout); return false; }

	scrollTimeout = setTimeout('performDivDown(\'' + iDiv.id + '\');', 25);
}


function performDivUp(iDiv) {
	if (!iDiv.id) { iDiv = findObj(iDiv); }
	if (!iDiv) { clearTimeout(scrollTimeout); return false; }

	if (iDiv.scrollTop == 0) { clearTimeout(scrollTimeout); return false; }
	
	iDiv.scrollTop = iDiv.scrollTop - 10;
	scrollTimeout = setTimeout('performDivUp(\'' + iDiv.id + '\');', 25);
}

function performDivDown(iDiv) {
	if (!iDiv.id) { iDiv = findObj(iDiv); }
	if (!iDiv) { clearTimeout(scrollTimeout); return false; }

	if ((iDiv.scrollTop + iDiv.offsetHeight) == iDiv.scrollHeight) { clearTimeout(scrollTimeout); return false; }
	
	iDiv.scrollTop = iDiv.scrollTop + 10;
	scrollTimeout = setTimeout('performDivDown(\'' + iDiv.id + '\');', 25);
}


/*
Login the user
*/
function loginUser() {
	/*
	var tmpFrm = findObj('login_frm');
	
	doFormSubmit('Logging In...', tmpFrm);
	clearFormErrors(tmpFrm);
	
	performAjax(tmpFrm, '/index.php?action=XML_LOGIN', '', '');
	*/
	
	doFormSubmit('Logging In...', findObj('login_frm'));
	submitAJAX('/index.php?action=LOGIN_USER', jQuery('#login_frm').serialize());
}
