var map;
var iconBlue = new GIcon(); 
iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);

var iconRed = new GIcon(); 
iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);

var iconpurple = new GIcon(); 
iconpurple.image = 'http://labs.google.com/ridefinder/images/mm_20_purple.png';
iconpurple.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconpurple.iconSize = new GSize(12, 20);
iconpurple.shadowSize = new GSize(22, 20);
iconpurple.iconAnchor = new GPoint(6, 20);
iconpurple.infoWindowAnchor = new GPoint(5, 1);

var iconyellow = new GIcon(); 
iconyellow.image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
iconyellow.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconyellow.iconSize = new GSize(12, 20);
iconyellow.shadowSize = new GSize(22, 20);
iconyellow.iconAnchor = new GPoint(6, 20);
iconyellow.infoWindowAnchor = new GPoint(5, 1);

var iconwhite = new GIcon(); 
iconwhite.image = 'http://labs.google.com/ridefinder/images/mm_20_white.png';
iconwhite.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconwhite.iconSize = new GSize(12, 20);
iconwhite.shadowSize = new GSize(22, 20);
iconwhite.iconAnchor = new GPoint(6, 20);
iconwhite.infoWindowAnchor = new GPoint(5, 1);

var icongreen = new GIcon(); 
icongreen.image = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
icongreen.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

icongreen.iconSize = new GSize(12, 20);
icongreen.shadowSize = new GSize(22, 20);
icongreen.iconAnchor = new GPoint(6, 20);
icongreen.infoWindowAnchor = new GPoint(5, 1);

var iconblack = new GIcon(); 
iconblack.image = 'http://labs.google.com/ridefinder/images/mm_20_black.png';
iconblack.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconblack.iconSize = new GSize(12, 20);
iconblack.shadowSize = new GSize(22, 20);
iconblack.iconAnchor = new GPoint(6, 20);
iconblack.infoWindowAnchor = new GPoint(5, 1);

var iconorange = new GIcon(); 
iconorange.image = 'http://labs.google.com/ridefinder/images/mm_20_orange.png';
iconorange.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconorange.iconSize = new GSize(12, 20);
iconorange.shadowSize = new GSize(22, 20);
iconorange.iconAnchor = new GPoint(6, 20);
iconorange.infoWindowAnchor = new GPoint(5, 1);

var icongray = new GIcon(); 
icongray.image = 'http://labs.google.com/ridefinder/images/mm_20_gray.png';
icongray.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

icongray.iconSize = new GSize(12, 20);
icongray.shadowSize = new GSize(22, 20);
icongray.iconAnchor = new GPoint(6, 20);
icongray.infoWindowAnchor = new GPoint(5, 1);

var iconbrown = new GIcon(); 
iconbrown.image = 'http://labs.google.com/ridefinder/images/mm_20_brown.png';
iconbrown.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';

iconbrown.iconSize = new GSize(12, 20);
iconbrown.shadowSize = new GSize(22, 20);
iconbrown.iconAnchor = new GPoint(6, 20);
iconbrown.infoWindowAnchor = new GPoint(5, 1);


var customIcons = [];
customIcons["9"] = iconbrown;
customIcons["8"] = icongray;
customIcons["7"] = iconorange;
customIcons["6"] = iconblack;
customIcons["5"] = icongreen;
customIcons["4"] = iconwhite;
customIcons["3"] = iconyellow;
customIcons["2"] = iconpurple;
customIcons["1"] = iconRed;
customIcons["0"] = iconBlue;

function load() 
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("GoogleMap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		map.setMapType(G_NORMAL_MAP);
		
		map.enableGoogleBar();
		map.setCenter(new GLatLng(27.6520306, 18.215332), 5);
		GDownloadUrl("http://www.ltt.ly/js/wimaxsites3.kml", function(data) 
		{

			var xml = GXml.parse(data);
			var placemarks = xml.documentElement.getElementsByTagName("Placemark");
			for (var i = 0; i < placemarks.length ; i++) 
			{

				map.addOverlay(createMarker(placemarks[i]));


	
		
			}
		});
		
	}
	
}
function createMarker(i) 
{
	var name = getnodetext(i.getElementsByTagName("name"));




	var description = getnodetext(i.getElementsByTagName("description"));




	var coordinates = getnodetext(i.getElementsByTagName("Point")[0].getElementsByTagName("coordinates"));
	var styleUrl = getnodetext(i.getElementsByTagName("styleUrl"));
	var Points=new Array();
	var Points=coordinates.split(",");
	var lng=Points[0];
	var lat=Points[1];
	var alt=Points[2];
	var icon=gettype(styleUrl);

	var html=name+"<br/>"+description;
	
	var pointm = new GLatLng(parseFloat(lat),parseFloat(lng));
	var mark = new GMarker(pointm, customIcons[icon]);
	GEvent.addListener(mark, 'click', function() 
	{
		mark.openInfoWindowHtml(html,{maxWidth:500});
	});
	return mark;
}
function getnodetext(i)
{
	var text="";
	if (i.length!=0)
	{
		for (var j = 0; j < i.length ; j++) 
		{
			text=text+i[j].childNodes[0].nodeValue;	
		}
	}
	return text;
}


function gettype(i)
{
	var icon;
	if(i.match("red")) icon=1;
	if(i.match("grn")) icon=5;
	if(i.match("ylw")) icon=3;
	return icon;
}


function atunload()
{

GUnload();
}
