var geocoder;
var bounds;
var destMap;
geocoder = new google.maps.Geocoder();


	// jQuery(document).load(function(){
		// jQuery('.couponPhoto img').each(function(){
			// var img = jQuery(this);
			// if(img.height() > 90)
			// {
				// img.css('width','auto');
				// img.css('height','90px');
			// }
		// });
	// });


function makeMapAddress(div,markers,options){
    jQuery(document).ready(function(){

        var zoom = 20;
        if (typeof(options)=='object'){
            if (typeof(options.zoom)!=undefined) zoom = options.zoom;
        } else {
            options = {};
        }

        var myOptions = {
            zoom: zoom,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        destMap = new google.maps.Map(document.getElementById(div), myOptions);

        var marker;
        bounds = new google.maps.LatLngBounds();
        
        for (marker in markers){            
            codeAddress(markers[marker],destMap,options);
        }        
                
    });

}



function codeAddress(address,map,options) {
    geocoder.geocode( {
        'address': address
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
            
            bounds.extend(results[0].geometry.location);

            if (typeof(options.zoom)!='undefined'){
                // zoom was specified, so let's just use the center
                map.setCenter(bounds.getCenter());                
                map.setZoom(options.zoom);
                
            } else {
                // no zoom specified, full auto
                map.fitBounds(bounds);
            }
            
//            var listener = google.maps.event.addListener(map, "idle", function() {
//                if (map.getZoom() > fzoom) map.setZoom(fzoom);
//                google.maps.event.removeListener(listener);
//            });
        } else {

            console.log("Geocode was not successful for the following reason: " + status);
            curlatlng = false;
            return false;
        }
    });
    
}

