(function() {
	PorArriba.SucursalesMapManager = function( _map ) {
		this.map = _map;
		
		this.sucursales = [];
		this.lastSucursalOpen = null;
		 
		this.drawSucursal = function (id, latitude, longitude, description, iconPath) {
			var point = new GLatLng(latitude, longitude);
			//var marker = new GMarker(point);
			if(iconPath != null && iconPath != ""){
				iconPath = "files/paMarker.png";;
			} 
			
			var icon = new GIcon();
			icon.image = iconPath;
			icon.iconSize = new GSize(20, 39);
			icon.iconAnchor = new GPoint(11, 41);
			icon.infoWindowAnchor = new GPoint(15, 0);
			var marker = new GMarker(point, icon);
			
			marker.id = id;
			marker.comDescription = description;
			this.map.addOverlay(marker);
			GEvent.addListener(marker, "click", 
				function() {
					marker.openInfoWindow(description, {maxWidth:550, maxHeight:380, autoScroll:true});
				}
			);
			this.sucursales.push(marker);
		}

		this.deleteSucursales = function (){
			this.map.closeInfoWindow();
			for(var i=0; i<this.sucursales.length; i++) {
				this.map.removeOverlay(this.sucursales[i]);
			}
			this.sucursales = [];
		}

		this.panToComercio = function(id, latitude, longitude){
			this.map.panTo(new GLatLng(latitude, longitude));
			for(var i=0; i<this.sucursales.length; i++) {
				if(this.sucursales[i].id == id){
					this.sucursales[i].openInfoWindow(this.sucursales[i].comDescription, {maxWidth:550, maxHeight:380, autoScroll:true});
					this.lastSucursalOpen = this.sucursales[i];
				} 
			}
		}
	}
})();

fileLoaded("SucursalesMapManager.js");

