google.load("maps", "3",{"other_params":"sensor=false"});
var mapsregistry = new Array();
var whichmap = 0;
function google_plotter_three() {
	$(".job_listing-box-map").each(function(){
		mapsregistry[mapsregistry.length] = $(this).attr('id');
	});
	plotMe();
}

function google_plotter_four() {
	$(".tradespeople-box-map").each(function(){
		mapsregistry[mapsregistry.length] = $(this).attr('id');
	});
	plotMeTradespeople();
}

function plotMe() {
	if(typeof(mapsregistry[whichmap]) != 'undefined' && google.maps) {
		var el = mapsregistry[whichmap];
		var title = $('#'+el).attr('title');
		$('#'+el).attr('title','');
		var position;
		var myOptions = {
			zoom:						10,
			mapTypeId:					google.maps.MapTypeId.ROADMAP,
			scrollwheel:				false,
			keyboardShortcuts:			false,
			mapTypeControl:				false,
			scaleControl:				false,
			navigationControl:			true,
			navigationControlOptions:	{
				style:	google.maps.NavigationControlStyle.SMALL
			}
		}
		var map = new google.maps.Map(document.getElementById(el), myOptions);
		if(google.maps.Geocoder) {
			var geocoder = new google.maps.Geocoder();
			if (geocoder) {
				geocoder.geocode( { 'address': title}, 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,
							title: title
						});
						map.setCenter(results[0].geometry.location);
					} else {
						alert("Geocode was not successful for the following reason: " + status);
					}
				});
			}
		}
		whichmap++;
		setTimeout("plotMe()", 1000);
	}
}

function plotMeTradespeople() {
	if(typeof(mapsregistry[whichmap]) != 'undefined' && google.maps) {
		var el = mapsregistry[whichmap];
		var title = $('#'+el).attr('title');
		$('#'+el).attr('title','');
		var position;
		var myOptions = {
			zoom:						11,
			mapTypeId:					google.maps.MapTypeId.ROADMAP,
			scrollwheel:				false,
			keyboardShortcuts:			false,
			mapTypeControl:				false,
			scaleControl:				false,
			navigationControl:			true,
			navigationControlOptions:	{
				style:	google.maps.NavigationControlStyle.SMALL
			}
		}
		var map = new google.maps.Map(document.getElementById(el), myOptions);
		if(google.maps.Geocoder) {
			var geocoder = new google.maps.Geocoder();
			if (geocoder) {
				geocoder.geocode( { 'address': title}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						if($('#'+el).parent().hasClass('job_page_box')) {
							var marker = new google.maps.Marker({
								map: map, 
								position: results[0].geometry.location,
								title: title
							});
						} else {
						}
						map.setCenter(results[0].geometry.location);
					} else {
						alert("Geocode was not successful for the following reason: " + status);
					}
				});
			}
		}
		whichmap++;
		setTimeout("plotMe()", 1000);
	}
}

function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
          var marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(address);
		  map.setCenter(point, 13);
        }
      }
    );
  }
}

