// Google Map - Search Results

    var map = null;

    var geocoder = null;

	var map_init = false;

	var currentMarker = null;

	var my_markers = new Array();
	
	var my_marker = null;



    function initialize(setCenter) {

      if (GBrowserIsCompatible() && (map_init == false)) {

        map = new GMap2(document.getElementById("gmap"));

        //map.setCenter(new GLatLng(40.7667, -73.2333), 9);

		map.setMapType(G_HYBRID_MAP);

        geocoder = new GClientGeocoder();

		map_init = true;

      }

    }



    function showAddress(address, town, ste, ml_num, img, lp_dol, bedrooms, bathrooms, sqft, details_link) {

	  if (geocoder) {

        geocoder.getLatLng(

          address,

          function(point) {

            if (!point) {

              alert(address + " not found");

			  map.setCenter(new GLatLng(40.7667, -73.2333), 9);

            } else {

              map.setCenter(point, 13);

			  map.addControl(new GSmallMapControl());

              map.addControl(new GMapTypeControl());

			  

			  var icon = new GIcon();

			  icon.image = "/images/search_results/red_egg.png";

			  icon.iconSize = new GSize(20, 25);

			  icon.iconAnchor = new GPoint(10, 25);

			  icon.infoWindowAnchor = new GPoint(10,12);

			  			  
			  var marker = new GMarker(point, icon);

			  GEvent.addListener(marker, "click", function() {

			  	//my_marker = marker;

			    var town_ste_row = ((town != '') && (ste != '')) ? ("<tr><td><span class=\"text_size_11\">" + town + ", " + ste + "</span></td></tr>") : ("<tr><td><span class=\"text_size_11\">" + town + ste + "</span></td></tr>");

				var price_row = ((lp_dol != '') && (lp_dol != '$ 0')) ? ("<tr><td><span class=\"text_size_11\">" + lp_dol + "</span></td></tr>") : '';

				var bedrooms_format = ((bedrooms != '') && (bedrooms > 0)) ? (bedrooms + " Bedrooms") : '';

		        var sqft_format = ((sqft != '') && (sqft > 0)) ? (sqft + " Sq. Ft.") : '';

		        var bedrooms_sqft_row = ((bedrooms_format != '') && (sqft_format != '')) ? ("<tr><td><span class=\"text_size_11\">" + bedrooms_format + ", " + sqft_format + "</span></td></tr>") : ("<tr><td><span class=\"text_size_11\">" + bedrooms_format + sqft_format + "</span></td></tr>");

		        var bathrooms_row = ((bathrooms != '') && (bathrooms > 0)) ? ("<tr><td><span class=\"text_size_11\">" + bathrooms + " Bathrooms</span></td></tr>") : '';

				var mls_log = (data_source == 'li') ? "<img src=\"/images/search_results/MLS_icon.gif\" width=\"55\" height=\"17\" />" : "<img src=\"/images/search_results/mls_logo_mht.gif\" width=\"55\" height=\"25\" />";

				

				var info_window_html = '';

				info_window_html += "<table id=\"gmiw\" width=\"369\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += "  <tr><td colspan=\"5\" width=\"369\" height=\"13\"></td></tr>";

				info_window_html += "  <tr>";

				info_window_html += "    <td width=\"13\">&nbsp;</td>";

				info_window_html += "    <td width=\"104\"><img src=\"" + img + "\" width=\"104\" height=\"68\" border=\"0\" onerror=\"imgNotAvailableSmall(this)\" onclick=\"show_property_details_layer('" + ml_num + "','" + data_source + "','')\" style=\"cursor:pointer\"/></td>";

				info_window_html += "    <td width=\"10\">&nbsp;</td>";

				info_window_html += "    <td width=\"233\">";

				info_window_html += "      <table width=\"233\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += town_ste_row;

				info_window_html += price_row;

				info_window_html += "        <tr><td><a href=\"javascript:show_property_details_layer('" + ml_num + "', '" + data_source + "','')\">PROPERTY DETAILS &gt;</a></td></tr>";

				info_window_html += bedrooms_sqft_row;

				info_window_html += bathrooms_row;

				info_window_html += "      </table>";

				info_window_html += "    </td>";

				info_window_html += "    <td width=\"9\"></td>";

				info_window_html += "  </tr>";

				info_window_html += "  <tr><td width=\"369\" height=\"8\" colspan=\"5\"></td></tr>";

				info_window_html += "  <tr>";

				info_window_html += "    <td width=\"369\" colspan=\"5\">";

				info_window_html += "      <table width=\"369\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += "        <tr>";

				info_window_html += "          <td width=\"13\"></td>";

				info_window_html += "          <td width=\"22\"><img id=\"gmiw_atmf_icon_" + ml_num + "\" src=\"/images/search_results/little_elephant_grey.gif\" width=\"18\" height=\"14\" /></td>";

				info_window_html += "          <td width=\"111\" id=\"gmiw_atmf_holder\"><div id=\"gmiw_atmf_error_holder_" + ml_num + "\" class=\"add_to_myfavs_error_holder\" onClick=\"$(this).hide();\"></div><a href=\"javascript:add_to_my_favs('" + data_source + "', '" + ml_num + "', 3);\" class=\"text_size_11\">add to my favorites</span></td>";

				info_window_html += "          <td width=\"23\"><a href=\"\"><img src=\"/images/search_results/little_square.gif\" width=\"16\" height=\"16\" border=\"0\" /></a></td>";

				info_window_html += "          <td width=\"117\" id=\"\"><a id=\"show_zoom_map\" href=\"javascript:map.setZoom(30);\">center and zoom on map</a></td>";

				info_window_html += "          <td width=\"83\">" + mls_log + "</td>";

				info_window_html += "        </tr>";

				info_window_html += "      </table>";

				info_window_html += "    </td>";

				info_window_html += "  </tr>";

				info_window_html += "</table>";

				

				marker.openInfoWindowHtml(info_window_html);

				

				request_fav_property_registered(get_ulrp_usrlogin_cookie_value(), data_source, ml_num, 3);

			  });

			  my_markers[ml_num]= marker;

              map.addOverlay(marker);

            }

          }

        );

      }

    }



   function show_gmap()

   {

     initialize();

	 for (var i = 0; i < page.RESULTS.length; i++) {
		if(i < 8) {
		 address = page.RESULTS[i].address;

		 town = page.RESULTS[i].town;

		 ste = page.RESULTS[i].ste;

		 ml_num = page.RESULTS[i].ml_num;

		 img = page.RESULTS[i].img;

		 lp_dol = page.RESULTS[i].lp_dol;  

		 bedrooms = page.RESULTS[i].bedrooms;

		 bathrooms = page.RESULTS[i].bathrooms;

		 sqft = page.RESULTS[i].sqft; 

		 details_link = page.RESULTS[i].details_link;

         showAddress(address, town, ste, ml_num, img, lp_dol, bedrooms, bathrooms, sqft, details_link);
		}
      }

   }
   
   
   function show_marker(ml_num)

   {

	 GEvent.trigger(my_markers[ml_num], "click");

   }
   
   
   function showAddressSohoMews(address, town, ste, ml_num, img, lp_dol, details_link) {

	  if (geocoder) {

        geocoder.getLatLng(

          address,

          function(point) {

            if (!point) {

              alert(address + " not found");

			  map.setCenter(new GLatLng(40.7667, -73.2333), 9);

            } else {

              map.setCenter(point, 13);

			  map.addControl(new GSmallMapControl());

              map.addControl(new GMapTypeControl());
			  

			  var icon = new GIcon();

			  icon.image = "/images/search_results/red_egg.png";

			  icon.iconSize = new GSize(20, 25);

			  icon.iconAnchor = new GPoint(10, 25);

			  icon.infoWindowAnchor = new GPoint(10,12);

			  			  
			  var marker = new GMarker(point, icon);

	  GEvent.addListener(marker, "click", function() {

			  	//my_marker = marker;

			    var town_ste_row = ((town != '') && (ste != '')) ? ("<tr><td><span class=\"text_size_11\">" + town + ", " + ste + "</span></td></tr>") : ("<tr><td><span class=\"text_size_11\">" + town + ste + "</span></td></tr>");

				var price_row = ((lp_dol != '') && (lp_dol != '$ 0')) ? ("<tr><td><span class=\"text_size_11\">" + lp_dol + "</span></td></tr>") : '';

				var bedrooms_format = ((bedrooms != '') && (bedrooms > 0)) ? (bedrooms + " Bedrooms") : '';

		        var sqft_format = ((sqft != '') && (sqft > 0)) ? (sqft + " Sq. Ft.") : '';

		        var bedrooms_sqft_row = ((bedrooms_format != '') && (sqft_format != '')) ? ("<tr><td><span class=\"text_size_11\">" + bedrooms_format + ", " + sqft_format + "</span></td></tr>") : ("<tr><td><span class=\"text_size_11\">" + bedrooms_format + sqft_format + "</span></td></tr>");

		        var bathrooms_row = ((bathrooms != '') && (bathrooms > 0)) ? ("<tr><td><span class=\"text_size_11\">" + bathrooms + " Bathrooms</span></td></tr>") : '';

				var mls_log = (data_source == 'li') ? "<img src=\"/images/search_results/MLS_icon.gif\" width=\"55\" height=\"17\" />" : "<img src=\"/images/search_results/mls_logo_mht.gif\" width=\"55\" height=\"25\" />";

				

				var info_window_html = '';

				info_window_html += "<table id=\"gmiw\" width=\"369\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += "  <tr><td colspan=\"5\" width=\"369\" height=\"13\"></td></tr>";

				info_window_html += "  <tr>";

				info_window_html += "    <td width=\"13\">&nbsp;</td>";

				info_window_html += "    <td width=\"104\"><img src=\"" + img + "\" width=\"104\" height=\"68\" border=\"0\" onerror=\"imgNotAvailableSmall(this)\" onclick=\"show_property_details_layer('" + ml_num + "','" + data_source + "','')\" style=\"cursor:pointer\"/></td>";

				info_window_html += "    <td width=\"10\">&nbsp;</td>";

				info_window_html += "    <td width=\"233\">";

				info_window_html += "      <table width=\"233\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += town_ste_row;

				info_window_html += price_row;

				info_window_html += "        <tr><td><a href=\"javascript:show_property_details_layer('" + ml_num + "', '" + data_source + "','')\">PROPERTY DETAILS &gt;</a></td></tr>";

				info_window_html += bedrooms_sqft_row;

				info_window_html += bathrooms_row;

				info_window_html += "      </table>";

				info_window_html += "    </td>";

				info_window_html += "    <td width=\"9\"></td>";

				info_window_html += "  </tr>";

				info_window_html += "  <tr><td width=\"369\" height=\"8\" colspan=\"5\"></td></tr>";

				info_window_html += "  <tr>";

				info_window_html += "    <td width=\"369\" colspan=\"5\">";

				info_window_html += "      <table width=\"369\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

				info_window_html += "        <tr>";

				info_window_html += "          <td width=\"13\"></td>";

				info_window_html += "          <td width=\"22\"><img id=\"gmiw_atmf_icon_" + ml_num + "\" src=\"/images/search_results/little_elephant_grey.gif\" width=\"18\" height=\"14\" /></td>";

				info_window_html += "          <td width=\"111\" id=\"gmiw_atmf_holder\"><div id=\"gmiw_atmf_error_holder_" + ml_num + "\" class=\"add_to_myfavs_error_holder\" onClick=\"$(this).hide();\"></div><a href=\"javascript:add_to_my_favs('" + data_source + "', '" + ml_num + "', 3);\" class=\"text_size_11\">add to my favorites</span></td>";

				info_window_html += "          <td width=\"23\"><a href=\"\"><img src=\"/images/search_results/little_square.gif\" width=\"16\" height=\"16\" border=\"0\" /></a></td>";

				info_window_html += "          <td width=\"117\" id=\"\"><a id=\"show_zoom_map\" href=\"javascript:map.setZoom(30);\">center and zoom on map</a></td>";

				/*info_window_html += "          <td width=\"83\">" + mls_log + "</td>";*/

				info_window_html += "        </tr>";

				info_window_html += "      </table>";

				info_window_html += "    </td>";

				info_window_html += "  </tr>";

				info_window_html += "</table>";

				

				marker.openInfoWindowHtml(info_window_html);

				

				request_fav_property_registered(get_ulrp_usrlogin_cookie_value(), data_source, ml_num, 3);

			  });

			  my_markers[ml_num]= marker;

              map.addOverlay(marker);

            }

          }

        );

      }

    }
   
   
  function initialize_sohomews(setCenter) {

      if (GBrowserIsCompatible() && (map_init == false)) {

        map = new GMap2(document.getElementById("gmap"));

        //map.setCenter(new GLatLng(40.721746, -74.003778), 9);

		map.setMapType(G_NORMAL_MAP);

        geocoder = new GClientGeocoder();

		map_init = true;

      }

    } 
   
   function show_gmap_sohomews(){
	   	initialize_sohomews();
		for (var i = 0; i < page.RESULTS.length; i++) {
		if(i < 8) {
		 address = page.RESULTS[i].address;

		 town = page.RESULTS[i].town;

		 ste = page.RESULTS[i].ste;

		 ml_num = page.RESULTS[i].ml_num;

		 img = page.RESULTS[i].img;

		 lp_dol = page.RESULTS[i].lp_dol;  

		 bedrooms = page.RESULTS[i].bedrooms;

		 bathrooms = page.RESULTS[i].bathrooms;

		 sqft = page.RESULTS[i].sqft; 

		 details_link = page.RESULTS[i].details_link;
		 //alert(address + town + ste + ml_num + img + lp_dol + bedrooms + bathrooms + sqft + details_link);

         showAddressSohoMews(address, town, ste, ml_num, img, lp_dol, details_link);
		}
      }
   }

      

   
