var baseIco = new GIcon();
	baseIco.iconSize = new GSize(25, 31);
	baseIco.iconAnchor = new GPoint(13, 31);
	baseIco.shadow = "/_ico/gmico_Shdw.png";
	baseIco.shadowSize = new GSize(41, 31);
	baseIco.transparent = "/_ico/gmico_Transp.png";
	baseIco.infoWindowAnchor = new GPoint(10, 33);
	baseIco.infoShadowAnchor = new GPoint(18, 25);
	
var icoBeach = new GIcon(baseIco);
	icoBeach.image = "/_ico/gmico-beach.png";
	icoBeach.printImage = "/_ico/gmico-beachP.gif";
	icoBeach.mozPrintImage = "/_ico/gmico-beachPmoz.gif";

var icoGolf = new GIcon(baseIco);
	icoGolf.image = "/_ico/gmico-golf.png";
	icoGolf.printImage = "/_ico/gmico-golfP.gif";
	icoGolf.mozPrintImage = "/_ico/gmico-golfPmoz.gif";

var icoHotel = new GIcon(baseIco);
	icoHotel.image = "/_ico/gmico-hotel.png";
	icoHotel.printImage = "/_ico/gmico-hotelP.gif";
	icoHotel.mozPrintImage = "/_ico/gmico-hotelPmoz.gif";
	
var icoPousada = new GIcon(baseIco);
	icoPousada.image = "/_ico/gmico-pousada.png";
	icoPousada.printImage = "/_ico/gmico-pousadaP.gif";
	icoPousada.mozPrintImage = "/_ico/gmico-pousadaPmoz.gif";

var icoRealestate = new GIcon(baseIco);
	icoRealestate.image = "/_ico/gmico-realestate.png";
	icoRealestate.printImage = "/_ico/gmico-realestateP.gif";
	icoRealestate.mozPrintImage = "/_ico/gmico-realestatePmoz.gif";

var icoTrain = new GIcon(baseIco);
	icoTrain.image = "/_ico/gmico-train.png";
	icoTrain.printImage = "/_ico/gmico-trainP.gif";
	icoTrain.mozPrintImage = "/_ico/gmico-trainPmoz.gif";

var icoShopping = new GIcon(baseIco);
	icoShopping.image = "/_ico/gmico-supermarket.png";
	icoShopping.printImage = "/_ico/gmico-supermarketP.gif";
	icoShopping.mozPrintImage = "/_ico/gmico-supermarketPmoz.gif";

var icoShopping = new GIcon(baseIco);
	icoShopping.image = "/_ico/gmico-market.png";
	icoShopping.printImage = "/_ico/gmico-marketP.gif";
	icoShopping.mozPrintImage = "/_ico/gmico-marketPmoz.gif";

var icoSightseeing = new GIcon(baseIco);
	icoSightseeing.image = "/_ico/gmico-sightseeing.png";
	icoSightseeing.printImage = "/_ico/gmico-sightseeingP.gif";
	icoSightseeing.mozPrintImage = "/_ico/gmico-sightseeingPmoz.gif";

var icoVisit = new GIcon(baseIco);
	icoVisit.image = "/_ico/gmico-visit.png";
	icoVisit.printImage = "/_ico/gmico-visitP.gif";
	icoVisit.mozPrintImage = "/_ico/gmico-visitPmoz.gif";

var ownerIco = new GIcon();
	ownerIco.image = "/_ico/gmico-1x1.png";
	ownerIco.iconSize = new GSize(1, 1);
	ownerIco.iconAnchor = new GPoint(1, 1);
	ownerIco.infoWindowAnchor = new GPoint(1, 1);
	ownerIco.infoShadowAnchor = new GPoint(1, 1);
	
var gicons = {	
	beach: icoBeach
	, golf: icoGolf
	, hotel: icoHotel
	, pousada: icoPousada
	, realestate: icoRealestate
	, shopping: icoShopping
	, train: icoTrain
	, sightseeing: icoSightseeing
	, visit: icoVisit
}
var gmarkers = [];

var gmsidebarHtmlRegions = "";

function jumpToMap() {
	 window.location = String(window.location).replace(/\#.*$/, "") + "#ggmap";
}
function myclick(label) {
	GEvent.trigger(gmarkers[label], "click");
	jumpToMap();
}
function myclickLocate(label, category) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].label == label && gmarkers[i].icontype == category) {
			GEvent.trigger(gmarkers[i], "click");
		}
	}
	show(category);
	jumpToMap();
}

function show(category) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].icontype == category) {
			gmarkers[i].show();
		}
	}
	document.getElementById(category+"box").checked = true;
	makeSidebar();
}
function hide(category) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].icontype == category) {
			gmarkers[i].hide();
		}
	}
	document.getElementById(category+"box").checked = false;
	makeSidebar();
	// NEED TO BE FIXED !
			//alert("i am closeInfoWindow");
	//var mymap = document.getElementById("map"); // == close the info window, in case its open on a marker that we just hid
	//mymap.closeInfoWindow();	
}

function boxclick(box,category) {
	if (box.checked) {
		show(category);
	} else {
		hide(category);
	}
}
function makeSidebar() {
	var html = "";
	var runningCath = "";
	for (var i=0; i<gmarkers.length; i++) {
		if (!gmarkers[i].isHidden()) {
			if (runningCath != gmarkers[i].icontype) {
				runningCath = gmarkers[i].icontype;
				html += '<br /><b>' + gmarkers[i].displayCath + '</b><br />';
			}
			html += '&nbsp;<a href="javascript:myclick(' + i + ')">' + gmarkers[i].label + '</a><br />';
		}
	}
	document.getElementById("gmsidebar").innerHTML = html;
//alert(html);
}

function createIcoMarker(point, label, html, url, icontype, displayCath, lang) {
	var marker = new GMarker(point, gicons[icontype]);
		marker.icontype = icontype;                                 
		marker.label = label;
		marker.displayCath = displayCath;
	if (url != "#") {
		if (lang == "pt") {
			html += "<br />- <a href='"; 
			html +=  url;
			html += "'>Ver nesta janela</a><br />- <a href='"
			html +=  url;
			html += "' target='_blank'>Ver numa janela separada</a>";
		} else if (lang == "fr") { 
			html += "<br />- <a href='"; 
			html +=  url;
			html += "'>Voir dans cette fen&ecirc;tre</a><br />- <a href='"
			html +=  url;
			html += "' target='_blank'>Voir dans une fen&ecirc;tre s&eacute;par&eacute;e</a>";
		} else {
			html += "<br />- <a href='"; 
			html +=  url;
			html += "'>See in this window</a><br />- <a href='"
			html +=  url;
			html += "' target='_blank'>See in a separate window</a>";
		}
	}
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	gmarkers.push(marker);
	return marker;
}
function drawCategory (url, displayCath, category, map, lang, onoff) {
//alert("displayCath:" + displayCath + " category:" + category + " onoff:" + onoff + " url:" + url);
	GDownloadUrl(url, function(data, responseCode) {
		var xmlDoc = GXml.parse(data);
		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
		
//				if (displayCath="sightseeing") {
//					alert("markers.length:" + markers.length + " mresponseCode:" + responseCode );							
//				}								

		
//alert("markers.length:" + markers.length + " mresponseCode:" + responseCode );
		for (var i = 0; i < markers.length; i++) {
			var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
			var html = GXml.value(markers[i].getElementsByTagName("html-" + lang)[0]);
			var url = markers[i].getAttribute("url-"+lang);
			var label = markers[i].getAttribute("label");
			
				if ( undefined != markers[i].getAttribute("label-"+lang) ) {
					if (typeof markers[i].getAttribute("label-"+lang) != null) {label = markers[i].getAttribute("label-"+lang)}
				}
				
			var marker = createIcoMarker(point, label, html, url, category, displayCath, lang);
			map.addOverlay(marker);
//alert("label:" + label + " category:" + category + " onoff:" + onoff);
			if (onoff == "off") {
				marker.hide();
//			} else {
//				if (displayCath="sightseeing") {
//					alert("label:" + label + " category:" + category + " onoff:" + onoff);							
//				}								
			}
		}
		if (onoff == "off") {
			document.getElementById(category+"box").checked = false;
		} else {
			document.getElementById(category+"box").checked = true;
		}
		makeSidebar();
	});
}
