function triggerObject(ev, inObj){
	dBoxHighlight(inObj);
	var popup = function(e){
		dBoxHighlight(inObj);
		showPopup(AJS.getMousePos(e), inObj);
	}
	var pophide = function(e){
		dBoxNormal(inObj);
		hidePopup();
	}
	AJS.AEV(inObj, "mouseover", popup);
	AJS.AEV(inObj, "mouseout", pophide);
	showPopup(AJS.getMousePos(ev), inObj);
}

function showPopup(inLoc, inObj){
	if(inObj.description){
		if(inObj.description == "")
			return;
		showPop = true;
	    setPopupContent(inObj.description);
		pOffset = 25;
		_window = AJS.getWindowSize();
		if(inLoc.x > _window.w*3/5){
			setPopupX(inLoc.x-pOffset-getPopupWidth());
		}else{
			setPopupX(inLoc.x+pOffset);
		}
		if(inLoc.y > (AJS.getScrollTop()+_window.h/2))
			setPopupY(inLoc.y-pOffset-getPopupHeight());	
		else
			setPopupY(inLoc.y+pOffset);			
		if(getPopupHeight() > 350){
			setPopupX(inLoc.x-pOffset-getPopupWidth());
			setPopupY(AJS.getScrollTop()+2);	
		}
	}else{
		showPop = false;
		AJS.BASE_URL = "http://www.csu.edu.au/staff/yourcsu";
		if (inObj.id)
			_file = inObj.id;
		else
			_file = inObj.innerHTML;
		var d = AJS.getRequest("/descriptions/"+_file+".htm", false, "GET")
		d.addCallback( function(res_txt, req) { 
			showPop = true;
			inObj.description = res_txt;
			setPopupContent(inObj.description);
			pOffset = 25;
		_window = AJS.getWindowSize();
		if(inLoc.x > _window.w*3/5){
			setPopupX(inLoc.x-pOffset-getPopupWidth());
		}else{
			setPopupX(inLoc.x+pOffset);
		}
		if(inLoc.y > (AJS.getScrollTop()+_window.h/2))
			setPopupY(inLoc.y-pOffset-getPopupHeight());	
		else
			setPopupY(inLoc.y+pOffset);			
		if(getPopupHeight() > 350){
			setPopupX(inLoc.x-pOffset-getPopupWidth());
			setPopupY(AJS.getScrollTop()+2);	
		}
		} )	
		d.addErrback(function(res_txt, req) { inObj.description = ""; })
		d.sendReq()
	}
}

function hidePopup(){
	if (!showPop)
		return false;
	
	setPopupX(-500);
	setPopupY(-500);
	setPopupContent('');
}

function setPopupContent(inC){
	AJS.$("popwindow").innerHTML = inC;
}

function setPopupX(inX, right){
	AJS.$("popwindow").style.left = inX + "px";
}

function setPopupY(inY, bottom){
	AJS.$("popwindow").style.top  = inY + "px";
}

function getPopupX(){
	return AJS.$("popwindow").style.left;
}

function getPopupY(){
	return AJS.$("popwindow").style.top;
}

function getPopupHeight(){
	return AJS.$("popwindow").offsetHeight;
}

function getPopupWidth(){
	return AJS.$("popwindow").offsetWidth;
}

function keyNav(e){ // in place for arrow key navigation
//	return;
	if (e.keyCode && (e.keyCode == 37 || e.keyCode == 39)){
//		alert(pageNavList);
		if (!pageNavList)
			return;
		if(e.keyCode == 37)
			navigateBack();
		if(e.keyCode == 39)
			navigateForward();
	}
}

function setUpKeyNavigation(){
	AJS.AEV(document, "keydown", keyNav);
}

function navigateBack(){
//	alert("back: "+(locationNavNumber-1));
	_targ = parseInt(locationNavNumber)-1;
	if (_targ < 0)
		return;
	document.location = pageNavList[_targ];
}

function navigateForward(){
	var _targ = parseInt(locationNavNumber)+1;
	if (_targ>=pageNavList.length)
		return;
	document.location = pageNavList[_targ];
}

function getPageName(){
	var dn = document.URL;
	var loc= 0;
	while (dn.indexOf("/", loc) != -1){
		loc = dn.indexOf("/", loc)+1;
	}
	var _x = dn.substr(loc);
	var loc = _x.indexOf("#");
	if (loc != -1){
		_x = _x.substr(0, loc);
	}
	return _x;
}

function getPageLocation(){
	var nm = getPageName();
	if (nm == '')
		return 0;
	for(x in pageNavList){
		if(pageNavList[x] == nm)
			return x;
	}
}

var pageNavList = ['index.html','why.html','who.html','who_executive.html','who_committee.html','who_units.html','who_committees.html','who_stakeholders.html','how.html','where.html','when.html','what.html','disciplines.html','systems.html'];
var locationNavNumber = getPageLocation();
setUpKeyNavigation();