/**** Add application wide javascripts below this point  ******/
$(document).ready(function() {
	$("#contact input").focus(function(){ $(this).parent().addClass("selected_field")});
  $("#contact input").blur(function(){ $(this).parent().removeClass("selected_field")});
  $("#pulse_subscribe input").focus(function(){ $(this).parent().addClass("selected_field")});
  $("#pulse_subscribe input").blur(function(){ $(this).parent().removeClass("selected_field")});
  $("#report_form input").focus(function(){ $(this).parent().addClass("selected_field")});
  $("#report_form input").blur(function(){ $(this).parent().removeClass("selected_field")});	
  $("#report_form select").focus(function(){ $(this).parent().parent().addClass("selected_field")});
  $("#report_form select").blur(function(){ $(this).parent().parent().removeClass("selected_field")});
	
  $("#contact_name").example('Name', {
  	hide_label: true
  });
  $("#contact_telephone").example('Telephone', {
  	hide_label: true
  });
  $("#search_field").example('Search', {
  	hide_label: true
  });
  $("#contact_me").example('Telephone or email', {
  	hide_label: true
  });
	autobrowse = setTimeout("default_image()", 15000);
  
  $("#home_buttons div").hover(
    function() { 
			clearTimeout(autobrowse);
		  autobrowse = setTimeout("default_image()", 15000);
      
      $("#home_buttons div").removeClass("highlighted");
      $("#page_content").css("background-image", "url(/images/"+home_images[$(this).attr("id")]+")");
			area = "#"+$(this).attr("id") +"_text";
			new_content = $(area).html();
			$("#homepage_content").html(new_content);
			$("#page_content p").css("color", "#767676");
			$("#page_content h1").css("color", "#767676");
			$("#page_content h2").css("color", "#767676");
      $(this).addClass("highlighted");
    },
    function() { 
    }
  );
  if($("#gmap").length) { 
    map = new GMap2(document.getElementById("gmap"));
    maplocation = new GLatLng(52.271031, 0.492778);
    map.setCenter(maplocation, 13);
    map.addControl(new GSmallMapControl());
    var eicIcon = new GIcon(G_DEFAULT_ICON);
    eicIcon.image = "/images/map_pointer.png";
    eicIcon.iconSize = 53;
    markerOptions = { icon:eicIcon };
    map.addOverlay(new GMarker(maplocation, markerOptions));
    map.addControl(new GOverviewMapControl());
    $("#g_norwich").click(function(){
      get_directions_from("Norwich");
      return false;
    });
    $("#g_brum").click(function(){
      get_directions_from("Birmingham, UK");
      return false;
    });
    $("#g_london").click(function(){
      get_directions_from("London M25");
      return false;
    });
  }

});

function get_directions_from(place) {
  map.clearOverlays();
  gdir = new GDirections(map);
  var direct = "from "+place+" to "+maplocation.lat()+", "+maplocation.lng();
  gdir.load(direct);
}

home_images = {
  "risk_man_button":      "home_fireater.jpg",
  "market_intel_button":  "home_target.jpg",
  "procurement_button":   "home_jump.jpg",
  "data_button":          "home_data.jpg",
  "carbon_button":        "home_carbon.jpg",
	"water_button": 				"home_water.jpg" 
}


function default_image() {
  if($("#home_buttons")) {
    $("#home_buttons .highlighted").each(function(){
      $(this).removeClass("highlighted");
			$("#page_content").css("background-image", "url(/images/home_home.jpg)");
			$("#page_content p").css("color", "#EBEBEB");
			$("#page_content h1").css("color", "#EBEBEB");
			$("#page_content h2").css("color", "#EBEBEB");
			area = "#original_text";
			new_content = $(area).html();
			$("#homepage_content").html(new_content);
    });
  }

}

