function Nmac(nmacXML, imgroot_in)
{    
    this.guid = nmacXML.getAttribute("guid");
    this.url = nmacXML.getAttribute("url");
    this.utcdate = nmacXML.getAttribute("utcdate");
    this.localtime = nmacXML.getAttribute("localtime");
    this.eventid = nmacXML.getAttribute("eventid");
    this.reportnumber = nmacXML.getAttribute("reportnumber");
    this.reportingfacility = nmacXML.getAttribute("reportingfacility");
    this.cityname = nmacXML.getAttribute("cityname");
    this.airportname = nmacXML.getAttribute("airportname");
    this.incidentevaluation = nmacXML.getAttribute("incidentevaluation");
    this.diagonalseparation = nmacXML.getAttribute("diagonalseparation");
    var c = nmacXML.getElementsByTagName("coordinates")[0];
    if (c != null)
    {
        this.latitude = parseFloat(c.getAttribute("lat"));
        this.longitude = parseFloat(c.getAttribute("lng"));
        this.dmslatitude = c.getAttribute("dmslat");
        this.dmslongitude = c.getAttribute("dmslng");
    }
    var a1 = nmacXML.getElementsByTagName("aircraft1")[0];
    if (a1 != null)
    {
        this.aircraft1 = new NmacAircraft(a1);       
    }
    var a2 = nmacXML.getElementsByTagName("aircraft2")[0];
    if (a2 != null)
    {
        this.aircraft2 = new NmacAircraft(a2);
        
    }   
    
    this.imgroot = imgroot_in + "/images/";    

    
    
}

function NmacAircraft(aircraftXML)
{   
    this.operator = aircraftXML.getAttribute("operator");
    this.operationtype = aircraftXML.getAttribute("operationtype");
    this.make = aircraftXML.getAttribute("make");
    this.model = aircraftXML.getAttribute("model");
    this.series = aircraftXML.getAttribute("series");
    this.registrationnumber = aircraftXML.getAttribute("registrationnumber");
    this.flightplantype = aircraftXML.getAttribute("flightplantype");
    this.altitude = aircraftXML.getAttribute("altitude");
    this.sightseparation = aircraftXML.getAttribute("sightseparation");
}

NmacAircraft.prototype.operator = null;
NmacAircraft.prototype.operatortype = null;
NmacAircraft.prototype.make = null;
NmacAircraft.prototype.model = null;
NmacAircraft.prototype.series = null;
NmacAircraft.prototype.registrationnumber = null;
NmacAircraft.prototype.flightplantype = null;
NmacAircraft.prototype.altitude = null;
NmacAircraft.prototype.sightseparation = null;

Nmac.prototype.guid = null;
Nmac.prototype.url = null;
Nmac.prototype.utcdate = null;
Nmac.prototype.localtime = null;
Nmac.prototype.eventid = null;
Nmac.prototype.reportnumber = null;
Nmac.prototype.reportingfacility = null;
Nmac.prototype.cityname = null;
Nmac.prototype.airportname = null;
Nmac.prototype.incidentevaluation = null;
Nmac.prototype.diagonalseparation = null;
Nmac.prototype.aircraft1 = null;
Nmac.prototype.aircraft2 = null;
Nmac.prototype.latitude = null;
Nmac.prototype.longitude = null;
Nmac.prototype.dmslatitude = null;
Nmac.prototype.dmslongitude = null;
Nmac.prototype.imageroot = null;

Nmac.prototype.show = function(b_show)
{
	//if (false == this.visible)
    //{
    
        var marker = this.createMarker();
        if (null != marker)
        {
            map.addOverlay(marker);            
        }
        else
        {
            alert("In Nmac.prototype.show:  the marker is null!");
        }
    //}
    this.visible = b_show;
}
Nmac.prototype.setZindex = function(marker, b)
{
    return 2;
}
Nmac.prototype.createMarker = function()
{   
    var icon = this.createIcon();
    var marker = null;        
    
    if (null != icon)
    {
		marker = new GMarker(new GLatLng(this.latitude, this.longitude), {title:this.name, icon:icon, zIndexProcess:this.setZindex});
        
        if (nmac_markers)
        {
			nmac_markers[nmac_markers.length] = marker;
			nmac_guids[this.guid] = this.guid;
			
		}
		
		
		
        //setup display to show nmac data            
        var html = null;
        
        html = this.getInfoWindowHtml();                    		 
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
        });
    
    }
    else
    {
        alert("In Nmac.prototype.createMarker:  the icon is null!");
    }
    
    return marker;
}

Nmac.prototype.createIcon = function()
{
    var baseIcon = new GIcon();
    baseIcon.shadow = this.imgroot + "google/Nmac_shadow.png";
	baseIcon.iconSize = new GSize(20, 20);
	baseIcon.shadowSize = new GSize(37, 17);
	baseIcon.iconAnchor = new GPoint(10, 10);
	baseIcon.infoWindowAnchor = new GPoint(10, 10);
	baseIcon.infoShadowAnchor = new GPoint(10, 10);
	
    var icon = new GIcon(baseIcon);
    icon.image = this.imgroot + "google/nmac_marker.png";
    
    return icon;
}


Nmac.prototype.getInfoWindowHtml = function()
{

	var ret = "";
	if (null != this.guid)
	{
		if (this.reportnumber.search("AFSAS") != -1)
		{
			ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";

			ret += "<tr valign=\"top\">";
			ret += "<td colspan=\"2\"><h4>NEAR MIDAIR COLLISION</h4></td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Report Number:</td>";
			ret += "<td>" + this.reportnumber + "</td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Date:</td>";
			ret += "<td>" + this.utcdate + "</td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Aircraft 1:</td>";
			ret += "<td>" + this.aircraft1.model + " " + this.aircraft1.series + "</td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Aircraft 2:</td>";
			ret += "<td>" + this.aircraft2.model + " " + this.aircraft2.series + "</td>";
			ret += "</tr>";

			ret += "</table>";
		}
		else
		{
			ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";

			ret += "<tr valign=\"top\">";
			ret += "<td colspan=\"2\"><h4>NEAR MIDAIR COLLISION</h4></td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Report Number:</td>";
			ret += "<td>" + this.reportnumber + "</td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Date:</td>";
			ret += "<td>" + this.utcdate + "</td>";
			ret += "</tr>";

			ret += "<tr valign=\"top\">";
			ret += "<td>Local Time:</td>";
			ret += "<td>" + this.localtime + "</td>";
			ret += "</tr>";


			ret += "<tr valign=\"top\">";
			ret += "<td colspan=\"2\"><p><a target=\"_blank\" href=\"" + this.url + "\">Click here for event details on the FAA website</a></p></td>";
			ret += "</tr>";

			ret += "</table>";
		}

	}

	return ret;
}







