﻿	var geocoder = null;
	var map = null;
	var oficina;
	var hotel = null;
	
	var icon = new GIcon();
	icon.image = "img/icono2_googlemaps.png";
	icon.shadow = "img/shadow2_googlemaps.png";
	icon.iconSize = new GSize(55, 54);
	icon.shadowSize = new GSize(55, 54);
	icon.iconAnchor = new GPoint(18, 54);
	icon.infoWindowAnchor = new GPoint(18, 0);

	function Counter() {
		this.c = 1;
		this.get = function () {
			return this.c++;	
		}	
	}

	var q = new Counter();
	
	function out(s) {
		$('log').innerHTML += s + "<br/>";	
	}

	function Marker() {
		this.map = map;
		this.id = q.get();
		this.info = "";
		this.name = "";
		this.marker = "";
		
		this.hola = function () {
			out("soy marker " + this.id);	
		}
		
		this.infoWin = function () {
				this.marker.openInfoWindowHtml(this.info);
		}
		
		this.attach = function( aPoint, principal ) {
			var aMarker = new GMarker ( aPoint, (principal ? icon : icon), false );
			this.marker = aMarker;
			GEvent.addListener(aMarker, "click", this.infoWin.bind(this) );
			map.addOverlay( aMarker );
			if (principal)
				this.infoWin();
		}
		
		this.setGooglePos = function( anAddress, principal ) {
			geocoder.getLatLng( anAddress, this.attach.bind(this) );
		}
		 
		this.setInfo = function( name, direccion  ) {
			this.info = "<div>";
			this.info += "<h6>" + name + " ";
			this.info += "</h6>";
			this.info += direccion + "<br/>";
			this.info += "</div>";
			this.name = name;
		}
		
		this.setCoords = function ( aLat, aLng, principal ) {
			var aPoint = new GLatLng ( aLat, aLng );
			this.attach( aPoint, principal );
		}

	}
	
    function ponMapa() {

				var onmap = 0;
				
				active = -1;
				
				map.addControl(new GSmallMapControl()); 
				map.setCenter ( new GLatLng( "38.721722", "-9.217283"), 15  );
	    				
				    	var direccion = "Rua do Proletariado 1 <br> Quinta do Paizinho 2790 - 138 <br> Carnaxide, Portugal";
				    			
				  		var name = "WERFEN Group";

						oficina = new Marker();
	
						oficina.setInfo( name, direccion );
							    
						oficina.setCoords ( "38.721722", "-9.217283", true );
    }
    
    
    
    function mapaLoad( ) {

      if (GBrowserIsCompatible()) {

		map = new GMap2( $("mapa") );
    	geocoder = new GClientGeocoder();
       	ponMapa();  
      }

    }
    
    function mapaLoadPrint ( ) {
    	if (Prototype.K(true))
    		mapaLoad();
    	else
			window.setTimeout('mapaLoadPrint()', 1000);

    }
    
    function myUnload() {
    	GUnload();
    }
    
    
