/** 
 * Inserts the google map with EH marker into the map canvas
 */
function gmap_init(id) { 
  
	// Set up the lat/long location of the clinic
	var ehealth = new google.maps.LatLng(51.5017, -0.020200);

  // Set up the map
  var mapOptions = {
    center: ehealth,
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    streetViewControl: false
  };
	var map = new google.maps.Map(document.getElementById(id), mapOptions);


  // Setup the markers on the map
  var image = '/~exceptio/application/wp-content/themes/ExceptionalHealth/resources/images/exceptionalhealth/layout/gmap-marker.png';
  
  var ehealthMarker = new google.maps.Marker({
      position: ehealth,
      map: map,
      icon: image,
      title: 'Exceptional Health'
  });
}



/**
 * Loaded when the page has rendered and is displayed
 */
$(document).ready(function() {

	// Enable CSS-based javascript
	$('body').removeClass('no-js');


	// Newsletter signup field contains example text, so need to remove on focus
	$('input#newsletter-email').focus(function() {
		
		if($(this).val() == $('input#newsletter-email_example-value').val()) {
			$('input#newsletter-email').removeClass('hasExample').val(''); }
	});
	
	// If focus is removed from newsletter-email and it is empty, re-insert the example
	if($('input#newsletter-email').val() == '') {
			$('input#newsletter-email').addClass('hasExample').val($('input#newsletter-email_example-value').val()); }
	
	$('input#newsletter-email').focusout(function() {

		if($(this).val() == '') {
			$('input#newsletter-email').addClass('hasExample').val($('input#newsletter-email_example-value').val()); }
	});



	// Search query field contains example text, so need to remove on focus
	$('#searchform input#s').focus(function() {
		
		if($(this).val() == $('#searchform input#search-query_example-value').val()) {
			$('#searchform input#s').removeClass('hasExample').val(''); }
	});
	
	// If focus is removed from the search query and it is empty, re-insert the example
	if($('#searchform input#s').val() == '') {
			$('#searchform input#s').addClass('hasExample').val($('#searchform input#search-query_example-value').val()); }
	
	$('#searchform input#s').focusout(function() {

		if($(this).val() == '') {
			$('#searchform input#s').addClass('hasExample').val($('#searchform input#search-query_example-value').val()); }
	});



	// Active Google maps
	//gmap_init('footer_map_canvas');
	
	if($('body').hasClass('page-template-template_contact-us-php')) {
		gmap_init('contact-us_map_canvas'); }
		
		
	// Fade-in content
	$('.subnav-wrapper.onload-hide').slideDown(800).removeClass('onload-hide');
	
	
	// Fade in class 1st, before 2nd, before 3rd
	$('.fadeIn1st').fadeIn(1000, function() {
		$('.fadeIn2nd').fadeIn(800, function() {
			$('.fadeIn3rd').fadeIn(800);
		});
	});
});


