/********************************************************************
 *
 * Manages DMS RSS 
 * Author: TTI, Gabriel Torres
 * Date:   January 25, 2008
 *
 * Modified By: TTI, Michael Montgomery
 * Date: April 14, 2008
 * Uses code from TxDOT's scriptDMS.js written by Leobardo J. Landeros
 *
 *******************************************************************/

var veLayerDMSs = null; //layer not loaded by default
var bLayerDMSs  = false;
var kDMSRSSFile = "RSS/DMS.xml?";

var selID;
var dmsMessage;
var indexMessage;
var dmsTimer;
var dmsAgainTimer;
var dmsUpdate = 3000;
var dmsReloadTime = 60000;

// Configure message signs icons
// Created: Gabriel, 5/15/07
function ConfigureDMSIcons(layer)
{
    var iShapes = layer.GetShapeCount();
    for(var i=0; i < iShapes; ++i) {
        var shape = layer.GetShapeByIndex(i);
	  idMess=shape.GetDescription().split("~");
	  if(idMess[1].trim()=="") idMess[1]="**No Message**";
        shape.SetCustomIcon("<img src='../Images/dms.gif' height='15px' width='18px' />");	
	  //customIcon = new VECustomIconSpecification();
	  //customIcon.CustomHTML = "<img src='../Images/dms.gif' height='15px' width='18px' onmouseover=\"DMSMessage('"+ idMess[0] + "','" + idMess[1] + "')\" onmouseout='dmsStop()'>";
	  //shape.SetCustomIcon(customIcon);
	  shape.SetDescription(idMess[1]);
    }
}

// Load Dynamic Message signs map layer
// Created: Gabriel, 5/15/07
function LoadDMSs(go)
{
    showProgressIndicator("Loading message signs");        
    if (!go)
        //Time out to show the progress indicator
        //calls itself with a value to go to the ELSE portion
        setTimeout(function() { LoadDMSs(1); }, iAsyncDelay);
    else {
        if (!bLayerDMSs) {
            veLayerDMSs = new VEShapeLayer();        
            var veShapeSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, 
                              kDMSRSSFile + GetRan(), veLayerDMSs); 
            //passes ConfigureDMSIcons the layer from veShapeSpec: "veLayerDMSs"
            map.ImportShapeLayerData(veShapeSpec, ConfigureDMSIcons, false);
            bLayerDMSs = true;
        }
        else veLayerDMSs.Show();
        hideProgressIndicator();
    }
}