function initContactMap() {
      var buxton = new google.maps.LatLng(53.253387,-1.91625);
      var mapOptions = {
        zoom:      2,
        center:    buxton,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      var map = new google.maps.Map($("#map_canvas")[0], mapOptions);

      

      var currentPlace = null;
      var info = $('#placeDetails');
      var icons = {
        'truck':          '/images/map_truck_icon.png',
        'truck-selected': '/images/map_truck_icon_selected.png'
      }


      $.getJSON('/js/places.json', function(places) {
        $(places).each(function() {
          var place = this;
          var marker = new google.maps.Marker({
            position: new google.maps.LatLng(place.position[0], place.position[1]),
            map:      map,
            title:    place.title,
            icon:     icons['truck']
          });

          google.maps.event.addListener(marker, 'click', function() {
            var hidingMarker = currentPlace;
            var slideIn = function(marker) {
              $('h1', info).text(place.title);
              $('address',  info).text(place.address);
              $('.tel',  info).text(place.tel);
              $('.fax',  info).text(place.fax);
              $('.mob',  info).text(place.mob);
              $('.email a',  info).text(place.email).attr("href", "mailto:" + place.email);

              info.animate({right: '0'});
            }

            marker.setIcon(icons['truck-selected']);
            
         //if close button is clicked
			$('.close').click(function (e) {
				//Cancel the link behavior
				e.preventDefault();
				
				 info.animate({right: '-570px'});
			});	
	
	
            
            

            if (currentPlace) {
              currentPlace.setIcon(icons['truck']);

              info.animate(
                { right: '-570px' },
                { complete: function() {
                  if (hidingMarker != marker) {
                    slideIn(marker);
                  } else {
                    currentPlace = null;
                  }
                }}
              );
            } else {
              slideIn(marker);
            }
            currentPlace = marker;
          });
        });
      });
}


function initContactLocations() {
        $.getJSON("/js/places.json", function(result) {
					   $.each(result, function(i, item) {
					       $('<h3>' + item.title + '</h3><li><address>' + item.address + '</address><span class="tel">' + item.tel + '</span><span class="fax">' + item.fax + '</span><span class="mob">' + item.mob + '</span><span class="email"><a href="mailto:' + item.email + '">' + item.email + '</a></span></li>').appendTo("#contactLocations");
					   });
		});
}
         

function initConvertTextToEmails() {
    var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
 
    $(".email").filter(function() {
        return $(this).html().match(regEx);
    }).each(function() {
        $(this).html($(this).html().replace(regEx, "<a href=\"mailto:$1\">$1</a>"));
    });
}



function initDownloadTabs() {
		$( "#tabs" ).tabs();
}

function initMenuHighlight() {
		$("#top_nav ul li, #top_nav_two ul li").find("a").each(function(){
		if( location.href.indexOf(this.href) != -1) {
		$(this).addClass("here");
		}
		});
}



$(document).ready(function() {
			initMenuHighlight();
});


