// global variables
var mapbounds = new GBounds(Number.MAX_VALUE, Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE); 
// Create our "tiny" marker icon 
var baseIcon = new GIcon();
baseIcon.image =  mygDefaultIconImage;
baseIcon.shadow = mygDefaultIconShadow;
baseIcon.iconSize = new GSize(12, 20);
baseIcon.shadowSize = new GSize(22, 20);
baseIcon.iconAnchor = new GPoint(6, 20);
baseIcon.infoWindowAnchor = new GPoint(5, 1);
baseIcon.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0]; 
//baseIcon.transparent = "mapIcons/mm_20_transparent.png";
var icons=[];

// Hide/Display Markers
function Markers(code){
	map.closeInfoWindow();
   	if (document.getElementById(code).checked==false) { 
		MarkersRemoveOverlay(code);
   	} else { 
		MarkersAddOverlay(code);
   	}
}

function MarkersRemoveOverlay(code) {
	for (var i=0;i<mymarkerset.length;i++) {
		if (mymarkerset[i].type==code)  {
       		map.removeOverlay(mymarkerset[i]);
    	}
   	}
}

function MarkersAddOverlay(code) {
	for (var i=0;i<mymarkerset.length;i++) {
   		if (mymarkerset[i].type==code)  {
       		map.addOverlay(mymarkerset[i]);
      	} 
 	}
}

/*
GMap.prototype.centerAndZoomOnBounds = function(mapbounds) {
   var span = new GSize(mapbounds.maxX - mapbounds.minX, mapbounds.maxY - mapbounds.minY);
   var center = new GPoint(mapbounds.minX + span.width / 2., mapbounds.minY + span.height / 2.);
   var newZoom = this.spec.getLowestZoomLevel(center, span, this.viewSize);
   if (this.getZoomLevel() != newZoom) {
       this.centerAndZoom(center, newZoom);
   } else {
       this.recenterOrPanToLatLng(center);
   }
}
GMap.prototype.centerAndZoomOnBounds = function(mapbounds) {
   var center_lat = (mapbounds.getNorthEast().lat() + mapbounds.getSouthWest().lat()) / 2.0;
   var center_lng = (mapbounds.getNorthEast().lng() + mapbounds.getSouthWest().lng()) / 2.0;
   var center = new GLatLng(center_lat,center_lng)
   map.setCenter(center, map.getBoundsZoomLevel(mapbounds));
}
*/

// Change this function to change icons from the simple colors
function getIcon(p_iconImage) {
   var iconImage;
   if ((typeof(p_iconImage)=="undefined") || (p_iconImage==null) || p_iconImage=="") { 
      iconImage= mygDefaultIconImage;
   } else { 
      iconImage = p_iconImage; 
   }
   if (!icons[p_iconImage]) {
      var icon = new GIcon(G_DEFAULT_ICON);
      // icon.image = iconImage;
      //icon.printImage = iconImage;
      //icon.mozPrintImage = iconImage;
      //icon.printShadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; 
      //icons[p_iconImage]=icon;
      
      icon.image = iconImage;
      icon.printImage = iconImage;
      icon.mozPrintImage = iconImage;
      icon.shadow=  mygDefaultIconShadow;
      icon.printShadow=  mygDefaultIconPrintShadow;
      icons[p_iconImage]=icon;


   } 
   return icons[p_iconImage];
}
	

// Initialize Marker
function initMarker(lng, lat, title, data, code,id) {
   var point = new GPoint(lng, lat);
   
	if (arrGroups[code] ==null||arrGroups[code]=="undefined") {
		alert ("Warning! no definition for '"+code+"' in config.xml file");
	} else {
   		var icon = getIcon(arrGroups[code]['imgsrc']);
   		var marker = new GMarker(point, icon);
	}
   marker.type = code; 
   marker.title= title; 
   marker.id= id; 

   GEvent.addListener(marker, "click", function () {
		if (booMeasure) {
			//lHtml=data+'<center><a href="#" class="linkstyle12" onclick="mt.addRow(\''+title+'\',\''+id+'\',\'measure\');imt.addRow(\'itin\',\''+id+'\',\'imeasure\');">Add to my trip</a></center>';
			lHtml=data+'<center><a href="#" class="linkstyle12" onclick="mt.addRow(\'attraction\',\''+id+'\',\'measure\');imt.addRow(\'itin\',\''+id+'\',\'imeasure\');">Add to my trip</a></center>';
		} else {
			lHtml=data;
		}
		if (code=="useradded" && gUserId !="guest") lHtml+='<br><center><a href="#" class="linkstyle12" onclick="deletePoint(\''+id+'\');">Delete</a></center>';
		marker.openInfoWindowHtml(lHtml);
   	});
	return marker;
}


