﻿$(document).ready(function() {  
  initializeMap();
  getDirections();      
});

function initializeMap()
{
  var latlng = new google.maps.LatLng(51.50339, -2.540057);
  var myOptions = {
    zoom: 14,
    center: latlng,
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    mapTypeId: google.maps.MapTypeId.HYBRID
  };
  var map = new google.maps.Map(document.getElementById("googleMap"), myOptions);
  
  var image = cct.root + "images/a/contact-us/map-marker.png";  
  var beachMarker = new google.maps.Marker({
      position: latlng,
      map: map,
      icon: image,
      title:"CCT Headquarters"
  });

} //  initializeMap

function getDirections()
{
  $("div.googleMapWrapper").show();
  $("div.nonJSMap").hide();
  $("div#find-us p.intro").text("Use the map below to get directions to CCT with Google Maps.");
  
  $("input.btnGetDirections").click(function() {    
    var isValid = true;    
    if ($("input#txtFrom").val() == "") { isValid = false; }    
    if (isValid == true)
      window.open("http://maps.google.co.uk/maps?f=d&source=s_d&hl=en&geocode=&saddr=" + $("input#txtFrom").val() + "&daddr=BS16 1EJ", "popupDir");
    else
      $("input#txtFrom").addClass("error").val("Enter Postcode");
    return false;
  });
  
  $("input#txtFrom").focus(function() {
    if ($(this).val() == "Enter Postcode") { $(this).val("").removeClass("error"); }
  });  
}

