function Airport(airportXML, imgroot_in)
{    
    this.guid = airportXML.getAttribute("guid");
    this.date = airportXML.getAttribute("date");
    this.name = airportXML.getAttribute("name");
    this.faaidentifier = airportXML.getAttribute("faaidentifier");
    this.airfieldtype = airportXML.getAttribute("airfieldtype");
    this.elevation = airportXML.getAttribute("elevation");
    this.address1 = airportXML.getAttribute("address1");
    this.address2 = airportXML.getAttribute("address2");
    this.address3 = airportXML.getAttribute("address3");
    this.city = airportXML.getAttribute("city");
    this.state_province = airportXML.getAttribute("state_province");
    this.postal_code = airportXML.getAttribute("postal_code");
    var c = airportXML.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");
    this.imgroot = imgroot_in + "/images/";      
}

Airport.prototype.guid = null;
Airport.prototype.date = null;
Airport.prototype.name = null;
Airport.prototype.faaidentifier = null;
Airport.prototype.airfieldtype = null;
Airport.prototype.elevation = null;
Airport.prototype.address1 = null;
Airport.prototype.address2 = null;
Airport.prototype.address3 = null;
Airport.prototype.city = null;
Airport.prototype.state_province = null;
Airport.prototype.postal_code = null;
Airport.prototype.latitude = null;
Airport.prototype.longitude = null;
Airport.prototype.dmslatitude = null;
Airport.prototype.dmslongitude = null;
Airport.prototype.visible = false;
Airport.prototype.imgroot = null;

Airport.prototype.show = function(b_show)
{
	//if (false == this.visible)
    //{
    
        var marker = this.createMarker();
        if (null != marker)
        {
            map.addOverlay(marker);            
        }
        else
        {
            alert("In Airport.prototype.show:  the marker is null!");
        }
    //}
    this.visible = b_show;
}

Airport.prototype.createMarker = function()
{   
    var icon = this.createIcon();
    var marker = null;
    //alert("foo");
    
    if (null != icon)
    {
		marker = new GMarker(new GLatLng(this.latitude, this.longitude), {title:this.name, icon:icon});
        
        //if (markers)
        //{
		//	markers[markers.length] = marker;
		//}
		
		//determine which array to add to based on type
		if (this.airfieldtype == "Airport")
		{
		//alert('inside major type:' + this.airfieldtype);
		    if (airport_markers)
            {
			    airport_markers[airport_markers.length] = marker;
			    airport_guids[this.guid] = this.guid;
		    }
		}
		else
		{
		    //alert('inside minor type'+ this.airfieldtype);
		    if (minor_airport_markers)
            {
			    minor_airport_markers[minor_airport_markers.length] = marker;
			    minor_airport_guids[this.guid] = this.guid;
		    }
		}
		
        var html = this.getInfoWindowHtml();
        GEvent.addListener(marker, "click", function() {
		    marker.openInfoWindowHtml(html);
	    });
	    
	    /* this code is to open another window onclick instead
        var html = this.getInfoWindowHtml();
        GEvent.addListener(marker, "click", function() {
	         window.open ("http://www.airnav.com/airports/"+this.faaidentifier,"Airport Detail");
	        //window.document.location.href='http://www.airnav.com';
	    });
	    */
    }
    else
    {
        alert("In Airport.prototype.createMarker:  the icon is null!");
    }
    
    return marker;
}

Airport.prototype.createIcon = function()
{
    var baseIcon = new GIcon();
    baseIcon.shadow = this.imgroot + "google/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/" + this.getIconImage();
    
    return icon;
}

Airport.prototype.getIconImage = function()
{
    var icon = null;
    
    switch(this.airfieldtype)
    {
        case "Airport":                
            icon = "orange_sign.png";
            break;        
        default:
            //alert('default icon');
            icon = "lav_sign.png";
            break;
    }   
    return icon;
}

Airport.prototype.getInfoWindowHtml = function()
{
	//var html = "<div style=\"bubbleGeneralTab\">";		    
	var html = this.createAirportTable();
	//html += "</div>";
    		    
	return html;
}

Airport.prototype.createAirportTable = 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>" + this.name + "</h4></td>";
	    ret += "</tr>";
		
		ret += "<tr valign=\"top\">";
	    ret += "<td>FAA Identifier</td>";
	    ret += "<td>" + this.faaidentifier + "</td>";
	    ret += "</tr>";
		
		ret += "<tr valign=\"top\">";
	    ret += "<td>Airfield Type:</td>";
	    ret += "<td>" + this.airfieldtype + "</td>";
	    ret += "</tr>";				
				
	    ret += "<tr valign=\"top\">";
	    ret += "<td>State:</td>";
	    ret += "<td>" + this.state_province + "</td>";
	    ret += "</tr>";
	    
	    ret += "<tr valign=\"top\">";
	    ret += "<td>Zip code:</td>";
	    ret += "<td>" + this.postal_code + "</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 += "</table>";	    
	    
	}
	
	return ret;
}

