// JavaScript Document


  
	var red_icon = new google.maps.MarkerImage('/images/MapIconRed.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));

	var green_icon = new google.maps.MarkerImage('/images/MapIconGreen.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));
			
	var brown_icon = new google.maps.MarkerImage('/images/MapIconBrown.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));			

	var beige_icon = new google.maps.MarkerImage('/images/MapIconBeige.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));

	var blue_icon = new google.maps.MarkerImage('/images/MapIconBlue.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));

      var darkblue_icon = new google.maps.MarkerImage('/images/MapIconDarkBlue.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));
				
	var land_icon = new google.maps.MarkerImage('/images/MapIconLand.gif',
      new google.maps.Size(24, 24),
      new google.maps.Point(0,0),
      new google.maps.Point(12, 24));
					
				
	   function overlayAdd(region)
   {
	 	changeMode(1);
	if (overlay != "0") { overlayRemove(); }
		
		if (region == "w") {
		    var sw = new google.maps.LatLng(43.217994,-80.275711) ;
    var ne = new google.maps.LatLng(44.085422,-79.376956) ;
    var bounds = new google.maps.LatLngBounds(sw,ne);
	
			overlay = new ProjectedOverlay(map,'/images/overlay_w.png', bounds, {}) ;
	//		document.getElementById('w-overlay').href = "#";
		} else if ( region == "cs") {
		    var sw = new google.maps.LatLng(43.584713,-79.4666) ;
    var ne = new google.maps.LatLng(43.754203,-79.284679) ;
    var bounds = new google.maps.LatLngBounds(sw,ne);
			overlay = new ProjectedOverlay(map,'/images/overlay_cs.png', bounds, {}) ;
	
		} else if ( region == "cn") {
		
				    var sw = new google.maps.LatLng(43.677613,-79.510165) ;
    var ne = new google.maps.LatLng(43.848203,-79.289065) ;
    var bounds = new google.maps.LatLngBounds(sw,ne);
			overlay = new ProjectedOverlay(map,'/images/overlay_cn.png', bounds, {}) 
		
		} else if ( region  == "n" ) {
						    var sw = new google.maps.LatLng(43.556569,-80.14477) ;
    var ne = new google.maps.LatLng(44.42403,-78.945387) ;
    var bounds = new google.maps.LatLngBounds(sw,ne);
			overlay = new ProjectedOverlay(map,'/images/overlay_n.png', bounds, {}) 
		
		
		
		} else if ( region == "e" ) {
		var sw = new google.maps.LatLng(43.608047,-79.35773) ;
    var ne = new google.maps.LatLng(44.322185,-78.422519) ;
    var bounds = new google.maps.LatLngBounds(sw,ne);
			overlay = new ProjectedOverlay(map,'/images/overlay_e.png', bounds, {}) ;
		
		
		
		}
		
   }

// Remove the overlay

  function overlayRemove()
  {
	changeMode(1);
	
   if ( !overlay )
   {
    return ;
   }
   overlay.remove();
   overlay = null;
  }

		
	function changeMode(mode) 
	{
		if (mode == currentMode) { 
			return;
		}
	
		if (mode == 1) {	
				Effect.BlindUp('gallery_canvas', { duration: 0.5 });		
				Effect.BlindDown('map_canvas', { duration: 0.5 });
				Effect.BlindDown('map_legend', { duration: 0.5 });
				document.getElementById('mapmode').checked = true;
				currentMode = 1;
		} else if (mode == 2) {
				Effect.BlindUp('map_canvas', { duration: 0.5 });
				Effect.BlindUp('map_legend', { duration: 0.5 });
				Effect.BlindDown('gallery_canvas', { duration: 0.5 });	
				document.getElementById('gallerymode').checked = true;
				currentMode = 2;
		}
	
	}
	
	function placeMarker (lat, lng, icon, infoblurb, address){
		
//	alert(icon);
//	alert(infoblurb);
//	alert(infoblurb);
//	alert(address);
//		if (icon = "red_icon") {
			icon_type = icon;
//		}
			
		
		var marker = new google.maps.Marker({
									map: map, 
									title: address,
									position: new google.maps.LatLng(lat, lng),
									icon: icon_type
		});
		
		google.maps.event.addListener(marker, 'click', function() {
						 infowindow.setContent(infoblurb); 
						 infowindow.open(map,marker);
		}); 
			 
		marker.myname = address;
		gmarkers.push(marker);
		
	}
	
	
			function place_marker_geo(address, asking_price, mlsid, icon_type) {
	
	    if (geocoder) {
      geocoder.geocode( { 'address': address },  function(results, status) 
				{
         if (status == google.maps.GeocoderStatus.OK) {
						if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
							//map.set_center(results[0].geometry.location);
							
							var marker = new google.maps.Marker({
									map: map, 
									title: address,
									position: results[0].geometry.location,
									icon: icon_type
							});
						 
						
						
						 var contentString ='<div style="width:350px"><img src="/images/fh_90.jpg" height="90"  align="left" style="padding-right:10px;" /><p><strong>Address:</strong> '+address+
						 '<br /><strong>Asking Price:</strong> '+ asking_price +'</p>'
						 + '<a href="#" onclick="showAjaxFormDemonstration(\''+mlsid+'\'); return false;">more info</a></div>';
						 
						 
						google.maps.event.addListener(marker, 'click', function() {
						 infowindow.set_content(contentString); 
						 infowindow.open(map,marker);
					 }); 
			 
							marker.myname = address;
							gmarkers.push(marker);
						} else {
							alert("No results found");
						}
					} else {
						//alert("Geocode was not successful for the following reason: " + status);
					}
				});
				
				
			}
	
		
		}

