var map;
var overlay;

LightMapOverlay.prototype = new google.maps.OverlayView();

function mapa(lat,lng,zoom)
{
	
	var mapdiv = 'map_canvas';
	var latlng = new google.maps.LatLng(lat,lng); // nastavenie vycentrovania mapy pri nacitani
	var zoom = zoom; // nastavenie zoomu
	var typemap = google.maps.MapTypeId.HYBRID ; // nastavenie typu zobrazovanej mapy
	
	// vykreslenie mapy do div-u map_canvas
	var myOptions = {
		zoom: zoom,
		center: latlng,
		//panTo(48.641598:19.709415): void,
		mapTypeId: typemap
	};
	
	map = new google.maps.Map(document.getElementById(mapdiv), myOptions);
	
	vypis_atrakcii(locations); // funkcia na vypisanie lokalizacii

}






// funkcia na vypisanie lokalizacii zo suboru location.js
function vypis_atrakcii(locations)
{
	for (var i = 0; i < locations.length; i++) {
		var neBound = new google.maps.LatLng(locations[i][1], locations[i][2]);
		var swBound = new google.maps.LatLng(locations[i][1], locations[i][2]);
		var bounds = new google.maps.LatLngBounds(swBound, neBound);
		var h1 = locations[i][0];
		var text = locations[i][3];
		var pic = locations[i][4];
		var id = locations[i][5];
		new LightMapOverlay(bounds, h1, text, pic, id);
	}
}







// funkcie na zobrazovanie objektov div na mape
function LightMapOverlay(bounds, h1, text, pic, id)
{
	this.bounds_ = bounds;
	this.h1_ = h1;
	this.text_ = text;
	this.pic_ = pic;
	this.id_ = id;
	this.div_ = null;
	this.setMap(map);
}

LightMapOverlay.prototype.onAdd = function()
{
	var div = document.createElement('div');
	div.className = "mapbox";

	this.div_ = div;
	
	var panes = this.getPanes();
	// nastavenie, v ktorej vrstve sa ma zobrazovat nas layer
	// MapPanes.mapPane
	// MapPanes.overlayLayer
	// MapPanes.overlayShadow
	// MapPanes.overlayImage
	// MapPanes.floatShadow
	// MapPanes.overlayMouseTarget
	// MapPanes.floatPane
	panes.overlayImage.appendChild(div);
}

LightMapOverlay.prototype.draw = function()
{
	var overlayProjection = this.getProjection();
	
	var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest())
	var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast())
	
	var div = this.div_;
	div.style.left = sw.x + 'px';
	div.style.top = ne.y + 'px';
	
	this.div_.innerHTML = 
	'<div class="thumb" id="thumb'+ this.id_ +'">'+
	'	<img src="'+ this.pic_ +'">'+
	'</div>';
}

LightMapOverlay.prototype.onRemove = function()
{
	this.div_.parentNode.removeChild(this.div_);
	this.div_ = null;
}
