/**
 Script para el manejo de Mapas.
 Depende del script de Google Maps
 
 Autor: Víctor Corrales <vcorrales@farmatodo.com.ve>

*/

var nivel=10;
var incremento=40;
var minNivel=10;
var maxNivel=90;

var mapa = "/farmacias/images/mapas/Croquis_";
var sufijo = new Array();
var controles = new Array();
var zoomMapaSat = new Array();

var longitud="-66.863593";
var latitud="10.435672";
var satMode = false;
var map = null;
var inicializadoGMap = false;


sufijo[10] = "_Z3";
sufijo[50] = "_Z2";
sufijo[90] = "_Z1";

zoomMapaSat[10] = 17;
zoomMapaSat[50] = 15;
zoomMapaSat[90] = 14;

function dibujarNivel() {
   	controles[10] = document.getElementById("ct10"); 
   	controles[50] = document.getElementById("ct50");
   	controles[90] = document.getElementById("ct90");
    
   	var ruta= mapa+sufijo[nivel]+'.gif';
   	document["farmacroquis"].src=ruta;
   	
   	if (satMode) {
   		map.checkResize();
	   	var FTDGPS = new GLatLng(latitud,longitud);
	   	map.setCenter(FTDGPS);
        map.setMapType(G_SATELLITE_MAP); 	   	
	   	map.setZoom(zoomMapaSat[nivel]);
	   	agregarLogoFTD();
    }
}

function agregarLogoFTD() {
	var icon = new GIcon(); 
	icon.image = "http://www.farmatodo.com.ve/img/farmatodo.png"; 
	icon.iconSize = new GSize(32, 32); 
	icon.iconAnchor = new GPoint(16, 16);
		
	var coorTienda = new GLatLng(latitud,longitud);			
			
	var marker = new GMarker(coorTienda,icon);        
	map.addOverlay(marker);
	
}

function farmaZoomin() {
    nivel = nivel - incremento;
    if (nivel < 0 ) {
       nivel=minNivel;
    }
    dibujarNivel();
}

function farmaZoom(proximo) {
	nivel = proximo;
	dibujarNivel();
}

function farmaZoomOut() {
	nivel = nivel + incremento;
	if (nivel > maxNivel) {
		nivel = maxNivel;
 	}
 	
 	dibujarNivel();
}

function farmaSwithMode() {
	var mapa = document.getElementById("map");
   	var croquis = document.getElementById("croquis");
   	var ctlSat = document.getElementById("modsat");
   	var ctlCro = document.getElementById("modcro");

   	if (satMode) { // Activamos el Croquis y el control para cambiar a Satelite
   		satMode = false;
		mapa.setAttribute("class", "invisible");
		mapa.setAttribute("className", "invisible"); 
		ctlSat.setAttribute("class", "visible");
		ctlSat.setAttribute("className", "visible"); 
		croquis.setAttribute("class", "visible");
		croquis.setAttribute("className", "visible"); 
		ctlCro.setAttribute("class", "invisible");
		ctlCro.setAttribute("className", "invisible"); 

   	} else { // Activamos el Satelite y el control para cambiar a Croquis
   		satMode = true;
		mapa.setAttribute("class", "visible");
		mapa.setAttribute("className", "visible");
		ctlSat.setAttribute("class", "invisible");
		ctlSat.setAttribute("className", "invisible"); 
		croquis.setAttribute("class", "invisible");
		croquis.setAttribute("className", "invisible"); 
		ctlCro.setAttribute("class", "visible");
		ctlCro.setAttribute("className", "visible"); 

		
		map.disableDoubleClickZoom();
		map.disableDragging();
	   	map.setCenter(new GLatLng(latitud,longitud));
	   	
	}
	   
   	dibujarNivel();
}

function inicializar(tienda,lo,la) {
		mapa = mapa + tienda;
		longitud = lo;
		latitud = la;
}
	
function load() {
    var ctlSat = document.getElementById("modsat");

	if (GBrowserIsCompatible()) {
		ctlSat.setAttribute("class", "visible");
		ctlSat.setAttribute("className", "visible");

		var divmap = document.getElementById("map");
		divmap.style.height = "210px";
    	divmap.style.width = "380px";

		map = new GMap2(divmap);
		
	} else {
		ctlSat.setAttribute("class", "invisible");
		ctlSat.setAttribute("className", "invisible"); 
	}
}     