﻿//<![CDATA[
        var map = null;      
        var bounds = null;
		var marker = null;
        var zoom = null;
        var newCenter = null;        
        var baseIcon = new GIcon();
        baseIcon.iconSize = new GSize(44, 41);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
       // Re-Zooms and Centers to include all the markers
	   	function inicio_map(){
			GEvent.trigger(marker, "click"); // iniciar info box
			}
        function zoomIt(){
				
                zoom = map.getBoundsZoomLevel(bounds);
                newCenter = bounds.getCenter();	
                map.setCenter(newCenter,zoom);
				
				
        }
        function createTabbedMarker(point, windowtext1, windowtext2, windowtext3, label1, label2, label3) {
            var icon = new GIcon(baseIcon);
            icon.image = "../scripts/gmap/googleIcon1.png";
            marker = new GMarker(point, icon);
			var myWidth = map.getSize().width/2;
			if (myWidth<290){
				myWidth == 290;
			}
			
            GEvent.addListener(marker, "click", function() {	
				var tabs = [new GInfoWindowTab(label1,windowtext1), new GInfoWindowTab(label2,windowtext2), new GInfoWindowTab(label3,windowtext3)];
				marker.openInfoWindowTabsHtml(tabs,{maxWidth:myWidth});
				
             });

            bounds.extend(point);
            return marker;
			
			
			
        } 
		
        function showAddress(address, windowtext1, windowtext2, windowtext3, label1, label2, label3, altadress) {
            geocoder.getLatLng(
              address,
              function(point) {
                if (point) {
					map.setCenter(point, 6);
                    map.addOverlay(createTabbedMarker(point, windowtext1, windowtext2, windowtext3, label1, label2, label3));
                    zoomIt();
					
                }else{
			  	 geocoder.getLatLng(
              altadress,
              function(point) {
                if (point) {
					map.setCenter(point, 6);
                    map.addOverlay(createTabbedMarker(point, windowtext1, windowtext2, windowtext3, label1, label2, label3));
                    zoomIt();
					
                }
              });
			  /**/
				}
              }
			
            );
          }
        function load(zipcode,content1,content2,content3,titulo1,titulo2,titulo3,concelho) {
          if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("content"));
           // map.addControl(new GSmallMapControl());
            map.setCenter(new GLatLng(0, 0), 6);
			
			var customUI = map.getDefaultUI();
        	customUI.controls.scalecontrol = false;
			map.setUI(customUI);
			//map.addMapType(G_PHYSICAL_MAP); 
			//map.addControl(new GMapTypeControl());
			//map.addControl(new GLargeMapControl());
			
			
            geocoder = new GClientGeocoder();
            bounds = new GLatLngBounds();
			
			showAddress(zipcode,content1,content2,content3,titulo1,titulo2,titulo3,concelho);
			
            zoomIt();    
          }
        }
		


///// MAPA DE PESQUISA

//<![CDATA[

    var map2 = null;
    var geocoder2 = null;
	 var baseIcon2 = new GIcon();
        baseIcon2.iconSize = new GSize(30, 30);
        baseIcon2.iconAnchor = new GPoint(9, 34);
        baseIcon2.infoWindowAnchor = new GPoint(9, 0);
        baseIcon2.infoShadowAnchor = new GPoint(18, 25);

    function load_searchmap() {
      if (GBrowserIsCompatible()) {
        map2 = new GMap2(document.getElementById("map"));
		//map2.addControl(new GLargeMapControl3D());
		var customUI = map2.getDefaultUI();
        customUI.controls.scalecontrol = false;
        map2.setUI(customUI);
		//map2.addControl(new GSmallMapControl());
		//map.addControl(new GMapTypeControl());
        map2.setCenter(new GLatLng(39.6995706, -8.7281443), 6);
        geocoder2 = new GClientGeocoder();
      }

		  
	  
    }
	
    function showAddress_2(address,id_address,link_list) {
	 //alert("teste")
      if (geocoder2) {
        geocoder2.getLatLng(
          address,
          function(point2) {
            if (!point2) {
              alert(address + " not found");
            } else {
				 //map.setCenter(point, 6);
				 //alert(point)
				var icon2 = new GIcon(baseIcon2);
            	icon2.image = "../scripts/gmap/icon.png";
				var marker2 = new GMarker(point2, icon2);
				
				map2.addOverlay(marker2);
				//marker.openInfoWindowHtml(address);
				//alert(id_address);
				var windowtext1 = "<iframe id='ngh_list' name='ngh_list' style='border:none; margin:14px 0 10px -10' height='120px' width='230px' frameborder='0' src='gmap/info.htm?twn="+id_address+"' ></iframe><br /><span class='btn_map_right float_right'><a onClick='set_right();' title='Seguinte'></a></span><span class='btn_map_left float_right'><a onClick='set_left();' title='Anterior'></a></span><br /><br /><br />";
				var windowtext2 = "<iframe id='imo_list' name='imo_list' style='border:none; margin:14px 0 10px -10' height='120px' width='230px' frameborder='0' src='gmap/imoveis.htm?twn="+id_address+"' ></iframe>";
				var label1 = "Info";
				var label2 = "Imóveis";
				
				var myWidth = 180;
				
				/*
				var myWidth = map.getSize().width/2;
				if (myWidth<290){
				myWidth == 290;
				}
				*/
				
				GEvent.addListener(marker2, "click", function() {	
				var tabs2 = [new GInfoWindowTab(label1,windowtext1), new GInfoWindowTab(label2,windowtext2)];
				marker2.openInfoWindowTabsHtml(tabs2,{maxWidth:myWidth});
				
             });
			 if(link_list == "on"){
			 GEvent.trigger(marker2, "click");
			 }
			
            }
          }
        );
      }
    }
	

    //]]>
		