// JavaScript Document


//var i;
//var trailNames = new Array();
//for(i = 0; i < trailsList.length; i++){
//		trailNames[i] = trailsList[i].name;
//	}
//	var autosuggest = new AutoSuggest(document.getElementById("collegeNames"),trailNames, -1, -22);
//
//

function CustomGetTileUrl(a,b) {
	if (b==11 && a.x>=595 && a.x<=610 && a.y>=761 && a.y<= 778) {
		return "tiles/" + college + "/"+(a.x)+"_"+(a.y)+"_"+b+".gif";
	} else if (b==10 && a.x>=297 && a.x<=305 && a.y>=380 && a.y<= 389) {
		return "tiles/" + college + "/"+(a.x)+"_"+(a.y)+"_"+b+".gif";
	} else if (b==9 && a.x>=148 && a.x<=152 && a.y>=190 && a.y<= 195) {
		return "tiles/" + college + "/" +(a.x)+"_"+(a.y)+"_"+b+".gif";
	}else{
		return "images/blacktile.gif";
		//return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(a,b);
	}
}

function virtualTourSelected(obj){
	var value = obj.value;
	//if(window.XMLHttpRequest) {
  //  	window.location.href="movingMap1.php?trailName="+value;	
    // branch for IE/Windows ActiveX version
   // } else if(window.ActiveXObject) {
		var params = value.split(":");
		var trailName = params[0];
		var trailPos = params[1];
		var orientation = FRONT;
		if(params.length == 3){
			orientation = params[2];
		}
		moveToLocation(trailName, trailPos, orientation, INCREMENT, STRAIGHT);
	//}
}

function changeTrailListener(trailName, trailPos){
	//var obj = document.getElementById("trail");
	//
	//if(obj.value.substring(0, trailName.length) == trailName){
	//	return;
	//}
	//
	//for(i = 0; i < obj.options.length; i++){
	//	var optionTrailName = obj.options[i].value.substring(0, obj.options[i].value.indexOf(':'));
	//	if(optionTrailName == trailName){		
	//		obj.selectedIndex = i;
	//		break;
	//	}
	//}
}


	

function editDescription(){
	var url = 'editDescription.php?';
	url = url + 'trailId=' + trailState.route.trailId;
	url = url + '&direction=' + trailState.direction;
	url = url + '&orientation=' + trailState.orientation;
	url = url + '&point=' + trailState.currentPoint;
	url = url + '&sequence=' + trailState.route.getTrailPoint(trailState.currentPoint).sequence;
	window.open(url, "_blank", "width=910,height=600,resizable=yes");
}

function addReview(){
	var url = 'addReview.php?';
	url = url + 'trailId=' + trailState.route.trailId;
	url = url + '&direction=' + trailState.direction;
	url = url + '&orientation=' + trailState.orientation;
	url = url + '&point=' + trailState.currentPoint;
	url = url + '&sequence=' + trailState.route.getTrailPoint(trailState.currentPoint).sequence;
	window.open(url, "_blank", "width=910,height=600,resizable=yes");
} 


function generalUpdateListener(){
	
	if(urlFixer == null){
		
		urlFixer = getAjaxUrlFixer();
		urlFixer.linkIds[0] = "frontNavTop_href";
		urlFixer.linkIds[1] = "frontNavLeft_href";
		urlFixer.linkIds[2] = "frontNavRight_href";
		urlFixer.linkIds[3] = "frontNavBottom_href";
		urlFixer.linkIds[4] = "sideNavBack_href";
		urlFixer.fixLinks();
		urlFixer.startTimer();
	}else{
		urlFixer.fixLinks();
	}
}



function toggleSound(linkObj){
	muteAvatar = !muteAvatar;
	if(muteAvatar){
		document.getElementById("avatarSoundLink").innerHTML = "<img alt=\"Unmute\" src=\"images/unmutebutton.gif\" onMouseOver=\"this.src='images/unmutebutton-h.gif'\" onMouseOut=\"this.src='images/unmutebutton.gif'\">";
		stopSpeech();
	}else{
		document.getElementById("avatarSoundLink").innerHTML = "<img alt=\"Mute\" src=\"images/mutebutton.gif\" onMouseOver=\"this.src='images/mutebutton-h.gif'\" onMouseOut=\"this.src='images/mutebutton.gif'\">";
	}
}

function menuEventListener(opened){
	if(document.getElementById("avatarPanel") && opened){
		document.getElementById("avatarPanel").style.visibility = "hidden";
	}
	if(document.getElementById("avatarPanel") && !opened){
		document.getElementById("avatarPanel").style.visibility = "visible";
	}
}

function registerVisitorsClick(link, facebook){
	loadHtmlDoc("functions.php?method=registerVisitorsClick&college=" + college + "&link=" + link + "&facebook=" + facebook);
	return true;
}

function registerUsersClick(userkey, sessionid, action){
	loadHtmlDoc("functions.php?method=registerUsersClick&userkey=" + userkey + "&sessionid=" + sessionid + "&action=" + action);
	return true;
}