var map;
var localSearch = new GlocalSearch();
var bounds = new GLatLngBounds();



function showDealers(type) {
    if(type.toLowerCase() == "all")
    {
        for(var i = 0; i < numOfDealers; i++)
        {
            var point = new GLatLng(DLat[i],DLng[i]);
            icon.image = 'http://motoring.friday-ad.co.uk/Image/MakesLogos/' + DMake[i] + '.gif';
            placeMarkerAtPointForArea(point,DInfo[i],DWebsite[i],DLogo[i],DArea[i]);
        }
    } else {
        for(var i = 0; i < numOfDealers; i++)
        {
            var point = new GLatLng(DLat[i],DLng[i]);
            placeMarkerAtPoint(point,DInfo[i],DWebsite[i],DLogo[i]);
        }
    }
}

function placeMarkerAtPoint(point, dealerInfo, webURL, logoURL)
{
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, 'mouseover', function() {    
      map.openInfoWindowHtml(point, '<div style="max-width:400px;">' + dealerInfo + logoURL + '</div>' + webURL);  
    });  
	map.addOverlay(marker);
	bounds.extend(point);
}

function placeMarkerAtPointForArea(point, dealerInfo, webURL, logoURL, dealerArea)
{
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, 'mouseover', function() {    
      map.openInfoWindowHtml(point, '<div style="max-width:400px;">' + dealerInfo + logoURL + '</div>' + webURL);  
    });  
	map.addOverlay(marker);
	if(area.toLowerCase() == dealerArea.toLowerCase() || area.toLowerCase() == "all"){
	    bounds.extend(point);
	}
}

function mapLoad(type) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		showDealers(type);
		map.setCenter(bounds.getCenter());
		map.setZoom(map.getBoundsZoomLevel(bounds));
	}
}


