﻿var poster;
var inMapView = false;
var usCenter = new Array(38.75408, -93.60352);

function showMap() 
{
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        var latlongzoom = mapCenter.split(",");
        map.setCenter(new GLatLng(latlongzoom[0],latlongzoom[1]), parseInt(latlongzoom[2]));
        map.setUIToDefault();
        AddPropPins(map);
    }
    else { alert("Your browser is not compatible with Google Maps."); }
}


function createMarker(home)
{
    var myIcon = new GIcon(G_DEFAULT_ICON);
    
    if(is_ie6) // ie6 and google maps can't handle the PNG!
    {
        myIcon.image = "/Assets/Images/map-marker.gif";	
        myIcon.transparent = null; // don't use transparency mask
        myIcon.shadow = null; // don't use shadow image
        myIcon.iconSize = new GSize(22, 35); // icon size matches image
        myIcon.shadowSize = null; // self-explanatory
        myIcon.iconAnchor = new GPoint(11, 34); // *center* of the icon
        myIcon.infoWindowAnchor = new GPoint(17, 8);
        myIcon.infoShadowAnchor = null;

    }
    else  // not ie6?  good browser, you can handle the PNG
    {
        myIcon.image = "/Assets/Images/gmap_house_marker.png";
        myIcon.iconSize = new GSize(22, 35);
        myIcon.shadow = "/Assets/Images/gmap_house_marker_shadow.png";
        myIcon.shadowSize = new GSize(48, 35);
        myIcon.iconAnchor = new GPoint(11, 34);
        myIcon.infoWindowAnchor = new GPoint(17, 8);
        myIcon.printImage = "/Assets/Images/gmap_house_marker_print.gif";
        myIcon.mozPrintImage = "/Assets/Images/gmap_house_marker_mozPrint.gif";
        myIcon.printShadow = "/Assets/Images/gmap_house_marker_printShadow.gif";
        myIcon.transparent = "/Assets/Images/gmap_house_marker_transparent.png";
        myIcon.imageMap = [ 0,0, 21,0, 21,22, 16,22, 12,34, 10,34, 5,22, 0,22 ]; 
    }

    var markerOptions = { icon:myIcon };

    var marker = new GMarker(home.latlong, markerOptions);
    var html = "<b>" + home.addr + "</b> <br/>";
    GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
    });
    return marker;
}

function maxInfoWindow(center) 
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("map_canvas"));
        var latlong
        
        if(center == 'undefined')
            latlong = center.split(",");
        else
            latlong = usCenter
            
        map.setCenter(new GLatLng(latlong[0], latlong[1]), 4);
        map.setUIToDefault();
        map.openInfoWindow(map.getCenter(), document.createTextNode("Your search returned too many listings to plot. Please narrow your search."));
    }
    else { alert("Your browser is not compatible with Google Maps."); }
}

function zeroInfoWindow() 
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(usCenter[0], usCenter[1]), 4);
        map.setUIToDefault();
        map.openInfoWindow(map.getCenter(), document.createTextNode("There are no listings that matched your search. Please broaden your search."));
    }
    else { alert("Your browser is not compatible with Google Maps."); }
}