function InfoWindowCreate(titolo, desc, url, img){
	var chtml = '<table class="blob" width="260" border="0" cellpadding=\"5\">';
	chtml += '<tr>';
		chtml += '<td style="text-align:center;color:black;font-weight:bold;font-size:11px;">' + titolo + '</td>';
		if(img!='')
			chtml += '<td rowspan="'+ ((desc!='')?'2':'1') +'" valign="top"><img src="' + img + '" alt="" width="100" height="100" border="0"></td>';
	chtml += '</tr>';
	if(desc!=''){
		chtml += '<tr>';
		chtml += '<td style="text-align:justify;color:black;">'+desc+'</td>';
		chtml += '</tr>';
	}
	if(url!='')
		chtml += '<tr><td colspan="'+ ((img!='')?'2':'1') +'"><a href="' + url + '" target="_blank">' + url + '</a></td></tr>';
	chtml += '</table>';
	debug(chtml);
	return chtml;
}



function MarkerAdd(mappa, index) {
	  // Create our "tiny" marker icon
	  var icon = new GIcon();
	  icon.image = APP_PATH + gg_locations_icons[gg_locations[index].loctype];
	  icon.iconSize = new GSize(20, 20);
	  icon.iconAnchor = new GPoint(6, 20);
	  icon.infoWindowAnchor = new GPoint(5, 1);
	  var point = new GLatLng(gg_locations[index].lat, gg_locations[index].lng);
	  var marker = new GMarker(point, icon);
	  var LMarkers = document.getElementById("mapMarkers");
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(InfoWindowCreate(gg_locations[index].titolo, gg_locations[index].desc, gg_locations[index].url, gg_locations[index].img));
	  });		
		mappa.addOverlay(marker);
		//contentTitolo
		document.getElementById("contentTitolo"+gg_locations[index].loctype).innerHTML += "<div onclick=\"selectMarker(this, '"+index+"')\" title=\""+gg_locations[index].desc+"\" style=\"padding-left:15px;font-family:verdana;width:180px;height:16;cursor:pointer;overflow:hidden;font-size:12px;\"><img src=\"commonimages/joinbottom.gif\" align=\"absmiddle\">"+gg_locations[index].titolo+"</div>";
}

var lastMarkSel = null;

function selectMarker(layer, index){
	if(lastMarkSel!=null)
		lastMarkSel.style.backgroundColor='transparent';
	if(layer!=null){
		layer.style.backgroundColor='#FFcc33';
		lastMarkSel = layer;
		map.setCenter(new GLatLng(gg_locations[index].lat , gg_locations[index].lng), parseInt(gg_locations[index].zoom));
		map.openInfoWindowHtml(map.getCenter(),InfoWindowCreate(gg_locations[index].titolo, gg_locations[index].desc, gg_locations[index].url, gg_locations[index].img));
	}
}

function MRKmodifica(mID){
	location = "MRK-edit.php?idMRK=" + mID;
}
function MRKelimina(mID){
	LEdit.location = "MRK-drop.php?idMRK=" + mID;
	document.getElementById("LDivEdit").style.visibility = 'visible'
}
        
function loadMarkers(){
	 for(var k=0;k<gg_locations.length;k++)
		MarkerAdd(map, k);
}

function expandContractLayer(layer, img){
	var currLayer = document.getElementById(layer);
	var currLayer_closer = document.getElementById(layer + "_closer");	
	var currImg = document.getElementById(img);
	
	if(currLayer.style.display == 'none'){
		currLayer_closer.style.display = 'block'
		currLayer.style.display = 'block'
		currImg.src="commonimages/minus.gif"
	}else{
		currLayer_closer.style.display = 'none'
		currLayer.style.display = 'none'
		currImg.src="commonimages/plus.gif"
	}
}


function bringInterfaceToCenter(divlayer){
    var obj_divInterface        =  document.getElementById(divlayer);
    obj_divInterface.style.left = (document.body.clientWidth / 2) - (obj_divInterface.clientWidth / 2);
}

function load(){
	  map = new GMap2(document.getElementById("map"));
      if (GBrowserIsCompatible()) {
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
       if(gg_locations.length>0)
			map.setCenter(new GLatLng(gg_locations[0].lat, gg_locations[0].lng), parseInt(gg_locations[0].zoom));
		else
			map.setCenter(new GLatLng(45.85558643964395, 9.3548583984375), 13);
		setTimeout("loadMarkers(map)",1000)
      }
	  bringInterfaceToCenter('main_layer');
}