﻿// JavaScript Document
/*
	JavaScript by Lazo Lazarev a.k.a. Lazarius Borg @ zerogravity
	July 2006, Skopje, Macedonia
	Google Maps APIs are used for Alexandria IT Academy
 */
//<![CDATA[
function InfoDisplay(argLatLng, argText, argImgUrl) {
	this.latLng = argLatLng;
	this.text = argText;
	this.imgUrl = argImgUrl;
}
InfoDisplay.prototype = new GOverlay();
InfoDisplay.prototype.initialize = function(map) {
	
	var div = document.createElement("div");
	div.style.position = "absolute";
	div.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
	div.style.fontSize = "11px";
	// div.style.width = "250px";
	// div.style.backgroundColor = "#ffffcc";
	// div.style.border = "1px solid #ffffff";
	div.style.padding = "3px";


	if (this.imgUrl != null && this.imgUrl != "") {
		var imgEL = new Image();
		imgEL.src = this.imgUrl;
		div.appendChild(imgEL);
	}
	
	div.appendChild(document.createElement("br"));
	
	if (this.text != null && this.text !="") {
		var textNode = document.createTextNode(this.text);
		div.appendChild(textNode);
	}

	map.getPane(G_MAP_MARKER_PANE).appendChild(div);
	
	this.map_ = map;
	this.div_ = div;
}
InfoDisplay.prototype.remove = function() {
	this.div_.parentNode.removeChild(this.div_);
}
InfoDisplay.prototype.copy = function() {
	return new InfoDisplay(this.latLng, this.text, this.imgUrl);
}
InfoDisplay.prototype.redraw = function(force) {
	if (!force) return;
	
	var point = this.map_.fromLatLngToDivPixel(this.latLng);
	
	this.div_.style.left = (point.x + 20) + "px";
	this.div_.style.top = (point.y - 35) + "px";
}
		   
var map, markerData;
markerData = [
	[{}, 41.99667737876342, 21.407235860824585, "", "imgs/logo_alexandria.gif"],
	[{}, 41.99658, 21.40634536743164, "", "imgs/logo_tinex.gif"],
	[{}, 41.996800967820604, 21.404950618743896, "", "imgs/logo_vero.gif"],
	[{}, 41.99662555102285, 21.405487060546875, "", "imgs/logo_McDonalds.gif"],
	[{}, 41.99555709281329, 21.41132354736328, "", "imgs/logo_blue_cafe.gif"],
	[{}, 41.99547735640674, 21.412975788116455, "", "imgs/logo_treska.gif"],
	[{}, 41.99887403880725, 21.412460803985596, "", "imgs/logo_simpo.gif"]
];

function load() {

  if (GBrowserIsCompatible()) {
	  
	map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(41.99667737876342, 21.407235860824585), 18);
	map.addControl(new GSmallZoomControl());
	map.addControl(new GScaleControl());
	map.setMapType(G_HYBRID_MAP);

	for (var i = 0; i < markerData.length; i++) {
		markerData[i][0] = createMarker(markerData[i][1], markerData[i][2], markerData[i][3], markerData[i][4]);
		map.addOverlay(markerData[i][0]);
	}


	GEvent.addListener(map, "zoomend", function(oldLevel, newLevel) {

		if (oldLevel == 14 && newLevel == 15) {
			for (var i = 1; i < markerData.length; i++) {
				map.addOverlay(markerData[i][0]);
			}
		} else if (oldLevel == 15 && newLevel == 14) {
			for (var i = 1; i < markerData.length; i++) {
				map.removeOverlay(markerData[i][0]);
			}
		}

	});
		
  }

}

function createMarker(lat, lng, text, url) {

	var marker = new GMarker(new GLatLng(lat, lng));
	var infoDisplay = new InfoDisplay(new GLatLng(lat, lng), text, url);

	GEvent.addListener(marker, "mouseover", function() {
													 
		map.addOverlay(infoDisplay);

	});

	GEvent.addListener(marker, "mouseout", function() {
		
		map.removeOverlay(infoDisplay);

	});

	return marker;

}

//]]>
