
//<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {

		// Define the widht of the map depending on the browser vendor
		var myWidth = 0, myHeight = 0;
		
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		document.getElementById("map").style.width = (myWidth -203)+"px";
		document.getElementById("header-menu").style.width = (myWidth -203)+"px";
		document.getElementById("map").style.height = (myHeight-135)+"px";
		
		var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(35.325999,25.133333),14);			
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GOverviewMapControl());
			map.enableScrollWheelZoom();
			//var myLayer = new GLayer("com.panoramio.all");
			//map.addOverlay(myLayer);
			
			//map.openInfoWindow(map.getCenter(),document.createTextNode("Διαφημιστείτε εδώ."));
			//var infoWindowHTML = '<br /><a href=""><img style="border-style:none;" align="center" src="../images/weather.png" /> Καιρός </a>
			//<a href=""><img style="border-style:none;" align="center" src="../images/gus.png" /> Τιμές Καυσίμων </a>';
			
			map.openInfoWindowHtml(map.getCenter(),'<a href="../insert.php"><img style="border-style:none;" src="banners/2811_banner_468x60.png" width="468" height="60" /></a>');
			
			//Some icons...
			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 gusIcon = new GIcon(G_DEFAULT_ICON);
			gusIcon.iconSize = new GSize(32,32);
			gusIcon.shadowSize = new GSize(59,32);
			gusIcon.image = "images/gus.png";
			gusIcon.shadow = "images/gus_s.png";
			markerOptions = { icon:gusIcon };
			
			var firstAidsIcon = new GIcon(G_DEFAULT_ICON);
			firstAidsIcon.iconSize = new GSize(32,32);
			firstAidsIcon.shadowSize = new GSize(59,32);
			firstAidsIcon.image = "images/first_aids.png";
			firstAidsIcon.shadow = "images/first_aids_s.png";
			markerOptions = { icon:firstAidsIcon };
			
			var airportIcon = new GIcon(G_DEFAULT_ICON);
			airportIcon.iconSize = new GSize(32,32);
			airportIcon.shadowSize = new GSize(59,32);
			airportIcon.image = "images/airport1.png";
			airportIcon.shadow = "images/airport1_s.png";
			markerOptions = { icon:airportIcon };

			var footballIcon = new GIcon(G_DEFAULT_ICON);
			footballIcon.iconSize = new GSize(32,32);
			footballIcon.shadowSize = new GSize(59,32);
			footballIcon.image = "images/football.png";
			footballIcon.shadow = "images/football_s.png";
			markerOptions = { icon:footballIcon };
			
			var officeEpiplaIcon = new GIcon(G_DEFAULT_ICON);
			officeEpiplaIcon.iconSize = new GSize(32,32);
			officeEpiplaIcon.shadowSize = new GSize(59,32);
			officeEpiplaIcon.image = "images/chair-32.png";
			officeEpiplaIcon.shadow = "images/football_s.png";
			markerOptions = { icon:officeEpiplaIcon };
			
			var beachIcon = new GIcon(G_DEFAULT_ICON);
			beachIcon.iconSize = new GSize(32,32);
			//beachIcon.shadowSize = new GSize(59,32);
			beachIcon.image = "images/umbrella.png";
			//beachIcon.shadow = "images/football_s.png";
			markerOptions = { icon:beachIcon };			
			
			var monasteryIcon = new GIcon(G_DEFAULT_ICON);
			monasteryIcon.iconSize = new GSize(32,32);
			monasteryIcon.shadowSize = new GSize(59,32);
			monasteryIcon.image = "images/monastery.png";
			monasteryIcon.shadow = "images/monastery_s.png";
			markerOptions = { icon:monasteryIcon };
			
			var museumIcon = new GIcon(G_DEFAULT_ICON);
			museumIcon.iconSize = new GSize(32,32);
			museumIcon.shadowSize = new GSize(59,32);
			museumIcon.image = "images/museum.png";
			museumIcon.shadow = "images/museum_s.png";
			markerOptions = { icon:museumIcon };
			
			var caveIcon = new GIcon(G_DEFAULT_ICON);
			caveIcon.iconSize = new GSize(32,32);
			caveIcon.shadowSize = new GSize(59,32);
			caveIcon.image = "images/cave.png";
			markerOptions = { icon:caveIcon };
			
			var archaiologicalIcon = new GIcon(G_DEFAULT_ICON);
			archaiologicalIcon.iconSize = new GSize(32,32);
			archaiologicalIcon.shadowSize = new GSize(59,32);
			archaiologicalIcon.image = "images/archaiological.png";
			markerOptions = { icon:archaiologicalIcon };
			
			var gorgeIcon = new GIcon(G_DEFAULT_ICON);
			gorgeIcon.iconSize = new GSize(32,32);
			gorgeIcon.shadowSize = new GSize(59,32);
			gorgeIcon.image = "images/gorge.png";
			markerOptions = { icon:gorgeIcon };
			
			var cityIcon = new GIcon(G_DEFAULT_ICON);
			cityIcon.iconSize = new GSize(32,32);
			cityIcon.shadowSize = new GSize(59,32);
			cityIcon.image = "images/city.png";
			markerOptions = { icon:cityIcon };
			
			var basicIcon = new GIcon(G_DEFAULT_ICON);
			basicIcon.iconSize = new GSize(32,32);
			basicIcon.shadowSize = new GSize(59,32);
			basicIcon.iconAnchor = new GPoint(10, 10);
		    basicIcon.infoWindowAnchor = new GPoint(15, 15);
			markerOptions = { icon:basicIcon };
			
		    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 customIcons = [];
		    customIcons["restaurant"] = iconBlue;
		    customIcons["bar"] = gusIcon;
			customIcons["officeEpipla"] = officeEpiplaIcon;
			
			/*
			var benizeleio = new GMarker(new GLatLng(35.306009,25.154389),firstAidsIcon );
			map.addOverlay(benizeleio);

			var pepagni = new GMarker(new GLatLng(35.303935,25.084271),firstAidsIcon );
			map.addOverlay(pepagni);
			
			var pagritio = new GMarker(new GLatLng(35.336831,25.106142),footballIcon );
			map.addOverlay(pagritio);			

			var gipedoOfi = new GMarker(new GLatLng(35.337943,25.114735),footballIcon );
			map.addOverlay(gipedoOfi);
			
			//Heraclion airport
			var herAirport =  new GMarker(new GLatLng(35.336834, 25.174055),airportIcon);
			map.addOverlay(herAirport);
			*/

		//Function to create markers
		function createMarker(point, id, name, street,area, phone,mobile, web, subcategory, logo, gus_price, date_updated) {
			//var marker = new GMarker(point, customIcons["subcategory"]);
			
			var icon_name = "images/icons/"+subcategory+".png";
			var marker = new GMarker(point, new GIcon(basicIcon,icon_name));
			
			if (area != "")
				area = ", " + area;
			if (mobile != "")
				mobile = ", " + mobile;				
				
			if (logo ==1 && gus_price == null){
				var html = "<a target='_blank' href='" + web + "'><img src ='../images/logos/"+id+".gif' style='border:none' width='255' height='142' /></a><h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3> <h4 style='font-size:12; margin:0px; padding:0px; color:orange'> " + street + area + "</h4><img src='images/telephone.png'/> " + phone + " " + mobile + "<br /><a style='color:green' target='_blank' href=" + web+">"+web+"</a>";
			}
			else if (gus_price != null) {
				var html = "<img src =../images/logos/"+id+".gif width=150 height=100/><h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3> <h4 style='font-size:12; margin:0px; padding:0px; color:orange'> " + street + area + "</h4><img src='images/telephone.png'/> " + phone + " " + mobile + "<br />Τιμή Βενζίνης (Αμόλυβδη 95): <strong>"+ gus_price +"</strong><br />Τελευταία Ενημέρωση: "+ date_updated +"<br /><a target='_blank' href=" + web+">"+web+"</a>";

			}else
				var html = "<h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3><h4 style='font-size:12; margin:0px; padding:0px; color:orange'> " + street + area + "</h4><img src='images/telephone.png'/> " + phone + " " + mobile + "<br /><a style='color:green' target='_blank' href=" + web+">"+web+"</a>";

			GEvent.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(html);
			});
		return marker;
		}
				
		//Show Markers
		function showMarkers(e){
			map.clearOverlays();
			var targ;
			targ = e.target;
			var subcategory = targ.id;

			if (subcategory == "hotels_menu")
				subcategory = "hotels";
			if (subcategory == "rent_rooms_menu")
				subcategory = "rent_rooms";
			if (subcategory == "apartments_menu")
				subcategory = "apartments";
			if (subcategory == "villes_menu")
				subcategory = "villes";				
			if (subcategory == "traditional_rooms_menu")
				subcategory = "traditional_rooms";
			if (subcategory == "camping_menu")
				subcategory = "camping";
			
			if (subcategory == "gus_prices")
				subcategory = "gus_station";
			if (subcategory == "pharmacies")
				subcategory = "pharmacy";
				
			url = "phpsqlajax_genxml3.php?subcategory="+subcategory;
			//alert(url);
		GDownloadUrl(url, function(data) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var id = markers[i].getAttribute("id");
					var name = markers[i].getAttribute("name");
					var street = markers[i].getAttribute("street");
					var area = markers[i].getAttribute("area");
					var phone = markers[i].getAttribute("phone");
					var mobile = markers[i].getAttribute("mobile");
					var web = markers[i].getAttribute("web");
					var subcategory = markers[i].getAttribute("subcategory");
					var logo = markers[i].getAttribute("logo");
					var gus_price = markers[i].getAttribute("gus_price");
					var date_updated = markers[i].getAttribute("date_updated");
					
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
					var marker = createMarker(point, id, name, street, area, phone,mobile, web, subcategory, logo, gus_price, date_updated);
					map.addOverlay(marker);
				}
		});
		}
		
		
		//Event Listeners...
		GEvent.addDomListener(document.getElementById("menu"),"click", function showtheMarkers(e){
			showMarkers(e);
		});
		
		GEvent.addDomListener(document.getElementById("header-menu"),"click", function showtheMarkers(e){
			
			var targ;
			targ = e.target;
			var menu = targ.id;
			
			//alert(menu);
			if (menu == "crete")
				map.setCenter(new GLatLng(35.233876, 24.899999), 9);
			else if (menu == "heraklion")
				map.setCenter(new GLatLng(35.325999, 25.133333), 14);
			else if (menu == "chania")
				map.setCenter(new GLatLng(35.503355, 24.017057), 14);
			else if (menu == "rethymno")
				map.setCenter(new GLatLng(35.365167, 24.480629), 14);
			else if (menu == "agios")
				map.setCenter(new GLatLng(35.190530, 25.717406), 15);
			else if (menu == "beaches")
				showPlaces(beachIcon, "beach");
			else if (menu == "monasteries")
				showPlaces(monasteryIcon, "monastery");
			else if (menu == "museums")
				showPlaces(museumIcon, "museum");
			else if (menu == "caves")
				showPlaces(caveIcon, "cave");
			else if (menu == "archaiological_sites")
				showPlaces(archaiologicalIcon, "archaiological");
			else if (menu == "gorges")
				showPlaces(gorgeIcon, "gorge");
			else if (menu == "cities")
				showPlaces(cityIcon, "city");					
			
		});
		
		GEvent.addDomListener(document.getElementById("hotels_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});

		
		GEvent.addDomListener(document.getElementById("rent_rooms_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});

		
		GEvent.addDomListener(document.getElementById("apartments_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});

		
		GEvent.addDomListener(document.getElementById("traditional_rooms_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});
		
		GEvent.addDomListener(document.getElementById("villes_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});
		
		GEvent.addDomListener(document.getElementById("camping_menu"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
		});		
		
		GEvent.addDomListener(document.getElementById("gus_prices"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.325999, 25.133333), 14);
		});
		
		GEvent.addDomListener(document.getElementById("pharmacies"),"click", function showtheMarkers(e){
			showMarkers(e);
			map.setCenter(new GLatLng(35.325999, 25.133333), 14);
		});
		
		GEvent.addDomListener(document.getElementById("dianyktereyon"),"click", function showtheMarkers(){
			map.clearOverlays();
			map.setCenter(new GLatLng(35.325999, 25.133333), 14);
			
			url = "pharmacies.php?type=2";
			
			GDownloadUrl(url, function(data,responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("pharmacy");
				for (var i = 0; i < markers.length; i++) {
					var name = markers[i].getAttribute("name");
					var street = markers[i].getAttribute("street");
					var area = markers[i].getAttribute("area");
					var phone = markers[i].getAttribute("phone");

					//alert(name);
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
					var marker = createDianyktereyon(point, name, street, area, phone);
					map.addOverlay(marker);
				}
			});
			
			function createDianyktereyon(point, name, street, area, phone) {
				

				icon ="images/icons/pharmacy.png";
				var marker = new GMarker(point, new GIcon(basicIcon,icon));
				
				if (area != "")
					area = ", "+area;
					
				var html = "<h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3> <h4 style='font-size:12; margin:0px; padding:0px; color:orange'> " + street + area + "</h4><img src='images/telephone.png'/> " + phone;
				
				GEvent.addListener(marker, 'click', function() {
					marker.openInfoWindowHtml(html);
				});
				return marker;
			}
			
		});
		
		GEvent.addDomListener(document.getElementById("weather"),"click", function showWeather(){
			
			map.clearOverlays();
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);
			
			url = "weather.php";
			
			GDownloadUrl(url, function(data,responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("city");
				for (var i = 0; i < markers.length; i++) {
					var name = markers[i].getAttribute("name");
					var temp = markers[i].getAttribute("temp");
					var humidity = markers[i].getAttribute("humidity");
					var wind = markers[i].getAttribute("wind");
					var icon = markers[i].getAttribute("icon");

					
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
					var marker = createWeather(point, name, temp, humidity, wind, icon);
					map.addOverlay(marker);
				}
			});
			
			function createWeather(point, name, temp, humidity, wind, icon) {
				var marker = new GMarker(point, new GIcon(basicIcon,icon));
			
				var html = "<h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3> Θερμοκρασία: " + temp + "<br />" + humidity + "<br />"+wind;
				GEvent.addListener(marker, 'click', function() {
					marker.openInfoWindowHtml(html);
				});
				return marker;
			}
		});
		
		//Function to show Places
		function showPlaces(icon, type){
			map.clearOverlays();
			map.setCenter(new GLatLng(35.233876, 24.899999), 9);		
			url = "places_genxml.php?type="+type;
			//alert(url);
		GDownloadUrl(url, function(data,responseCode) {
			
			var xml = GXml.parse(data);
			var places = xml.documentElement.getElementsByTagName("place");
				for (var i = 0; i < places.length; i++) {
					var id = places[i].getAttribute("id");
					var name = places[i].getAttribute("name");
					var description = places[i].getAttribute("description");
					
					var point = new GLatLng(parseFloat(places[i].getAttribute("lat")),parseFloat(places[i].getAttribute("lng")));
					var marker = createPlaces(point, id, name, description, icon, type);
					map.addOverlay(marker);
				}
		});
		}
		
		//Function to create markers for Places
		function createPlaces(point, id, name, description, icon, type) {
			var marker = new GMarker(point, icon);
			if (type =="beach")
				type = "beaches";
			else if (type == "monastery")
				type = "monasteries";
			else if (type == "archaiological")
				type = "archaiological-sites";				
			else if (type == "cave")
				type = "caves";
			else if (type == "gorge")
				type = "gorges";
			else if (type == "city")
				type = "cities";				
			var html = "<div style='width:500; height:300'><h3 style='font-size:18; margin:0px; padding:0px; color:#105cb6'>" + name + "</h3><img src =../images/places/"+id+".jpg width=200 height=150 align=left hspace=5 /><p>" + description + "...</p>" + "<br /><a href='" + type + "/" + name + "'><img style='border:none' src='/images/more_button_light_blue.png' /></a> </div><div></div>";
				GEvent.addListener(marker, 'click', function() {
					marker.openInfoWindowHtml(html);
				});
		return marker;
		}
		
		//GEvent.addDomListener(document.getElementById("photos"),"click", function showPhotos(){
		//	var myLayer = new GLayer("com.panoramio.all");
		//	map.addOverlay(myLayer);
		//});
		
		GEvent.addDomListener(document.getElementById("archanes"),"click", function zoomtoArchanes(){
			map.setCenter(new GLatLng(35.233876, 25.158804), 16);
		});
		
		GEvent.addDomListener(document.getElementById("moires"),"click", function zoomtoMoires(){
			map.setCenter(new GLatLng(35.051234, 24.873798), 16);
		});
		
		GEvent.addDomListener(document.getElementById("sitia"),"click", function zoomtoSitia(){
			map.setCenter(new GLatLng(35.207484, 26.106530), 16);
		});
		
		GEvent.addDomListener(document.getElementById("ierapetra"),"click", function zoomtoIerapetra(){
			map.setCenter(new GLatLng(35.005541, 25.735613), 16);
		});
		
		GEvent.addDomListener(document.getElementById("malia"),"click", function zoomtoMalia(){
			map.setCenter(new GLatLng(35.283390, 25.460730), 16);
		});
		
		GEvent.addDomListener(document.getElementById("chersonissos"),"click", function zoomtochersonissos(){
			map.setCenter(new GLatLng(35.317002, 25.392875), 16);
		});
		
      }
    }
    //]]>