// JavaScript Document
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "http://venice.justaguide.com/img/markers/shadow.png";
baseIcon.image = "http://venice.justaguide.com/img/markers/marker.png";
baseIcon.iconSize = new GSize(21, 35);
baseIcon.shadowSize = new GSize(35, 28);
baseIcon.iconAnchor = new GPoint(11, 35);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

//mapIcon = new GIcon(GIcon, 'img/catMarkers/1.png');

// Creates a marker whose info window displays the letter corresponding
    // to the given index.
function createMarker(map, point, id, title, html, placeType) {
	var markerOptions = { icon:baseIcon };
	var marker = new GMarker(point, markerOptions);
	var tooltip = new Tooltip(marker, title,4); 
	marker.tooltip = tooltip;
	if(placeType){
		marker.getIcon().image = "http://venice.justaguide.com/img/markers/marker_" + placeType + ".png";
	}
	GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(html);});
	GEvent.addListener(marker,'mouseover',function(){ this.tooltip.show(); }); 
	GEvent.addListener(marker,'mouseout',function(){ this.tooltip.hide(); });
	map.addOverlay(marker); 
	map.addOverlay(tooltip);
	return marker;
}


function createInfoWinHTML(ext_id, name, desc, imagePath){
	var html = '<div class="jag_infoWindow">';
	if(imagePath){
		html += '<div class="thumb"><img src="photos/thumbs/' + imagePath +'" alt="Icon ' + name +'"/></div>';
	}
	html += '<div class="info"><h2>' + name + '</h2>';
	html += '<p>' + desc + '</p>';
	html += '<a href="place.php?place=' + ext_id + '">Dettagli</a></div></div>';
	return html;
}



/**
 * @author Marco Alionso Ramirez, marco@onemarco.com
 * @url http://onemarco.com
 * @version 1.0
 * This code is public domain
 */

/**
 * The Tooltip class is an addon designed for the Google Maps GMarker class. 
 * @constructor
 * @param {GMarker} marker
 * @param {String} text
 * @param {Number} padding
 */
function Tooltip(marker, text, padding){
	this.marker_ = marker;
	this.text_ = text;
	this.padding_ = padding;
}

Tooltip.prototype = new GOverlay();

Tooltip.prototype.initialize = function(map){
	var div = document.createElement("div");
	div.appendChild(document.createTextNode(this.text_));
	div.className = 'mapTooltip';
	div.style.position = 'absolute';
	div.style.visibility = 'hidden';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
}

Tooltip.prototype.remove = function(){
	this.div_.parentNode.removeChild(this.div_);
}

Tooltip.prototype.copy = function(){
	return new Tooltip(this.marker_,this.text_,this.padding_);
}

Tooltip.prototype.redraw = function(force){
	if (!force) return;
	var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	var iconAnchor = this.marker_.getIcon().iconAnchor;
	var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
	var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
	this.div_.style.top = yPos + 'px';
	this.div_.style.left = xPos + 'px';
}

Tooltip.prototype.show = function(){
	this.div_.style.visibility = 'visible';
}

Tooltip.prototype.hide = function(){
	this.div_.style.visibility = 'hidden';
}