// Arrays for long text variables, work-around for IE 2083 character href limit
var longTextData = [];

//	Create icons
var iconCalc;
var iconOffset;

//This function returns a new left value for icons.  
//It determines wether or not they lie on the current map by comparing the scaled results to mapextent
//If they fall on the map, it returns the value of the icon left in pixels
//If they fall of the map, it returns -20
function recalcLeft(latlongx,latlongy) {
  if (zoomLevel == "main") {
    iconCalc = 0.21119324181626187961985216473073 * latlongx - mapOffsetX;
  } else if (zoomLevel == "west") {
    iconCalc = 0.63357972544878563885955649419219 * latlongx - mapOffsetX;
  } else if ((zoomLevel == "southeast") || (zoomLevel == "northeast")) {
    iconCalc = 0.63357972544878563885955649419219 * latlongx - mapOffsetX;
  } else if (zoomLevel == "central") {
    iconCalc = 0.63357972544878563885955649419219 * latlongx - mapOffsetX;
  } else if (zoomLevel == "downtown") {
    iconCalc = latlongx * 8 - mapOffsetX;
  } else {
    iconCalc = latlongx * 4 - mapOffsetX;
  }
  if (iconCalc > mapextentX) {  //This icon falls off the current map
	return -20;
  } else {
    return iconCalc;
  }
}

//This function returns a new top value for icons.  
//It determines wether or not they lie on the current map by comparing the scaled results to mapextent
//If they fall on the map, it returns the value of the icon top in pixels
//If they fall of the map, it returns -20
function recalcTop(latlongx,latlongy) {
  if (zoomLevel == "main") {
    iconCalc = 0.21119324181626187961985216473073 * latlongy - mapOffsetY;
  } else if (zoomLevel == "west") {
    iconCalc = 0.65824308062575210589651022864019 * latlongy - mapOffsetY;
//	alert("Y Coordinate:" + iconCalc);
  } else if (zoomLevel == "southeast"){
    iconCalc = 0.64007092198581560283687943262411 * latlongy - mapOffsetY; // was 0.65824308062575210589651022864019 
  } else if (zoomLevel == "northeast"){
    iconCalc = 0.63114754098360655737704918032787 * latlongy - mapOffsetY; // was 0.65824308062575210589651022864019 
  } else if (zoomLevel == "central") {
    iconCalc = 0.65824308062575210589651022864019 * latlongy - mapOffsetY;
  } else if (zoomLevel == "state") {
    iconCalc = latlongy - mapOffsetY;
  } else if (zoomLevel == "downtown") {
  	iconCalc = latlongy * 8 - mapOffsetY;
  } else {
    iconCalc = latlongy * 4 - mapOffsetY;
  }
  if (iconCalc > mapextentY) { //This icon falls off the current map
	return -20;
  } else {
    return iconCalc;
  }
}

// Sets global variables that are used by all functions
var current_image;
var l= "../3_images/border_l.gif";
var r= "../3_images/border_r.gif";
var b= "../3_images/border_b.gif";
var t= "../3_images/border_t.gif";
var stat1 = "window.status='Click To View Image'; return true";
var stat2 = "window.status='Click For More Information'; return true";
var stat3 = "window.status=''";
var camNum;

// V1.0 Page Reload  60000 miliseconds = 60 seconds.
function autoReload() {
	var timeID = setTimeout("parent.mapnav.maincache = 1;document.location.reload();", 300000)
}



// This function will place either <div> tags or <layer> tags for the layer control.
// Higher "ind" numbered icons will obscure lower "ind" numbered icons
function layer_control(layer_name, ind, vis) {

var vis1;

  if (layer_name == "camera") {
	vis1 = parent.mapnav.cameraStatus;
	ind = 10;
	parent.mapnav.createCam = 1;
  } else if (layer_name == "signs") {
	vis1 = parent.mapnav.signsStatus;
	ind = 11;
	parent.mapnav.createSig = 1;
  } else if (layer_name == "planned") {
	vis1 = parent.mapnav.plannedStatus;
	ind = 12;
	parent.mapnav.createPln = 1;
  } else if (layer_name == "har") {
	vis1 = parent.mapnav.harStatus;
	ind = 13;
	parent.mapnav.createHar = 1;
  } else if (layer_name == "toll") {
	vis1 = parent.mapnav.tollStatus;
	ind = 14;
	parent.mapnav.createTol = 1;
  } else if (layer_name == "service") {
	vis1 = parent.mapnav.serviceStatus;
	ind = 15;
	parent.mapnav.createSvc = 1;
  } else if (layer_name =="weather") {
	vis1 = parent.mapnav.weatherStatus;
	ind = 16;
	parent.mapnav.createWea = 1;
  } else if (layer_name == "iweather") {
	vis1 = parent.mapnav.incidentStatus;
	ind = 17;
	parent.mapnav.createWea = 1;
  } else if (layer_name == "construction") {
	vis1 = parent.mapnav.constructionStatus;
	ind = 18;
	parent.mapnav.createCon = 1;
  } else if (layer_name == "incidents") {
	vis1 = parent.mapnav.incidentStatus;
	ind = 19;
	parent.mapnav.createInc = 1;
  } else if (layer_name == "planx") {
	vis1 = parent.mapnav.planxStatus;
	ind = 20;
	parent.mapnav.createPlx = 1;
  } else if (layer_name == "audios") {
	vis1 = 'visible';
	ind = 21;
  } else if (layer_name == "rwcs") {
	vis1 = 'visible';
	ind = 22;
  } else if (layer_name == "apas") {
	vis1 = 'visible';
	ind = 23;
  }
  
  // Write to the document
  if (parent.mapnav.browserVersion == "nav") { // Do nothing
  } else {
    document.open();
    document.write('<div id="' + layer_name + '" style="position:absolute;  visibility: ' + vis1 + ';  z-index:' + ind + '; top: 0px; left: 0px">');
    document.close();
  }
}

// This function will place either </div> tags or </layer> tags to close the layer control.
function layer_control2() {

  if (parent.mapnav.browserVersion == "nav") {
  } else {
    document.open();
    document.write('</div>');
    document.close();
  }
}

// This function displays the camera icons in either <div> tags or <layer> tags
// depending on which version of the parent.mapnav.browserVersion is being used.
function camera_icon(left1, top1, icon1, img5, mouse1) {
var left2 = recalcLeft(left1, top1);
var top2 = recalcTop(left1, top1);

if (parent.mapnav.browserVersion == "nav") {
  var vis1 = parent.mapnav.cameraStatus;
  var thisCam = parent.mapnav.createCam;
  document.open();
  document.write('<layer id="cam' + thisCam + '" visibility="' + vis1 + '" width="21px" height="18px" z-index="5" top="' + top2 + 'px" left="' + left2 + 'px">');
  document.write('<a onMouseOver="' + stat1 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();image1(\''+ img5 + '\');">');
  document.write('<img alt="' + mouse1 + '"  border="0" src="images/sm_cam' + icon1 + '.gif" width="21" height="18"></a></layer>');
  parent.mapnav.createCam = parent.mapnav.createCam + 1;
  document.close();

  } else {
  
  document.open();
  document.write('<div style="position:absolute; width:21px; height:18px; z-index:0; top: ' + top2 + 'px; left: ' + left2 + 'px">');
  document.write('<a ');
  document.write(' onMouseOver="' + stat1 + '"'); 
  document.write(' onMouseOut="' + stat3 + '"'); 
//  if (parent.mediaStatusFrm.mediaStatus == "off") {
//    document.write(' href="javascript:parent.blank.focus();image1(');
//  } else {
//    document.write(' href="javascript:parent.blank.focus();parent.basefrm.newImage(');
//  }
//  document.write("'");
//  document.write(img5);
//  document.write("'");
	document.write(' href="#" onClick="image1(' + img5 + ')"');
  document.write(');">');
  
  //Sizes used to be 15x13
  document.write('<img alt="' + mouse1 + '"  border="0" src="images/sm_cam' + icon1 + '.gif" width="21" height="18">');
  document.write('</a></div>');
  document.close();
  }

}
// This function identifies weather and PlanX icons, as they both display text and an image.
function device_icon1(left1, top1, image1, icon2, title1, text1) {

	if ((icon2 == "wea_rain") || (icon2 == "wea_rain_c") || (icon2 == "wea_snow") || (icon2 == "wea_snow_c")) {
	  weather_icon(left1, top1, icon2, title1, text1, image1);
	} 
	else if (icon2 == "planx"){
	  weather_icon(left1, top1, icon2, title1, text1, image1);
	} 
}


// This function displays the device icons in either <div> tags or <layer> tags
// depending on which version of the parent.mapnav.browserVersion is being used.
function device_icon(left1, top1, icon2, title1, text1) {
	longTextData.push(text1);
	//if ((icon2 == "wea_rain") || (icon2 == "wea_rain_c") || (icon2 == "wea_snow") || (icon2 == "wea_snow_c")) {
	if ((icon2 == "wea_rain") || (icon2 == "wea_snow")) {
	  weather_icon(left1, top1, icon2, title1, text1);
	} else if ((icon2 == "wea_rain_g") || (icon2 == "wea_snow_g")) {
	} else {

		var left2 = recalcLeft(left1, top1);
		var top2 = recalcTop(left1, top1);
		var devHeight = 13;
		var devWidth = 15;
		var devNmbr = '';
		if (icon2 == "wea_rain_c") {
			devHeight = 18;
			devWidth = 21;
		}	else if (icon2 == "rwc" || icon2 == "rwc_c") {
			devHeight = 18;
			devWidth = 21;
		}	else if (icon2 == "audio") {
			devHeight = 12;
			devWidth = 18;
			devNmbr = '2';
			//alert(text1);
		}	else if (icon2 == "apa") {
			devHeight = 45;
			devWidth = 35;
		}

	
	  if (parent.mapnav.browserVersion == "nav") {
			var vis1;
			var thisDev;
			var thisName;
			if (icon2 == "construction") {
			 vis1 = parent.mapnav.constructionStatus;
			 thisDev = parent.mapnav.createCon;
			 thisName = "con";	
			 parent.mapnav.createCon = parent.mapnav.createCon + 1;
			} else if (icon2 == "incident") {
			 vis1 = parent.mapnav.incidentStatus;
			 thisDev = parent.mapnav.createInc;
			 thisName = "inc";	
			 parent.mapnav.createInc = parent.mapnav.createInc + 1;
			} else if (icon2 == "planned") {
			 vis1 = parent.mapnav.plannedStatus;
			 thisDev = parent.mapnav.createPln;
			 thisName = "pln";	
			 parent.mapnav.createPln = parent.mapnav.createPln + 1;
			} else if (icon2 == "har") {
			 vis1 = parent.mapnav.harStatus;
			 thisDev = parent.mapnav.createHar;
			 thisName = "har";	
			 parent.mapnav.createHar = parent.mapnav.createHar + 1;
			} else if (icon2 == "planx") {
			 vis1 = parent.mapnav.planxStatus;
			 thisDev = parent.mapnav.createPlx;
			 thisName = "plx";	
			 parent.mapnav.createPlx = parent.mapnav.createPlx + 1;
			} else if (icon2 == "service") {
			 vis1 = parent.mapnav.serviceStatus;
			 thisDev = parent.mapnav.createSvc;
			 thisName = "svc";	
			 parent.mapnav.createSvc = parent.mapnav.createSvc + 1;
			} else if (icon2 == "toll") {
			 vis1 = parent.mapnav.tollStatus;
			 thisDev = parent.mapnav.createTol;
			 thisName = "tol";	
			 parent.mapnav.createTol = parent.mapnav.createTol + 1;
			} else if (icon2 == "wea_rain_c") {
			 vis1 = parent.mapnav.weatherStatus;
			 thisDev = parent.mapnav.createWea;
			 thisName = "wea";	
			 parent.mapnav.createWea = parent.mapnav.createWea + 1;
			 //alert('wea_rain_c resized');
			 devHeight = 18;
			 devWidth = 21;
			} else {
			 vis1 = parent.mapnav.signsStatus;
			 thisDev = parent.mapnav.createSig;
			 thisName = "sig";	
			 parent.mapnav.createSig = parent.mapnav.createSig + 1;
			}
//			if (icon2 == "wea_rain_c") {
//			}else{
//				alert('wea_rain_c NOT resized');
//			}
			
			document.open();
			document.write('<layer id="' + thisName + thisDev + '" visibility="' + vis1 + '" width="' + devWidth + 'px" height="' + devHeight + 'px" z-index="5" top="' + top2 + 'px" left="' + left2 + 'px">');
			//document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device(\'' + title1 + '\',\'' + text1 + '\');">');
			document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device(\'' + title1 + '\',longTextData[' + (longTextData.length-1) + ']);">');
			document.write('<img alt="' + title1 + '" border="0" src="images/sm_' + icon2 + '.gif" width="' + devWidth + '" height="' + devHeight + '"></a></layer>');
			document.close();
	  } else {
			document.open();
			document.write('<div style="position:absolute; width:' + devWidth + 'px; height:' + devHeight + 'px; z-index:0; top: ' + top2 + 'px; left: ' + left2 + 'px">');
			//document.write('<a onMouseOver="'+stat2+'" onMouseOut="' +stat3+'" href="javascript:parent.blank.focus();device' + devNmbr + '(\'' + title1 + '\',\'' + text1 + '\');">');
			document.write('<a onMouseOver="'+stat2+'" onMouseOut="' +stat3+'" href="javascript:parent.blank.focus();device' + devNmbr + '(\'' + title1 + '\',longTextData[' + (longTextData.length-1) + ']);">');
			document.write('<img alt="' + title1 + '"  border="0" src="images/sm_' + icon2 + '.gif" width="' + devWidth + '" height="' + devHeight + '">');
			document.write('</a></div>');
			document.close();
	  }
	}
}

// This function displays the weather or PlanX icons in either <div> tags or <layer> tags
// depending on which version of the parent.mapnav.browserVersion is being used.
function weather_icon(left1, top1, icon3, title1, text1, image1) {
var left2 = recalcLeft(left1, top1);
var top2 = recalcTop(left1, top1);
if (parent.mapnav.browserVersion == "nav") {
  var vis1 = parent.mapnav.weatherStatus;
  var vis2 = parent.mapnav.planxStatus;
  var thisWea = parent.mapnav.createWea;
  var thisPlx = parent.mapnav.createPlx;
  document.open();
  if (icon3 =="planx"){
  	document.write('<layer id="plx' + thisPlx + '" visibility="' + vis2 + '" width="15px" height="13px" z-index="5" top="' + top2 + 'px" left="' + left2 + 'px">');
	document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device1(\'' + title1 + '\',\'' + text1 + '\',\'px' + image1 + '.jpg\');">');
  	document.write('<img  alt="' + title1 + '" border="0" src="images/sm_' + icon3 + '.gif" width="15" height="13"></a></layer>');
	parent.mapnav.createPlx = parent.mapnav.createPlx + 1;
  }
  else{ // It's a weather icon
  	document.write('<layer id="wea' + thisWea + '" visibility="' + vis1 + '" width="16px" height="14px" z-index="5" top="' + top2 + 'px" left="' + left2 + 'px">');
	document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device1(\'' + title1 + '\',\'' + text1 + '\',\'aux' + image1 + '.jpg\');">');
  	document.write('<img  alt="' + title1 + '" border="0" src="images/sm_' + icon3 + '.gif" width="16" height="14"></a></layer>');
	parent.mapnav.createWea = parent.mapnav.createWea + 1;
  }
  document.close();

}else { // Using MSIE or any Mozilla browser
  document.open();
  if (icon3 == "planx"){
  	document.write('<div style="position:absolute; width:15px; height:13px; z-index:0; top: ' + top2 + 'px; left: ' + left2 + 'px">');
	  document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device1(\'' +title1+ '\', \'' +text1+'\', \'px' +image1+'.jpg\');">');
  } else{ // It's a weather icon
  	document.write('<div style="position:absolute; width:16px; height:14px; z-index:0; top: ' + top2 + 'px; left: ' + left2 + 'px">');
	  document.write('<a onMouseOver="' + stat2 + '" onMouseOut="' + stat3 + '" href="javascript:parent.blank.focus();device1(\'' +title1+ '\', \'' +text1+'\', \'rwis' +image1+'.jpg\');">');
  }

  if (icon3 == "planx"){
  	document.write('<img alt="' + title1 + '"  border="0" src="images/sm_' + icon3 + '.gif" width="15" height="13">');
  } else {
  	document.write('<img alt="' + title1 + '"  border="0" src="images/sm_' + icon3 + '.gif" width="16" height="14">');
  }
  document.write('</a></div>');
  document.close();
  }
}

function displayImage1() {
  parent.image.document.open();
  parent.image.document.write("<html><HEAD>");
  parent.image.document.write('<meta http-equiv="pragma" content="no-cache">');
  parent.image.document.write('<meta http-equiv="Cache-Control" content="no-cache">');
  parent.image.document.write("</HEAD><body bgcolor='99CC99'>");
  if (parent.mapnav.browserVersion == "nav") {
    parent.image.document.write('<layer id="border" width="192px" height="150px" z-index="2" top="-3px" left="-3px">');
  } else {
    parent.image.document.write('<div id="border" style="position: absolute; left: -3px; top: -3px; width: 192px; height: 150px; z-index: 2">');
  }
  parent.image.document.write('<a href="javascript:parent.blank.focus();parent.map.window1();">');
  parent.image.document.write('<img alt="Click on image to enlarge." name="border_010" src="../2_home/images/new_border_overlay.gif" border="0" width="192" height="150">');
  parent.image.document.write("</a>");
  if (parent.mapnav.browserVersion == "nav") {
    parent.image.document.write('</layer>');
    parent.image.document.write('<layer id="insideImage" width="192px" height="150px" z-index="1" top="6px" left="5px">');
  } else {
    parent.image.document.write('</div>');
    parent.image.document.write('<div id="insideImage" style="position: absolute; left: 5px; top: 6px; width: 192px; height: 150px; z-index: 1">');
  }
  parent.image.document.write('<img alt="Click on image to enlarge." border="0" width="175" height="131" src=');
  parent.image.document.write(current_image);
  parent.image.document.write(">");
  if (parent.mapnav.browserVersion == "nav") {
    parent.image.document.write('</layer>');
  } else {
    parent.image.document.write('</div>');
  }
  parent.image.document.write("</body></html>");
  parent.image.document.close();
}

// This function opens a new parent.mapnav.browserVersion window and displays the current image
// in full size.
function window1() {
  var win2 = window.open("../2_home/newwin.htm","","width=320,height=240,status=no,resizable=no");
}

//	POPUP BOXES FOR CAMERAS AND TEXT BOXES (USES POPUP.JS for "popup" function)
// This function opens a popup for icons that display text only

function device(title2, text2) {
//	alert(text2);
	setInfoText(title2,text2,'');
}
function device2(title2, text2) {
	setAudioText(title2,text2);
}
function device_POP(title2, text2) {
  	if (typeof(popupText) != "object" || popupText.closed){
		popupText=open("","DisplayWindow","height=150,width=300,status=no,top=170, left=460, toolbar=no,directories=no,menubar=no,location=no,statusbar=0,resizable=1, scrollbars=1, titlebar=0 alwaysRaised=1");
		popupText.document.write("<html><head></head>");
		popupText.document.write('<body bgcolor="white" text="black" onLoad="window.print()">');
		popupText.document.write('<p style="text-align: center; font-weight: bold;">' + title2 + '</p><p style="text-align: center;">' + text2 + '</p>');
    popupText.document.write('</body></html>');
		popupText.document.clear();
		popupText.document.close();
	} else {
		popupText.document.clear();
		popupText.document.write("<html><head></head>");
		popupText.document.write('<body bgcolor="white" text="black" onLoad="window.print()">');
		popupText.document.write('<p style="text-align: center; font-weight: bold;">' + title2 + '</p><p style="text-align: center;">' + text2 + '</p>');
		popupText.document.write('</body></html>');
		popupText.document.clear();
		popupText.document.close();
	}
	popupText.focus();
}

// This function opens a popup for icons that display images and text
function device1(title2, text2, img2) {
	setInfoText(title2,text2,'<br><a title="Click to Enlarge" href="../1_devices/' + img2 + '" target="_blank"><img border="1" width="320" height="240" hspace="0" vspace="0" src="../1_devices/' + img2 + '"></a>');
}
function device1_POP(title2, text2, imgp) {
  	if (typeof(popupText1) != "object" || popupText1.closed){
		popupText1=open("","DisplayWindow1","height=250,width=370,status=no,top=170, left=460, toolbar=no,directories=no,menubar=no,location=no,statusbar=0,resizable=1, scrollbars=1, titlebar=0 alwaysRaised=1");
		popupText1.document.write("<html><head></head>");
		popupText1.document.write('<body bgcolor="white" text="black" onLoad="window.print()">');
		popupText1.document.write('<p style="text-align: center; font-weight: bold;">' + title2 + '</p><p style="text-align: center;">' + text2 + '<br>' + imgp + '<br></p>');
    popupText1.document.write('</body></html>');
		popupText1.document.clear();
		popupText1.document.close();
	} else {
		popupText1.document.clear();
		popupText1.document.write("<html><head></head>");
		popupText1.document.write('<body bgcolor="white" text="black" onLoad="window.print()">');
		popupText1.document.write('<p style="text-align: center; font-weight: bold;">' + title2 + '</p><p style="text-align: center;">' + text2 + '<br>' + imgp + '<br></p>');
    popupText1.document.write('</body></html>');
		popupText1.document.clear();
		popupText1.document.close();
	}
	popupText1.focus();
}



// This function opens the popup for camera images
function image1(img) {
	camNum = img;
	setCamImage();
	return false;
}

function speedmap(roadlink, speed, direction){
}

function noData(){
  alert('Some of the data on this page is more than 20 minutes old. \nPlease use the text version of this site from the link on the left.');
	parent.map.document.location.replace('../2_home/nodata.htm');
}
