function Mac(macXML, imgroot_in)
{    
    this.guid = macXML.getAttribute("guid");
    this.url = macXML.getAttribute("url");
    this.eventdate = macXML.getAttribute("eventdate");
    this.localtime = macXML.getAttribute("localtime");
    this.eventid = macXML.getAttribute("eventid");
    this.cityname = macXML.getAttribute("cityname");
    this.state = macXML.getAttribute("state");
    var c = macXML.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 = macXML.getElementsByTagName("aircraft1")[0];
    if (a1 != null)
    {
        this.aircraft1 = new MacAircraft(a1);       
    }
    var a2 = macXML.getElementsByTagName("aircraft2")[0];
    if (a2 != null)
    {
        this.aircraft2 = new MacAircraft(a2);
        
    }
    
    this.imgroot = imgroot_in + "/images/";    

    
    
}

function MacAircraft(aircraftXML)
{   
    this.make = aircraftXML.getAttribute("make");
    this.model = aircraftXML.getAttribute("model");
    
}

MacAircraft.prototype.make = null;
MacAircraft.prototype.model = null;

Mac.prototype.guid = null;
Mac.prototype.url = null;
Mac.prototype.eventdate = null;
Mac.prototype.localtime = null;
Mac.prototype.eventid = null;
Mac.prototype.cityname = null;
Mac.prototype.state = null;
Mac.prototype.aircraft1 = null;
Mac.prototype.aircraft2 = null;
Mac.prototype.latitude = null;
Mac.prototype.longitude = null;
Mac.prototype.dmslatitude = null;
Mac.prototype.dmslongitude = null;
Mac.prototype.imageroot = null;

Mac.prototype.show = function(b_show)
{
    var marker = this.createMarker();
    if (null != marker)
    {
        map.addOverlay(marker);            
    }
    else
    {
        alert("In Mac.prototype.show:  the marker is null!");
    }

    this.visible = b_show;
}

Mac.prototype.setZindex = function(marker, b)
{
    return 2;
}

Mac.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 (mac_markers)
        {
			mac_markers[mac_markers.length] = marker;
			mac_guids[this.guid] = this.guid;			
		}
				
		
        //setup display to show mac data            
        var html = this.getInfoWindowHtml();                
		    
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
        });
    

    }
    else
    {
        alert("In Mac.prototype.createMarker:  the icon is null!");
    }
    
    return marker;
}

Mac.prototype.createIcon = function()
{
    var baseIcon = new GIcon();
    baseIcon.shadow = this.imgroot + "google/Nmac_shadow.png";  // Nmac_shadow.png works for mac_marker.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/mac_marker.png";
    
    return icon;
}


Mac.prototype.getInfoWindowHtml = function()
{
	
	var ret = "";
    if (null != this.guid)
    {                      	    
        
        ret += "<table id=\"bubbleGeneralTab\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" \">";			    

        ret += "<tr valign=\"top\">";
	    ret += "<td colspan=\"2\"><h4>MIDAIR COLLISION</h4></td>";	    
	    ret += "</tr>";
	    	   
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Date:</td>";
	    ret += "<td>" + this.eventdate + "</td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>City:</td>";
	    ret += "<td>" + this.cityname + "</td>";
	    ret += "</tr>";	
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>State:</td>";
	    ret += "<td>" + this.state + "</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>Latitude:</td>";
	    ret += "<td>" + this.dmslatitude + "</td>";
	    ret += "</tr>";	
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Longitude:</td>";
	    ret += "<td>" + this.dmslongitude + "</td>";
	    ret += "</tr>";	
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>First Aircraft:</td>";
	    ret += "<td>" + this.aircraft1.make + " / " + this.aircraft1.model + "</td>";
	    ret += "</tr>";	
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Second Aircraft:</td>";
	    ret += "<td>" + this.aircraft2.make + " / " + this.aircraft2.model + "</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 NTSB website</a></p></td>";
	    ret += "</tr>";	   	 	    	    
	    	    	     	    	    	    		        
	    ret += "</table>";
	    	    
	}
	
	return ret;
}







