/********************************************************************
 *
 * Manages Transvista Image Snapshots RSS 
 * Author: TTI, Gabriel Torres
 * Date:   January 25, 2008
 *
 * Shamelessly stolen and updated by Michael Montgomery - 6/23/09
 *******************************************************************/

var veLayerSectionsx  = new VEShapeLayer();

//color lines
var kLineGreen  = new VEColor(0,225,0,1.0);
var kLineRed    = new VEColor(225,0,0,1.0);
var kLineYellow = new VEColor(255,255,0,1.0);
var kLineSilver = new VEColor(150,150,150,1.0);
//line width
var kDefLineWidth = 4;
var kSectionsRSSFilex = "RSS/TruckRSS.xml?";


// Configure speed map line colors and icons
// Created: Gabriel, 5/15/07
function ConfigureTruckLines(layer)
{   
    var sTitle, sStatus;
    var sSectionIcon = "";
    var lineColor;
    var iShapes = layer.GetShapeCount();
    for(var i=0; i < iShapes; ++i) {
        var shape = layer.GetShapeByIndex(i);
        sTitle = shape.GetTitle();
        sStatus = sTitle.substring(sTitle.length-2,sTitle.length);
        sTitle = sTitle.substring(0,sTitle.length-2);
                         
        if (sStatus == "~r") lineColor = kLineRed;
        else if (sStatus == "~y") lineColor = kLineYellow;
        else if (sStatus == "~s") lineColor = kLineSilver;
        else lineColor = kLineGreen;        
		sSectionIcon = "<img style='position:relative; margin-top:-2px;' " + 
                           "src='../Images/TruckTime.gif' height='15px' width='25px' />";
        shape.SetCustomIcon(sSectionIcon);
        shape.SetLineColor(lineColor);
        shape.SetLineWidth(kDefLineWidth);
        shape.SetTitle(sTitle);
    }
}

// Load Speed map (colored lines) layer
// Created: Gabriel, 5/15/07
// Updated: Gabriel, 7/18/07, Use RSS feed

function LoadTruckTimes(go)
{
    showProgressIndicator("Updating Truck Wait times");
    if (!go) {
        setTimeout(function() { LoadTruckTimes(1); }, iAsyncDelay);
    }
    else {
        veLayerSectionsx.DeleteAllShapes();
        var veShapeSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, 
            kSectionsRSSFilex + GetRan(), veLayerSectionsx);
        map.ImportShapeLayerData(veShapeSpec, ConfigureTruckLines, false);
        veLayerSectionsx.Show();
        ttiTools.showElement("imgRefreshTruckTimes");
        window.status = "Truck Wait Times loaded";
        hideProgressIndicator();        
    }
}
function TruckHideSections()
{
    veLayerSectionsx.Hide();
    ttiTools.hideElement("imgRefreshTruckTimes");
}



