function Pois(xml)
{
	this.pois = new Array();
	this.placemarks = new Array();
	this.readXml(xml);
}
	

Pois.prototype.readXml = function(xml)
{
	var i=0;
	
	var a = new Array();

	$(xml).find('poi').each(function()
	{
		var lat = $(this).find("poi_x").text();
		var lon = $(this).find("poi_y").text();
		var type = $(this).find("poi_type").text();
		var pikto = $(this).find("poi_pikto").text();
		var html = $(this).find("poi_html").html();
		var name = $(this).find("name").html();
			
		lat = lat*10/10;
		lon = lon*10/10;
			
		var p = new Poi(name, lat, lon, type, pikto, html);
		a.push(p);
		
		i++;			
	});	
		
	this.pois = a;
}

Pois.prototype.drawPois = function(ge)
{
	for(var i=0; i<this.pois.length; i++)
	{
		
		var p = this.pois[i];
		// Create the placemark.
		var placemark = ge.createPlacemark('');

		
		// Create the placemark.
		var placemark = ge.createPlacemark('');
		placemark.setName(p.name);
		
		// Set the placemark's location.  
		var point = ge.createPoint('');
		point.setLatitude(p.lat);
		point.setLongitude(p.lon);
		placemark.setGeometry(point);
		
		// Create a style map.
		var styleMap = ge.createStyleMap('');
		
		// Create normal style for style map.
		var normalStyle = ge.createStyle('');
		var normalIcon = ge.createIcon('');
		normalIcon.setHref("http://www.absolut-gps.com/flex/pics/piktosFinalBig/"+p.getColor()+"_"+p.pikto+".png");
		normalStyle.getIconStyle().setIcon(normalIcon);
		
		// Create highlight style for style map.
		var highlightStyle = ge.createStyle('');
		var highlightIcon = ge.createIcon('');
		highlightIcon.setHref("http://www.absolut-gps.com/flex/pics/piktosFinalBig/"+p.getColor()+"_"+p.pikto+".png");
		highlightStyle.getIconStyle().setIcon(highlightIcon);
		highlightStyle.getIconStyle().setScale(3.0);
		
		styleMap.setNormalStyle(normalStyle);
		styleMap.setHighlightStyle(highlightStyle);
		
		// Apply stylemap to a placemark.
		placemark.setStyleSelector(styleMap);
		
		this.placemarks[i] = placemark;
		
		//Add the placemark to Earth.
		ge.getFeatures().appendChild(placemark);
		
	
		google.earth.addEventListener(placemark, 'click', function(event)
		{
		 	event.preventDefault();
			
			var n = 0;
			for(var i=0;i<pois.placemarks.length;i++)
			{
				if(this == pois.placemarks[i])
					n = i;
			}
	
			var p = pois.pois[n];
			var balloon = ge.createHtmlStringBalloon('');
			balloon.setFeature(this);
			balloon.setContentString(p.name+p.html);
			ge.setBalloon(balloon);																   
																   
		})	
	}
}


function Poi(name, lat, lon, type, pikto, html)
{
	this.name = name;
	this.lat = lat;
	this.lon = lon;
	this.type = type;
	this.pikto = pikto;
	this.html = html;	
}

Poi.prototype.getColor = function()
{
	if(this.pikto == "Gaststaette")
		return "gruen";
	
	if(this.type == "Uebernachtung")
		return "gruen";
	
	if(this.type == "Service")
		return "blau";

	if(this.type == "Kultur")
		return "grau";

	if(this.type == "Sonstiges")
		return "grau";

	if(this.type == "Sehenswert")
		return "grau";

	if(this.type == "Pause")
		return "grau";

	if(this.type == "Tour")
		return "blau";
		
}
				
			

