define(['jquery'], function($) {

	function Gpx(data) {
		this.points = [];
		var trkpts = data.documentElement.getElementsByTagName("trkpt");
		for (var i = 0; i < trkpts.length; i++) {
			var trkpt = trkpts[i];
			var lat = parseFloat(trkpt.getAttribute("lat"));
			var lon = parseFloat(trkpt.getAttribute("lon"));
			var eles = trkpt.getElementsByTagName("ele");
			var ele = undefined;
			if (eles) {
				ele = parseFloat(eles[0].firstChild.nodeValue);
			}
			this.points.push({lat: lat, lon: lon, ele: ele});
		}
	}

	function load(url, callback) {
		$.ajax({
			url: url,
			dataType: "xml",
			success: function(data) {
				var gpx = new Gpx(data);
				callback(gpx);
			}
		});
	}
	
	return {
		load: load
	}
});

define(['jquery'], function($) {

	function Gpx($gpx) {
		var tracks = [];
		$gpx.find("trk").each(function() {
			tracks.push(new Track($(this)));
		});
		this.tracks = tracks;
	}

	function Track($trk) {
		this.name = $trk.find("name").text();
		var trackSegments = [];
		$trk.find("trkseg").each(function() {
			trackSegments.push(new TrackSegment($(this)));
		});
		this.trackSegments = trackSegments;
	}

	function TrackSegment($trkseg) {
		var trackPoints = [];
		$trkseg.find("trkpt").each(function() {
			trackPoints.push(new WayPoint($(this)));
		});
		this.trackPoints = trackPoints;
	}

	function WayPoint($wtp) {
		var attributes = ["lat", "lon"];
		for (var i = 0; i < attributes.length; i++) {
			this[attributes[i]] = $wtp.attr(attributes[i]);
		}
		var elements = ["ele"];
		for (var i = 0; i < elements.length; i++) {
			this[elements[i]] = $wtp.find(elements[i]).text();
		}
	}

	function load(url, callback) {
		$.ajax({
			url: url,
			dataType: "xml",
			success: function(data) {
				var gpx = new Gpx($(data));
				callback(gpx);
			}
		});
	}
	
	return {
		load: load
	}
});

Restructure GPX according to GPX schema
Restructure GPX according to GPX schema
