//<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAANDxCKR7ig0xOvXUZ_IjwuhTOXHImBK9c8yWzFAGtPVTKaMGFQxRPxZQabvtqdrzp1eV7QHthhZqqQA"   type="text/javascript"></script>
//<body onload="initialize(); showAddress('1 Yonge St.');" onunload="GUnload();">
//<div id="map_canvas" style="width: 500px; height: 300px"></div>
//
/*
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAANDxCKR7ig0xOvXUZ_IjwuhTOXHImBK9c8yWzFAGtPVTKaMGFQxRPxZQabvtqdrzp1eV7QHthhZqqQA"   type="text/javascript"></script>
<script src="/js/gmap.js"   type="text/javascript"></script>
<script language='javascript'>
	var builder = new GHome();
	builder.addAddress("1 Yonge St.");
	</script>
	<body onload="initialize();builder.showAddresses(); " onunload="GUnload();">
*/
///////////////////////////GOOGLE////////////////////////////////


    function initialize() {
			if (GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById("map_canvas"));
				map.setCenter(new GLatLng(43.664891407668904, -79.37982559204102), 13);
				geocoder = new GClientGeocoder();
				map.addControl(new GSmallMapControl());  // zooming
				map.addControl(new GMapTypeControl());  // hybrid view...

			}
    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              GEvent.addListener(marker, "click", function() {
				        marker.openInfoWindowHtml(address);
				      });
              GEvent.addListener(marker, "onmouseover", function() {
				        marker.openInfoWindowHtml(address);
				      });
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }

      	var marker = null;

  // this variable will collect the html which will eventualkly be placed in the side_bar
      var nav_html = "";

      // arrays to hold copies of the markers and html used by the side_bar
      // because the function closure trick doesnt work there


          var gmarkers = [];

 // This function picks up the click and opens the corresponding info window
      function myclick(i) {

        GEvent.trigger(gmarkers[i], "click");
				gmarkers[i].show();
				map.setCenter(gmarkers[i].getLatLng(), 13);
      }



function showAddressModel(lat, lng,mName, pName, bName, htmlTag){
	// use a custom icon with letter A - Z
	var letter = String.fromCharCode("A".charCodeAt(0) + (gmarkers.length));
	var myIcon = new GIcon(G_DEFAULT_ICON, "/images/marker" + letter + ".png");
	myIcon.printImage = "http://maps.google.com/mapfiles/marker"+letter+"ie.gif";
	myIcon.mozPrintImage = "http://maps.google.com/mapfiles/marker"+letter+"ff.gif";

	var latlng = new google.maps.LatLng(lat, lng);

	map.setCenter(latlng, 11);
	/*
	if(pPhone == 'null')
		pPhone = '';
	var address = ""+ pName + "<BR>\n"+ unescape(pAddrs) + "<BR>\n"+  pPhone + "<BR>" + htmlTag;
	*/
	var address = htmlTag;
	marker = new GMarker(latlng, {icon:myIcon});

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(address);
		marker.show();
	});
	// save the info we need to use later for the side_bar
	gmarkers.push(marker);
	var tstr= '<b><img src="'+myIcon.image+'" align="left" hspace="10"/><\/b> <a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + mName + " - " +pName + '<\/a><ul style="list-style:none; padding: 0px 0px 0px 20px;"><li>'+bName+'</li></ul>';
	nav_html+= tstr;

	map.addOverlay(marker);
	marker.openInfoWindowHtml(address);
}


function showAddress(lat, lng, pName, bName, htmlTag){
	// use a custom icon with letter A - Z
	var letter = "";
	if(gmarkers.length < 26 )
	letter = String.fromCharCode("A".charCodeAt(0) + (gmarkers.length));
	var myIcon = new GIcon(G_DEFAULT_ICON, "/images/marker" + letter + ".png");
	myIcon.printImage = "http://maps.google.com/mapfiles/marker"+letter+"ie.gif";
	myIcon.mozPrintImage = "http://maps.google.com/mapfiles/marker"+letter+"ff.gif";

	var latlng = new google.maps.LatLng(lat, lng);
	map.setCenter(latlng, 11);

	var address =  unescape(htmlTag).replace(/\+/g,' ');
	marker = new GMarker(latlng, {icon:myIcon});

	GEvent.addListener(marker, "click", function() {

marker = new GMarker(latlng, {icon:myIcon});
map.addOverlay(marker);
		marker.openInfoWindowHtml(address);
		marker.show();
	});
	// save the info we need to use later for the side_bar
	gmarkers.push(marker);
	var tstr= '<b><img src="'+myIcon.image+'" align="left" hspace="10"/><\/b> <a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + unescape(pName).replace(/\+/g,' ') + '<\/a><ul style="list-style:none; padding: 0px 0px 0px 20px;"><li>'+unescape(bName).replace(/\+/g,' ')+'</li></ul>';
	nav_html+= tstr;

	map.addOverlay(marker);
	marker.openInfoWindowHtml(address);
}



    function loadMap() {
      map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(37.4419, -122.1419), 6);
      map.addOverlay(new GMarker(map.getCenter()));
    }


      function loadMap(lat,lng,z) {
      map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(lat,lng), z);
      map.addOverlay(new GMarker(map.getCenter()));
    }

    function loadScript() {
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "http://maps.google.com/maps?file=api&v=2.x&key=<%=PropertyManager.getProperty('gmapKey')%>&async=2&callback=loadMap";
      document.body.appendChild(script);
    }

    //]]>


///////////////////////////KEVIN W CODE////////////////////////

function GHome(){
	this.addresses = new Array();
	this.city = "";
	this.model= "";
}

GHome.prototype.addAddress = function(addr){
	this.addresses.push(new String(addr));
}

GHome.prototype.setCity = function(c){
	this.city = c;
}
GHome.prototype.setModel = function(m){
	this.model = m;
}
GHome.prototype.toURL = function(){
	var result = "/search/gmap.jsp?";
	for(  a in this.addresses){
		result+= "a="+this.addresses[a]+"&";
	}
	result+= "c="+this.city+"&";
	result+= "m="+this.model;
	return result;
}

GHome.prototype.openMap = function(){
	this.openMap(820, 710);
}

GHome.prototype.openMapSize = function(w, h){
	window.open(this.toURL(),"_blank", "New in Homes 2009", "width="+w+",height="+h);
}

GHome.prototype.openMap = function(w, h){
	window.open(this.toURL(),"_blank", "New in Homes 2009", "width="+w+",height="+h);
}


GHome.prototype.showAddresses = function(){
	for ( a in this.addresses ){
		showAddress(this.addresses[a]);
	}
}

/*
var test = new GHome();
test.addAddress("1 Yonge St.");
test.addAddress("250 QUEENS QUAY W");
*/

/*
var gData = new Object();
gData.addresses = new Array();
gData.addAddress = function(addr){
	this.addresses.push(new String(addr));
}
gData.toURL = function(){
	var result = "/search/gmap.jsp?";
	for(  a in gData.addresses){
		result+= "a="+gData.addresses[a]+"&";
	}
	return result;
}

gData.openMap = function(){
	window.open(gData.toURL(), "TorontoStar", "width=550, height=400");
}

gData.showAddresses = function(){
	for ( a in gData.addresses ){
		showAddress(gData.addresses[a]);
	}
}


gData.addAddress("1 Yonge St.");

gData.addAddress("L4B3W6");
gData.addAddress("250 QUEENS QUAY W");
//document.write(gData.toURL());

*/



