﻿var locations = "" ;
var optionsCountries = '';
var vrTextNeighbohoods = 'Neighbohoods';
var vrTextAllNeighbohoods = 'All Neighbohoods';
var vrTextHotels ='{0} Hotels';
try
{
    if (vrIdCulture == 1)
     {
         vrTextNeighbohoods = 'Áreas';
         vrTextAllNeighbohoods = 'Todas las Áreas';
         vrTextHotels ='Hoteles en {0}';
     }
}
  catch (e)
		         {
		         }

 var p=0;var Mapproperties=0;var MapDescriptions='';var Maplat=0;var Maplon=0;_Markers =new Array;var MapProperty=0;
     function createMarker(point,letter,prop,area) {
        
          var baseIcon = new GIcon(G_DEFAULT_ICON);
          var letter = "";//String.fromCharCode("A".charCodeAt(0) + letter);
          var letteredIcon = new GIcon(baseIcon);
          letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

          // Set up our GMarkerOptions object
          markerOptions = { icon:letteredIcon };
          
          var marker = new GMarker(point, letteredIcon);
          //marker.value = property.Id;
          
         GEvent.addListener(marker,"click", function() {;          
            map.openInfoWindowHtml(point, GetHtmlInfo(prop,area))
           
          });
          return marker;
        }
 function ShowArea(id)
 {
 initializeMap(id);
  optionsCountries = '<h3>' + vrTextNeighbohoods + '</h3><ul><li class=""last""><a  href="javascript:ShowArea(0)">' + vrTextAllNeighbohoods + '</a></li>';
  Maplat = 0;Maplon = 0;p=0;
  var strArea='';
  $.each(locations.area, function(i, itemCountry) {
     	        
	                optionsCountries += '<li><a href="javascript:ShowArea(' + itemCountry.value + ')">' + itemCountry.text  + '</a></li>';
	             
	                if (itemCountry.value==id || id ==0)
	                {
	                    if (id==0 && MapProperty==0){strArea =vrTextAllNeighbohoods;}else{strArea = itemCountry.text;
if(MapProperty>0){strArea ='';}
}
	                
	                $.each(itemCountry.city, function(j, itemCity) {
	                
	                         if (itemCity.latitude!='' && itemCity.longitude!='' && itemCity.latitude!=undefined && itemCity.longitude!=undefined)
				                {				
					                if (eval(itemCity.latitude)!=0 || eval(itemCity.longitude)!=0)
					                {
					                Maplat +=  parseFloat(itemCity.latitude);				
					                Maplon +=  parseFloat(itemCity.longitude);									             
					                var point = new GLatLng(itemCity.latitude,itemCity.longitude);								
					                var Mk=createMarker(point,p,itemCity,itemCountry.text);
					                _Markers[_Markers.length]= Mk;
					                map.addOverlay(Mk);		
									if(MapProperty!=0)map.openInfoWindow(point, GetHtmlInfo(itemCity,itemCountry.text));									
					                p = p+1;
            				
									//map.openInfoWindow(map.getCenter(),marker);
							
					                }
            			
		                        }			
	                });
	            }
	                
	        });
			optionsCountries += "</ul>";
	        if (p>0) {$("div#AreasInfo").html(optionsCountries);}
	        if (p>0 && MapProperty==0) $("h1#MapTitle").html(vrTextHotels.replace('{0}',strArea));
	        if(p==0){ document.getElementById("MapContainer").style.display='none';}
	        	try
		        {				
	                    if (p!=0)
		                    {
		                        Maplat = Maplat/p;Maplon = Maplon/p;
		                    }
		                 else
		                    {
		                      Maplat = '19.40598888';Maplon = '-99.11926657';
		                    }
					 if (MapProperty==0){
					        map.setCenter(new GLatLng(Maplat,Maplon,5));}
						else{map.setCenter(new GLatLng(Maplat,Maplon,5));}
        				
		        }
		        catch (e)
		         {
		         }
	     
 }
$(document).ready(function() {	
	  	    //initializeMap();
	  	    var query='';
	  	    try{query='?Property=' + vrIdProperty;MapProperty=vrIdProperty;}catch(e){query='';MapProperty=0;}
	  	   
	        $.getJSON(VarUrlSite+"GetHotels.aspx" + query, function(data) {
	        locations = data;
	        //var locationsaux = data;
	       // var optionsCountries = '';
	        ShowArea(0)
	       /* $.each(locations.area, function(i, itemCountry) {
	                optionsCountries += '<a href="javascript:ShowArea(' + itemCountry.value + ')">' + itemCountry.text  + '</a><br/>';
	                
	                $.each(itemCountry.city, function(j, itemCity) {
	                         if (itemCity.latitude!='' && itemCity.longitude!='' && itemCity.latitude!=undefined && itemCity.longitude!=undefined)
				                {				
					                if (eval(itemCity.latitude)!=0 || eval(itemCity.longitude)!=0)
					                {
					                Maplat +=  parseFloat(itemCity.latitude);				
					                Maplon +=  parseFloat(itemCity.longitude);									             
					                var point = new GLatLng(itemCity.latitude,itemCity.longitude);								
					                var Mk=createMarker(point,p,itemCity);
					                _Markers[_Markers.length]= Mk;
					                map.addOverlay(Mk);					    
					                p = p+1;
            				
					                }
            			
		                        }			
	                });
	            
	                
	        });
	        
	        $("div#AreasInfo").html(optionsCountries);
	        
	        	try
		        {				
	                    if (p!=0)
		                    {
		                        Maplat = Maplat/p;Maplon = Maplon/p;
		                    }
		                 else
		                    {
		                      Maplat = '19.40598888';Maplon = '-99.11926657';
		                    }
					        map.setCenter(new GLatLng(Maplat,Maplon,5));					
        				
		        }
		        catch (e)
		         {
		         }*/
	        
	    });
	    
	});

  

function initializeMap(id) {	
   
	
	var points= new GLatLngBounds();
    if (GBrowserIsCompatible()) {   
       if (MapProperty==0)
{
       map = new GMap2(document.getElementById("MapContainer"),{ 
                        size: new GSize(600,600) } );}
else
{     map = new GMap2(document.getElementById("MapContainer"),{ 
                        size: new GSize(600,500) } );}
	if (MapProperty!=0){
            map.setCenter(new GLatLng(37.4419, -122.1419), 15);}
        else{
            map.setCenter(new GLatLng(37.4419, -122.1419), 11);
        }
        
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());      
       
         	
        
      }
	  
	  
}



function GetHtmlInfo(property,area)
{
  var myHtml = "<b><a href='" + property.UrlOverview + "'>" + property.text + "</a></b>" + "<br/>" + property.Address + "<br/>";// + area + ", " + property.City; 
                   /*if (property.StateCode && property.StateCode!='') myHtml += ", " + property.StateCode;
                   if (property.CountryCode && property.CountryCode!='' ) myHtml += ", " + property.CountryCode;*/
  return myHtml;
}


 


