    var YWSID = "7tUG01kkrqPkqVWUORd4Yg"; // common required parameter (api key)
    var map = null;
    var icon = null;

    /*
     * Creates the map object and calls setCenterAndBounds
     * to instantiate it.
     */
    function load(lat,long,zoom) {
        map = new GMap2(document.getElementById("map"));
        GEvent.addListener(map, "load", function() {updateMap();});    
        map.setCenter(new GLatLng(lat,long),zoom);

		var pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0,0));
    	pos.apply(document.getElementById("yelp-search"));
    	map.getContainer().appendChild(document.getElementById("yelp-search"));

		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0,0));
    	pos.apply(document.getElementById("yelp-info"));
    	map.getContainer().appendChild(document.getElementById("yelp-info"));

		var pos = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0,0));
    	pos.apply(document.getElementById("yelp-switcher"));
    	map.getContainer().appendChild(document.getElementById("yelp-switcher"));

		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0,0));
    	pos.apply(document.getElementById("yelp-dd"));
    	map.getContainer().appendChild(document.getElementById("yelp-dd"));

		var pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,40));
    	pos.apply(document.getElementById("yelp-map-control"));
       	map.getContainer().appendChild(document.getElementById("yelp-map-control"));

       
        //map.addControl(new GMapTypeControl());
        map.setMapType(G_NORMAL_MAP);
                
        if (window.attachEvent) window.attachEvent("onresize", function() {map.checkResize()});
        else if (window.addEventListener) window.addEventListener("resize", function() {map.checkResize()}, false);

        // setup our marker icon
        icon = new GIcon();
        icon.image = "/communities/_source/img/communities/marker_star.png";
        icon.shadow = "/communities/_source/img/communities/marker_shadow.png";
        icon.iconSize = new GSize(20, 29);
        icon.shadowSize = new GSize(38, 29);
        icon.iconAnchor = new GPoint(15, 29);
        icon.infoWindowAnchor = new GPoint(15, 3);

    }
	
	

    function constructYelpURL() {
	    document.getElementById("yelp-info").style.visibility = 'hidden';
        var mapBounds = map.getBounds();
        var URL = "http://api.yelp.com/" +
            "business_review_search?"+
            "callback=" + "handleResults" +
            "&category=" + document.getElementById("term").value + 
            "&num_biz_requested=100" +
            "&tl_lat=" + mapBounds.getSouthWest().lat() +
            "&tl_long=" + mapBounds.getSouthWest().lng() + 
            "&br_lat=" + mapBounds.getNorthEast().lat() + 
            "&br_long=" + mapBounds.getNorthEast().lng() +
            "&ywsid=" + YWSID;
        return encodeURI(URL);
    }

    function updateMap() {
        var yelpRequestURL = constructYelpURL();
        /* clear existing markers */
        map.clearOverlays();
        
        /* do the api request */
        var script = document.createElement('script');
        script.src = yelpRequestURL;
        script.type = 'text/javascript';
        var head = document.getElementsByTagName('head').item(0);
        head.appendChild(script);
        return false;
    }

    function handleResults(data) {
        if(data.message.text == "OK") {
            if (data.businesses.length == 0) {
                document.getElementById("yelp-info").style.visibility = 'visible';
                return;
            }
            for(var i=0; i<data.businesses.length; i++) {
                biz = data.businesses[i];
                createMarker(biz, new GLatLng(biz.latitude, biz.longitude), i);
            }
        }
        else {
            alert("Error: " + data.message.text);
        }
    }

    function generateInfoWindowHtml(biz) {
        var text = '<div class="marker">';
        text += '<div class="businessinfo">';
        text += '<a href="'+biz.url+'" target="_blank">'+biz.name+'</a><br/>';
        text += biz.address1 + '<br/>';
        if(biz.address2.length) 
            text += biz.address2+ '<br/>';
        text += biz.city + ',&nbsp;' + biz.state + '&nbsp;' + biz.zip + '<br/>';
        if(biz.phone.length)
            text += formatPhoneNumber(biz.phone);
        text += '<img class="ratingsimage" src="'+biz.rating_img_url_small+'"/>&nbsp;based&nbsp;on&nbsp;';
        text += '<a href="'+biz.url+'" target="_blank">'+ biz.review_count + '&nbsp;reviews</a><br/>';
        text += '</div></div>'
        return text;
    }

    function formatPhoneNumber(num) {
        if(num.length != 10) return '';
        return '(' + num.slice(0,3) + ') ' + num.slice(3,6) + '-' + num.slice(6,10) + '<br/>';
    }
    
    function createMarker(biz, point, markerNum) {
        var infoWindowHtml = generateInfoWindowHtml(biz)
        var marker = new GMarker(point, icon);
        map.addOverlay(marker);
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(infoWindowHtml, {maxWidth:400});
        });
    }
