var map, isIE = (/*@cc_on ! @*/ false);

function notifyOpener() {
	if (self.opener || !self.opener.newwindow) self.opener.newwindow = self;
}

if (isIE)
	render_map(true);
else if (document.addEventListener)
	document.addEventListener("DOMContentLoaded", render_map, false);
else
	window.onload = render_map;

function render_map(ieDefer) {
	if (mapsize == "big") setInterval(notifyOpener, 200);
//	OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
	OpenLayers.Util.onImageLoadErrorColor = "transparent";
	OpenLayers.Util.onImageLoadError = function() {
		this.src = "http://hub.flightaware.com/images/mapcontrol/blank.gif";
		this.style.display = "";
	};
//	Proj4js.defs["AUTO:42003"] = "+proj=ortho +lat_0=40 +lon_0=-40 +x_0=0 +y_0=0 +units=m +no_defs";
	OpenLayers.Renderer.symbol.plane = [0,10, 1,8, 1,2, 9,-3, 1,-2, 1,-7, 3,-10, 0,-9, -3,-10, -1,-7, -1,-2, -9,-3, -1,2, -1,8, 0,10];

	var options = {
		theme: null,
		projection: new OpenLayers.Projection("EPSG:4326"),
		maxResolution: 0.6,
//		projection: new OpenLayers.Projection("AUTO:42003,9001,-40,40.0"),
//		displayProjection: new OpenLayers.Projection("EPSG:4326"),
//		maxResolution: 156543.0339,
//		maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
		buffer: 0,
		maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
		restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
		controls: [
			new OpenLayers.Control.Navigation(),
			new OpenLayers.Control.KeyboardDefaults(),
			new OpenLayers.Control.Attribution(),
			new OpenLayers.Control.PanPanel(),
			new OpenLayers.Control.ZoomPanel(),
			new OpenLayers.Control.LayerSwitcher(),
			new OpenLayers.Control.ScaleLine()
		]
	};
	map = new OpenLayers.Map("map", options);

// *** Dummy layer ***
	dummy = new OpenLayers.Layer(
		"Dummy", {
			isBaseLayer: true,
			displayInLayerSwitcher: false,
			attribution: "<div>&copy; 2009 FlightAware.com</div>",
			numZoomLevels: 10
		}
	);
	map.addLayer(dummy);

// *** Terrain layer from TileCache ***
	classic = new OpenLayers.Layer.TileCache(
		"Classic",
		"http://" + tile_cdn + "/images/tilecache/",
		"all", {
			isBaseLayer: false,
			visibility: false,
			displayInLayerSwitcher: false,
			gutter: 0,
			buffer: 0,
			numZoomLevels: 11,
			tileSize: new OpenLayers.Size(600, 600)
		}
	);
	map.addLayer(classic);

// *** True Marble from TileCache ***
    earthview = new OpenLayers.Layer.TileCache(
		"Earth View",
		"http://" + tile_cdn + "/images/tilecache/",
		"marble", {
			isBaseLayer: false,
			visibility: false,
			displayInLayerSwitcher: false,
			format: "image/jpeg",
			gutter: 0,
			buffer: 0,
			numZoomLevels: 11,
			tileSize: new OpenLayers.Size(600, 600),
			attribution: "<span>Imagery &copy; Unearthed Outdoors</span>"
        }
	);
	map.addLayer(earthview);

// *** Sectionals from TileCache ***
    aviationsectional = new OpenLayers.Layer.TileCache(
		"Aviation Sectional",
		"http://" + tile_cdn + "/images/tilecache/",
		"usasectional", {
			isBaseLayer: false,
			visibility: false,
			displayInLayerSwitcher: false,
			format: "image/jpeg",
            gutter: 0,
            buffer: 0,
			numZoomLevels: 11,
            tileSize: new OpenLayers.Size(600, 600),
			maxExtent: new OpenLayers.Bounds(-169, 18, -60, 72)
        }
	);
	map.addLayer(aviationsectional);

// *** Radar weather layer from FlexMaps ***
	weather = new OpenLayers.Layer.WMS("Weather",
		"http://" + weather_cdn + "/ajax/weather.rvt", {
			cdnEnabled: cdnEnabled,
			clock: nexrad_time
		}, {
			DEFAULT_PARAMS: { },
			isBaseLayer: false,
			getURL: FlexGetURL,
			gutter: 0,
			buffer: 0,
			opacity: 0.30,
			tileSize: new OpenLayers.Size(1000, 1000),
			maxExtent: new OpenLayers.Bounds(-126, 24, -66, 50),
			attribution: "<span>Weather: " + zulu_date(nexrad_time * 1000) + "</span>"
        }
	);
    map.addLayer(weather);

	draw_controls(document.getElementById("map"));

// *** Styles ***
	major_Classic = new OpenLayers.Style({
			label: "  ${getLabel}  ",
			labelAlign: "lm",
			fontSize: "12px",
			fontFamily: "Lucida Sans, Arial, Helvetica",
			fillColor: "#FFFF00",
			fontColor: "#FFFF00",
			pointRadius: 2
		}, { context: { getLabel: function(feature) { if (feature.layer.map.getZoom() > 3) return feature.attributes.label; else return ""; } }
	});
	major_EarthView = new OpenLayers.Style({
		fillColor: "#ED8000",
		fontColor: "#ED8000"
	});
	major_AviationSectional = new OpenLayers.Style({
		fillColor: "#0000CC",
		fontColor: "#0000CC",
		pointRadius: 3
	});
	major_stylemap = new OpenLayers.StyleMap({
		"default": major_Classic,
		AviationSectional: major_AviationSectional,
		EarthView: major_EarthView
	});

	planes_Classic = new OpenLayers.Style({
		label: " \n${ident} ${type}\n${altitude} ${groundspeed}\n${origin} ${destination}\n ",
		fillColor: "#00FF00",
		fontColor: "#00FF00",
		fontSize: "11px",
		fontFamily: "Lucida Sans, Arial, Helvetica",
		graphicName: "plane",
		rotation: "${direction}",
		pointRadius: 7,
		labelAlign: "${hAlign}"
	});
	planes_EarthView = new OpenLayers.Style({
		fillColor: "#ED8000",
		fontColor: "#ED8000"
	});
	planes_AviationSectional = new OpenLayers.Style({
		fillColor: "#000099",
		fontColor: "#000099"
	});
	text_shadow_style = new OpenLayers.Style({
		fontColor: "#000000",
		pointRadius: 0
	});
	white_shadow = new OpenLayers.Style({
		fontColor: "#FFFFFF",
		pointRadius: 0
	});
	plane_shadow_style = new OpenLayers.Style({
		fillColor: "#000000",
		label: ""
	});
	planes_stylemap = new OpenLayers.StyleMap({
		"default": planes_Classic,
		EarthView: planes_EarthView,
		AviationSectional: planes_AviationSectional,
		"text_shadow": text_shadow_style,
		"plane_shadow": plane_shadow_style,
		"white_shadow": white_shadow
	});

	tracks_Classic = new OpenLayers.Style({
		label: "  ${label}  ",
		strokeColor: "#00FF00",
		stroke: true,
		pointRadius: 2,
		fillColor: "#00FF00",
		fontColor: "#FFFF00",
		fontSize: "13px",
		fontFamily: "Lucida Sans, Arial, Helvetica",
		labelAlign: "${hAlign}"
	});
	tracks_EarthView = new OpenLayers.Style({
		strokeWidth: 2,
		strokeOpacity: 0.7,
		strokeColor: "#ED8000",
		fillColor: "#ED8000",
		fontColor: "#ED8000"
	});
	tracks_AviationSectional = new OpenLayers.Style({
		strokeWidth: 4,
		strokeOpacity: 0.4,
		strokeColor: "#0000CC",
		fillColor: "#0000CC",
		fontColor: "#0000CC"
	});
	tracks_stylemap = new OpenLayers.StyleMap({
		"default": tracks_Classic,
		EarthView: tracks_EarthView,
		AviationSectional: tracks_AviationSectional
	});

	route_Classic = new OpenLayers.Style({
		strokeWidth: 1,
		strokeDashstyle: "longdash",
		strokeColor: "#4499FF",
		stroke: true
	});
	route_EarthView = new OpenLayers.Style({
		strokeWidth: 1,
		strokeDashstyle: "longdash",
		strokeOpacity: 0.7,
		strokeColor: "#4499FF"
	});
	route_AviationSectional = new OpenLayers.Style({
		strokeWidth: 2,
		strokeDashstyle: "dash",
		strokeOpacity: 0.4,
		fillColor: "#0000CC",
		strokeColor: "#0000CC"
	});
	route_stylemap = new OpenLayers.StyleMap({
		"default": route_Classic,
		EarthView: route_EarthView,
		AviationSectional: route_AviationSectional
	});

	waypoint_Classic = new OpenLayers.Style({
		pointRadius: 1,
		fillColor: "#FFFFFF"
	});
	waypoint_EarthView = new OpenLayers.Style({
	});
	waypoint_AviationSectional = new OpenLayers.Style({
		pointRadius: 2,
		fillColor: "#000000"
	});
	waypoint_stylemap = new OpenLayers.StyleMap({
		"default": waypoint_Classic,
		EarthView: waypoint_EarthView,
		AviationSectional: waypoint_AviationSectional
	});

	json_major = new OpenLayers.Format.GeoJSON();
	json_tracks = new OpenLayers.Format.GeoJSON({
//		internalProjection: new OpenLayers.Projection("AUTO:42003"),
//		externalProjection: new OpenLayers.Projection("EPSG:4326")
	});
	json_route = new OpenLayers.Format.GeoJSON();
	json_waypoint = new OpenLayers.Format.GeoJSON();

	major_parsed = json_major.read(major_airports);
	tracks_parsed = json_tracks.read(trackstring);
	route_parsed = json_tracks.read(routestring);
	waypoint_parsed = json_tracks.read(waypointstring);

	var cookiearray = get_cookies();
	if (cookiearray["BaseLayer"] && typeof window[cookiearray["BaseLayer"].toLowerCase()] !== "undefined") {
		window[cookiearray["BaseLayer"].toLowerCase()].setVisibility(true);
		lastActive = document.getElementById(cookiearray["BaseLayer"]);
		lastActive.className = "Active";
	} else {
		classic.setVisibility(true);
		lastActive = document.getElementById("Classic");
		lastActive.className = "Active";
	}
	if (cookiearray["Weather"]) {
		weather.setVisibility(cookiearray["Weather"] * 1);
	}
	if (cookiearray["center"] && typeof flight_id != "undefined" && cookiearray["flight_id"] && cookiearray["flight_id"] == flight_id) {
		var vals = cookiearray["center"].split(",");
		map.setCenter(new OpenLayers.LonLat(vals[0].split(":")[1], vals[1].split(":")[1]), cookiearray["zoom"] * 1);
	} else if (tracks_parsed.length) {
		alternateZoomToFeatures(tracks_parsed, 11, 1.2);
	} else {
		map.setCenter(new OpenLayers.LonLat(-95.4, 30), 7);
	}

	if (ieDefer === true)
		window.attachEvent("onload", render_vectors);
	else
		render_vectors();
}

function render_vectors() {
	if (mapsize == "regular" && typeof newwindow !== "undefined" && newwindow.location && !newwindow.closed) popitup("/live/" + imgWindow, imgWidth, imgHeight);

// *** Major airports ***
	major = new OpenLayers.Layer.Vector("Major Airports", {visibility: false, styleMap: major_stylemap, displayError: notsupported});
	major.addFeatures(major_parsed);

// *** Temp vectors to be destroyed ***
	vectors = new OpenLayers.Layer.Vector("Temp Vectors");
	vectors.addFeatures(tracks_parsed);

// *** Other layers ***
	planes = new OpenLayers.Layer.Vector("Aircraft", {styleMap: planes_stylemap});
	tracks = new OpenLayers.Layer.Vector("Flown Route", {styleMap: tracks_stylemap});

// *** Flown Route ***
	splitTracks(vectors.features);
	remove_dupe_airports(major.features, (typeof origin !== "undefined" ? origin : ""), (typeof destination !== "undefined" ? destination : ""));
	map.addLayer(tracks);

// *** Planned Route ***
	route = new OpenLayers.Layer.Vector("Planned Route", {styleMap: route_stylemap});
	route.addFeatures(route_parsed);
	map.addLayer(route);

// *** Waypoints ***
	waypoint = new OpenLayers.Layer.Vector("Waypoints", {visibility: false, styleMap: waypoint_stylemap});
	waypoint.addFeatures(waypoint_parsed);
	map.addLayer(waypoint);

// *** Control panels, persistence, and autofit ***
	var panel = new OpenLayers.Control.Panel();
	var zoomfit = new OpenLayers.Control.ZoomToFeatures(tracks, { title: "Zoom to features", maxZoomLevel: 11, ratio: 1.2, autoActivate: false });
	panel.addControls([zoomfit]);
	map.addControl(panel);

	var cookiearray = get_cookies();
	if (cookiearray["BaseLayer"] && typeof window[cookiearray["BaseLayer"].toLowerCase()] !== "undefined") {
		switchVectorStyles(cookiearray["BaseLayer"]);
	} else {
		switchVectorStyles("Classic");
	}

    var overlays = {weather: "Weather", tracks: "Flown Route", route: "Planned Route", waypoint: "Waypoints", planes: "Aircraft", major: "Major Airports"};  // need to turn off weather earlier
    for (var x in overlays) {
        if (cookiearray[overlays[x].replace(" ", "")]) {
            window[x].setVisibility(cookiearray[overlays[x].replace(" ", "")] * 1);
        }
    }

	if (tracks.features.length) zoomfit.activate();
	panel.addControls([new OpenLayers.Control.CookieSetter()]);

	map.events.on({"zoomend": function (e) {
		moveSVGlabels(planes.features);
	}});
	map.events.on({"changelayer": function (e) {
		if (e.layer.CLASS_NAME == "OpenLayers.Layer.TileCache") {
//			set_cookie("BaseLayer", e.layer.name.replace(" ",""), 24);
			switchVectorStyles(e.layer.name.replace(" ",""));
		} else {
			set_cookie(e.layer.name.replace(" ", ""), e.layer.getVisibility() * 1, 24);
		}
	}});

	map.addLayer(planes);
	map.addLayer(major);
	moveSVGlabels(planes.features);

	bind_airport_clicks();

	setTimeout("classic.addOptions({transitionEffect: 'resize'}); aviationsectional.addOptions({transitionEffect: 'resize'}); earthview.addOptions({transitionEffect: 'resize'}); weather.addOptions({transitionEffect: 'resize'});", 2000);
}

function bind_airport_clicks() {
	highlightCtrl = new OpenLayers.Control.SelectFeature([tracks, major], {
		hover: true,
		highlightOnly: true,
		eventListeners: {
			beforefeaturehighlighted: function (e) { if (e.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.LineString") return false; }
		}
	});
	map.addControl(highlightCtrl);
	highlightCtrl.activate();

	clickCtrl = new OpenLayers.Control.SelectFeature([tracks, major], {
		onSelect: go_to_airport,
		clickout: true
	});
	map.addControl(clickCtrl);
	clickCtrl.activate();
}

function notsupported() {
	var oldMapImage = new Image();
	oldMapImage.src = oldMapUrl;
	if (mapsize === "regular") {
		oldMapImage.onclick = function () { popitup("/live/" + imgWindow, imgWidth, imgHeight); };
		oldMapImage.style.cursor = "pointer";
	}
	map.destroy();
	document.getElementById("map").innerHTML = "";
	document.getElementById("map").appendChild(oldMapImage);
}

function switchVectorStyles(base) {
	baseLayerName = base;
	layers = [major, tracks, planes, route, waypoint];

	for (var layer in layers) {
		for (var x = 0; x < layers[layer].features.length; x++)
			layers[layer].features[x].renderIntent = base;
		layers[layer].redraw();
	}
	update_plane_shadows(planes, true, base);
}

function update_plane_shadows(layer, fullupdate, view) {
	var text_shadow = 0, plane_shadow = 1, green_plane = 2;

	if (layer.features.length) {
		if (!fullupdate) {
			var lastLoc = layer.features[green_plane].geometry,
			scaleAltitude = Math.min(5, layer.features[green_plane].attributes.altitude / 60), newloc;
		}

		if (fullupdate) {
			if (view === "AviationSectional")
				layer.features[text_shadow].renderIntent = "white_shadow";
			else
				layer.features[text_shadow].renderIntent = "text_shadow";
		} else {
			newloc = new OpenLayers.LonLat(lastLoc.x + map.getResolution(), lastLoc.y - map.getResolution());
			layer.features[text_shadow].move(newloc);
			layer.features[text_shadow].move(newloc); // fix unknown bug
		}

		if (fullupdate) {
			layer.features[plane_shadow].renderIntent = "plane_shadow";
		} else {
			newloc = new OpenLayers.LonLat(lastLoc.x + map.getResolution() * scaleAltitude, lastLoc.y - map.getResolution() * scaleAltitude);
			layer.features[plane_shadow].move(newloc);
			layer.features[plane_shadow].move(newloc); // fix unknown bug

			newloc = new OpenLayers.LonLat(lastLoc.x, lastLoc.y); // another unknown bug relating to zIndex
			layer.features[green_plane].move(newloc);
			layer.features[green_plane].move(newloc);
		}
	}
	layer.redraw();
}

function moveSVGlabels(farray) {
	update_plane_shadows(planes, false, "");

	// Multi-line vector labels
	for (var x = farray.length - 1; x >= 0; x--) {
		var tspans = document.getElementsByTagName("tspan");
		for (var y = 0; y < tspans.length; y++) {
			if (tspans[y].id.indexOf("MultiLine_") !== -1) {
				tspans[y].setAttributeNS(null, "x", tspans[y].parentNode.getAttributeNS(null, "x"));
				if (tspans[y].parentNode.getAttributeNS(null, "dominant-baseline") == "start") {
//					alert(document.defaultView.getComputedStyle(tspans[y], null).getPropertyValue("width"));
//					tspans[y].setAttributeNS(null, "x", tspans[y].parentNode.getAttributeNS(null, "x") - tspans[y].getAttributeNS(null, "width"));
				}
			}
		}
	}
	planes.redraw();
}

function splitTracks(farray) {
	for (var x = farray.length - 1; x >= 0; x--) {
		switch (farray[x].geometry.CLASS_NAME) {
			case "OpenLayers.Geometry.Point":
				if (farray[x].attributes.label) {
					// Origin or destination
					farray[x].attributes.hAlign = headingAlign(farray[0].attributes.direction, farray[x].attributes.type == "origin");
					window[farray[x].attributes.type] = farray[x].attributes.label;
					tracks.addFeatures(farray[x].clone());
					vectors.removeFeatures(farray[x]);
				} else {
					farray[x].attributes.hAlign = headingAlign(farray[x].attributes.direction);
					planes.addFeatures(farray[x].clone()); // text shadow
					planes.addFeatures(farray[x].clone()); // plane shadow
					planes.addFeatures(farray[x].clone()); // green plane
					vectors.removeFeatures(farray[x]);
				}
				break;
			case "OpenLayers.Geometry.LineString":
				tracks.addFeatures(farray[x].clone());
				vectors.removeFeatures(farray[x]);
				break;
		}
	}
	tracks.redraw();
	planes.redraw();
	major.redraw();
}

function headingAlign(degrees, reverse) {
	if (reverse === true)
		degrees = (degrees + 180) % 360;
	if (degrees < 90)
		return "bl";
	else if (degrees < 180)
		return "br";
	else if (degrees < 270)
		return "tr";
	else
		return "tl";
}

function remove_dupe_airports(farray, orig, dest) {
	for (var x = farray.length - 1; x >= 0; x--) {
		if (farray[x].attributes.label == orig || farray[x].attributes.label == dest)
			major.removeFeatures(farray[x]);
	}
}

function get_cookies() {
	var cookiearray = document.cookie.split("; "), resultcookie = [], x, piece;
	for (x in cookiearray) {
		piece = cookiearray[x].split("=");
		resultcookie[piece[0]] = piece[1];
	}
	return (resultcookie);
}

function set_cookie(name, value, hours) {
	document.cookie = name + "=" + value + "; expires=" + (value !== "" ? (new Date((new Date()).getTime() + 1000*60*60*hours)).toGMTString() : new Date(1997, 10, 1).toGMTString()) + "; path=/";
}

function FlexGetURL(bounds) {
	bounds = this.adjustBounds(bounds);
	var imageSize = this.getImageSize();
	var url = this.getFullRequestString({
		time:		this.params.nexrad,
		lowlat:		bounds.bottom,
		lowlon:		bounds.left,
		hilat:		bounds.top,
		hilon:		bounds.right,
		height:		imageSize.h,
		width:		imageSize.w
	});
	return url;
}

function popitup(url, width, height) {
	if (typeof newwindow !== "undefined" && newwindow.location && !newwindow.closed) {
		newwindow.location.href = url;
		newwindow.focus();
	} else {
		newwindow = window.open(url,'FlightAwareBigMap','width=' + width +',height=' + height + ',menubar=no,resizeable=yes,resizable=yes,scrollbars=no,toolbar=no,location=no,status=no,titlebar=no');
	}
}

function alternateZoomToFeatures(features, maxZoomLevel, ratio) {
	var i = 0;
	while (!features[i].geometry) i++;

	var bounds = features[i].geometry.getBounds();
	for (var j = i + 1; j < features.length; j++) {
		var geom = features[j].geometry;
		if (geom) bounds.extend(geom.getBounds());
	}
	bounds = bounds.scale(ratio);

	if ((bounds.getWidth() === 0) && (bounds.getHeight() === 0)) {
		var zoom = maxZoomLevel;
	} else {
		var desiredZoom = map.getZoomForExtent(bounds);
		var zoom = (desiredZoom > maxZoomLevel) ? maxZoomLevel : desiredZoom;
	}
	map.setCenter(bounds.getCenterLonLat(), zoom);
};

function draw_controls(container) {
	var big_window_icon = new Image();
	big_window_icon.src = "http://hub.flightaware.com/images/mapcontrol/fa-open-fullscreen.png";
	big_window_icon.className = "FullscreenIcon";
	big_window_icon.onclick = function () { popitup("/live/" + imgWindow, imgWidth, imgHeight); };
	if (mapsize === "regular") container.appendChild(big_window_icon);

	var baselayers = document.createElement("div"), buttons = [];
	baselayers.className = "BaseLayerHolder";
	for (var lay = map.layers.length - 1; lay >= 0; lay--) if (map.layers[lay].CLASS_NAME == "OpenLayers.Layer.TileCache") {
		buttons[lay] = document.createElement("div");
		buttons[lay].innerHTML = map.layers[lay].name;
		buttons[lay].idx = lay;
		buttons[lay].id = map.layers[lay].name.replace(" ", "");
		buttons[lay].onclick = switchBaseLayer;
		baselayers.appendChild(buttons[lay]);
	}
	container.appendChild(baselayers);
}

function switchBaseLayer(e) {
//	e = e || event;
	if (typeof lastActive !== "undefined") lastActive.className = "";
	set_cookie("BaseLayer", map.layers[this.idx].name.replace(" ",""), 24);
	for (var lay = map.layers.length - 1; lay >= 0; lay--) {
		if (map.layers[lay].CLASS_NAME == "OpenLayers.Layer.TileCache") {
			map.layers[lay].setVisibility(this.idx == lay);
		}
	}
	switchVectorStyles(this.id);
	this.className = this.className + "Active";
	lastActive = this;
}

function zulu_date(timestring) {
	var t = new Date(timestring),
	months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

	return t.getDate() + " " + months[t.getUTCMonth()] + " " + String(t.getUTCFullYear()).slice(-2) + " " + ("00" + t.getUTCHours()).slice(-2) + ":" + ("00" + t.getUTCMinutes()).slice(-2) + "Z";
}

function go_to_airport(e) {
	if (e.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
		if (mapsize === "big") {
			location.href = "/live/airport_status_bigmap.rvt?airport=" + e.attributes.label;
			if (self.opener) self.opener.location.href = "/live/airport/" + e.attributes.label;
		} else {
			location.href = "/live/airport/" + e.attributes.label;
		}
	}
}

// *** Stuff for airport maps
/*	vectors = new OpenLayers.Layer.Vector("Temp Vectors", {
		strategies: [new OpenLayers.Strategy.Fixed()],
		protocol: new OpenLayers.Protocol.HTTP({
			url: "http://lucent.flightaware.com/megamap/tsdirect.rvt",
			params: { search: "-idents COA11*" },
			format: new OpenLayers.Format.GeoJSON()
		}),
		styleMap: styleMap
	});

	vectors.events.on({"loadend": function (e) {
		splitTracks(vectors.features);
	}});
*/
