//get link data from XML

var lonArray = [];
var latArray = [];
var linkPoints = [];

//we don't need to go and grab new event data when link checkbox is clicked on
//we just need new link data
var linkDataExists = false;

//***maybe we can try to revisit this in the future, but the performance
//was worse because there was too much on the map
//store either true or false at particular point index of array to determine
//whether link point has already been drawn or not. This is so we don't redraw
//links that have already been drawn. First load may take some time, but this
//should reduce the number of points drawn as user pans/zooms. The index of the array
//is the pointID for that particular point on the link.
var linkPointIDDrawnArray = new Array();

var ffPolylineArray = []; //store polylines for removal on pan/zoom. Only for FireFox

var newYPixel;
var newXPixel;

function getLinkData(elem, xmlDoc) {
	var pleaseWaitScreen = new getObj('pleaseWaitScreen');
	var imageHeight = parseInt(document.getElementById("map").style.height);
	var imageWidth = parseInt(document.getElementById("map").style.width);
		
		 for (var i = 0; i < elem.length; i++) {
	
		    var linkID = elem.item(i).getAttribute("ID");
		    var color = elem.item(i).getAttribute("color");
		    var speed = elem.item(i).getAttribute("speed");
		
		    var points = elem[i].getElementsByTagName("point");
      
		    //GLog.write("points.length: " + points.length);
            for (var j = 0; j < points.length; j++) {
				
			    var pointID = points[j].getAttribute("pointID");
			
			    //don't draw point if it has already been drawn
			    	var tempPoint = new GLatLng(parseFloat(points[j].getAttribute("Lat")), parseFloat(points[j].getAttribute("Long")));
			
				    if (browser != "Netscape") {
				    	var tempDivXY = googleMap.fromLatLngToDivPixel(tempPoint); 
					    lonArray[j] = tempDivXY.x;
					    latArray[j] = tempDivXY.y;
				    }
				    else {
					    //let Google handle drawing of Polylines
					    linkPoints.push(tempPoint); 
				    }
			
                iTotalRows++;			
			
			    //*maybe we can try to revisit this in the future, but the performance
			    //was worse because there was too much on the map
			    //now set that particular index true since the point has already been drawn
			    //this way, if the user pans/zooms, the point will not be redrawn
			    //linkPointIDDrawnArray[pointID] = true;
			
            } //end for var j = 0
	  	
	  	    if (browser != "Netscape") {
			    jg_doc.setStroke(3);
	  		    jg_doc.setColor(color);
	  		    jg_doc.drawPolyline(lonArray, latArray);
	  		    jg_doc.paint();
	  		    lonArray = [];
	  		    latArray = [];
	  		    var myCanvas = document.getElementById("myCanvas");
			    myCanvas.style.display = "block";
	  	    }
	  	    else {
	  	        //store polyline in array so that we can remove on pan/zoom
	  		    ffPolylineArray[i] = new GPolyline((linkPoints), color, 3, 1);
			    googleMap.addOverlay(ffPolylineArray[i]);
			    linkPoints = [];
		    }
	  		
	  		if (pleaseWaitScreen.style.visibility == "hidden") {
	  		    showPleaseWaitScreen("Updating map. Please wait.");
	  		}
		
		    if (i == elem.length-1) {
		        //wait till last element to set drawingLinks to false
		        //now we can allow turn off of please wait screen
		        drawingLinks = false;
		    }
	     }//end for var i = 0
	
	//now display markers - we had a problem trying to display markers first
	//the xml doc was coming back incorrectly. So, putting this function after creating the links
	//seemed to have fixed the issue.
	//createXML('events', 'marker', 'tM=traffic');
    var typeString = buildEventTypeString();
    if (typeString != "") {
    //checkboxes are checked - now go get events, otherwise, don't get any thing
	    createXML('events', 'marker', typeString);
	}
    else {
        hidePleaseWaitScreen();
	}
			
	typeString = "";
		
} //end getLinkData
