﻿/** START DEFAULT **/
title= "Traffic Conditions"
icon =  "http://nttawww1.ntta.org/images/pub_traffic_icon.jpg"

//set advisory tip layer
var AdvisoryTipLayerName="Tip"
var AdvisoryTipVisible=false
var MainMapLayerName="map"
var lastX
var lastY
var ie = document.all ? true : false
var ns4 = document.layers ? true : false
var ns6 = document.getElementById ? true : false //can be true for ie4+ as well
var baseopacity=0;

if(ns4){
	window.captureEvents(Event.MOUSEMOVE)
	window.onmousemove = window_onMouseMove
}
    
function moveAdvisoryTip(divTop, divLeft,numchars){
	//numchars are a patch to deal with netscape 6 problems
	var x = divLeft - 40;
	var y = divTop + 30;
	if(ie)
	{
		var AdvisoryTipWidth = document.all[AdvisoryTipLayerName].clientWidth;
		var AdvisoryTipHeight = document.all[AdvisoryTipLayerName].clientHeight;
		if (x < 0)
			x = 0;
		else if ((x + AdvisoryTipWidth) > (document.body.clientWidth + document.body.scrollLeft))
			x = (document.body.clientWidth + document.body.scrollLeft) - AdvisoryTipWidth - 10;
		if ((y + AdvisoryTipHeight) > (document.body.clientHeight + document.body.scrollTop))
			y = posY - AdvisoryTipHeight - 10;
	}
	else if (ns6)
	{
		//find out lower boundary of main division
	        var maxBot = parseInt(document.getElementById(MainMapLayerName).offsetHeight)-10;
		var numlines=0;
		var myBot=0;
		var pixheight = 0;
		var pixelsleft=0;
		if (x < 0){
			x = 0;
		}
		//figure out how many lines are in advisory tip, assume 12 char max per line, then add 12 padding
		if(numchars>0){
			 numlines = Math.round(numchars/12);
		}else{
			 numlines = 0;
		}
		//add height to y, see if it's close or greater than maxbot
		//note that each line is 12 px tall
		pixheight = numlines * 12+24;
		myBot = y + (numlines*12);

		//the difference between maxBot and myBot must be more than myBot
		pixelsleft = maxBot-myBot;

		//if y is too big, chop some off
		if((pixelsleft<1) || (pixelsleft<(numlines*12-12))){
			y = maxBot-(numlines*12)-12;
			x = x-60;
		}
	}

	else if (ns4)
	{
 		var AdvisoryTipWidth = document.layers[AdvisoryTipLayerName].clip.width;
		var AdvisoryTipHeight = document.layers[AdvisoryTipLayerName].clip.height;

		if (x < 0)
			x = 0;
		else if ((x + AdvisoryTipWidth) > (window.pageXOffset + window.innerWidth))
			x = window.innerWidth - AdvisoryTipWidth -10;
		if ((y + AdvisoryTipHeight) > (window.pageYOffset + window.innerHeight))
			y = posY - AdvisoryTipHeight - 10;
	}
	moveLayer(AdvisoryTipLayerName, x, y);
}
function moveLayer(layerID, x, y){
	if (ie){
		document.all[layerID].style.left = x;
		document.all[layerID].style.top = y;
	}
	else if (ns6){
		document.getElementById(layerID).style.left = x;
		document.getElementById(layerID).style.top = y;
	}

	else if (ns4 && document.layers[layerID]){
		document.layers[layerID].left = x;
		document.layers[layerID].top = y;
	}
}

function window_onMouseMove(evnt)
{
	if(ns4)
	{
		lastX = evnt.pageX + pageXOffset;
		lastY = evnt.pageY;
	}
	else if(ie || ns6)
	{
		lastX = window.event.x + document.body.scrollLeft;
		lastY = window.event.y + document.body.scrollTop;
	}

	if(AdvisoryTipVisible)
		moveAdvisoryTip(lastX, lastY);
}


function getObj(objID) {
  var theObj
  if (ie)
    theObj = document.all[objID];
  else if (ns6)
    theObj = document.getElementById(objID);
  else if (ns4)
    theObj = document.layers[objID];

  if(theObj != 'undefined' || theObj != null) {
      return theObj;
  }
  else {
    alert('browser not found');//return null;
  }
}
/** END DEFAULT **/

/** START SPEEDMAP **/
function getTravelTime(speed) {
  if (speed = 0) { speed = getDefaultSpeed(segmentID); }
  var distanceInMiles = (56086/5280);
  var distanceInKM = (distanceInMiles * 1.6);
  var travelTime = distanceInMiles/speed;
  var estimatedHours = parseInt(travelTime);
  var estimatedMinutes = (parseInt(parseFloat((travelTime - estimatedHours) * 60)));
  var estimatedTravelTime = estimatedHours + " hrs " + estimatedMinutes + " min";

  return estimatedTravelTime;
}

function showSegmentAdvisory(segmentID) {
  var div = getObj(segmentID)
  div.style.visibility="visible";
  div.style.display = 'block';
  slowhigh(segmentID);
}

function hideSegmentAdvisory(segmentID) {
  slowlow(segmentID);
   var div = getObj(segmentID)
   div.style.visibility="hidden";
   div.style.display = 'none';
}
/** END SPEEDMAP **/

/** START INCIDENT **/
function showIncidentAdvisory(thePlazaIcon, thePlazaTableId) {
  var div = getObj(thePlazaTableId);
  positionPlazaTable(thePlazaIcon, div)
  div.style.visibility='visible';
  div.style.display = 'block';
  slowhigh(thePlazaTableId);
}

function hideIncidentAdvisory(thePlazaTableId) {
  slowlow(thePlazaTableId);
  var div = getObj(thePlazaTableId);
  div.style.visibility='hidden';
  div.style.display = 'none';
}
/** END INCIDENT **/

/** START LANE CLOSURES **/
function hideLaneClosureAdvisory(PlazaID) {
	//var hiddenField = getObj("_ctl0_BodyContent_LaneClosures1_hfPlazaID");
	//hiddenField.value = null;
	
	var div = getObj("divPlazaDetails" + PlazaID);
	div.style.visibility = 'hidden';
	div.style.display = 'none';
	
	//var btn = getObj("_ctl0_BodyContent_LaneClosures1_btnHide");
	
	//if (btn!=null) {
	//	btn.click(); 
	//}
}

function showLaneClosureAdvisory(PlazaID){
	var div = getObj("divPlazaDetails" + PlazaID);
	div.style.visibility = 'visible';
	div.style.display = 'block';
	 
	//var hiddenField = getObj("_ctl0_BodyContent_LaneClosures1_hfPlazaID");
	//hiddenField.value = PlazaID;
	//var btn = getObj("_ctl0_BodyContent_LaneClosures1_btnShow");
	
	//if (btn!=null) {
	//	btn.click(); 
	//}
}
/** END LANE CLOSURES **/


function positionPlazaTable(thePlazaIcon, thePlazaTable) {
  thePlazaTable.style.left = 20;  // NW QUAD
  thePlazaTable.style.top = 10;
}

function setStartDisplay() {
	var txt1 = document.getElementById("ctl00_ContentPlaceHolder1_tbxClosedFromDate");
	var txt2 = document.getElementById("ctl00_ContentPlaceHolder1_tbxBeginDate");

	txt2.value = txt1.value;
}

function setStopDisplay() {
	var txt1 = document.getElementById("ctl00_ContentPlaceHolder1_tbxClosedToDate");
	var txt2 = document.getElementById("ctl00_ContentPlaceHolder1_tbxStopDate");

	txt2.value = txt1.value;
}


function positionPlazaTable(thePlazaIcon, thePlazaTable) {
  thePlazaTable.style.left = 20;  // NW QUAD
  thePlazaTable.style.top = 10;
}

/***********************************************
* Gradual Highlight image script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
* Modification by cr3ative to fade out again.
* Modified to work with NTTA Speed Map by slh
***********************************************/
var browserdetect;   /*for IE6 leave out*/
function slowhigh(theObjID){
  theObj = getObj(theObjID);
  imgobj=theObj
  /*browserdetect=theObj.filters ? "ie" : typeof theObj.style.MozOpacity=="string"? "mozilla" : ""*/  /*leave in for IE6*/
  instantset(baseopacity)
  highlighting=setInterval("gradualfade(imgobj)",20)
}

function slowlow(theObjID) {
  theObj = getObj(theObjID);
  cleartimer();
  setTimeout(function() {fadeoutest(theObj);}, 20);
}

function instantset(degree){
  if (browserdetect=="mozilla") {
    imgobj.style.MozOpacity=degree/100
  }
  else if (browserdetect=="ie") {
    imgobj.filters.alpha.opacity=degree
  }
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
  if (browserdetect=="mozilla" && cur2.style.MozOpacity<1) {
    cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 1.0) // CHANGE THIS NUMBER TO LOWER/RAISE TRANSPARENCY
  }
  else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100) {  // CHANGE THIS NUMBER TO LOWER/RAISE TRANSPARENCY
    cur2.filters.alpha.opacity+=10
  }
  else if (window.highlighting) {
    clearInterval(highlighting)
  }
}

function fadeoutest(cur3){
  cr3=setTimeout(function() {fadeoutest(cur3);}, 20)
  if (browserdetect=="mozilla" && cur3.style.MozOpacity>0.0) {
    cur3.style.MozOpacity=Math.min(parseFloat(cur3.style.MozOpacity)-0.1)
  }
  else if (browserdetect=="ie" && cur3.filters.alpha.opacity>0) {
    cur3.filters.alpha.opacity=cur3.filters.alpha.opacity-10
  }
  if (browserdetect=="mozilla" && cur3.style.MozOpacity<=0.0) {
    clearTimeout(cr3);
  }
  if (browserdetect=="ie" && cur3.filters.alpha.opacity<=0) {
    clearTimeout(cr3);
  }
}
//  ************************  END FADE OUT SCRIPT  ****************************