//key = 'ABQIAAAAYJ1dtFvlDgvWpEG0-EPfShTzKqGAHroYmkP5szk3UXgcabzT7BRF8qX5BRfDlySbiSjhOZl5r5iaJA';
key ='ABQIAAAAnGU8CXMfa-GhcDfvDfFEDxSY041M02yLSCM8JDCUSRsahGsKphTJw5taI_G-2KzLC623hf2lOPtGFQ';
var scriptTag = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+key+'" type="text/javascript">' + '<' + '/script' + '>';
document.write(scriptTag);
			
jQuery(function($) {
	 $(document).ready(function () {
		if ($("#client").length ==1) {
			$("#client").bind("change", function(){
				  var match = /(http:\/\/[a-z0-9\-\.]*\/)/i.exec(window.location.href);
				  window.location.href = match[1] + "work/?client=" + $("#client").get(0).value; 
				});
		}
		
		if ($("#discipline").length ==1) {
			$("#discipline").bind("change", function(){
				  var match = /(http:\/\/[a-z0-9\-\.]*\/)/i.exec(window.location.href);
				  window.location.href = match[1] + "work/?discipline=" + $("#discipline").get(0).value; 
				});
		}
		/* Start Luton Map Replace */	 
		if ($("#map").length ==1 && GBrowserIsCompatible()) {
		      //settings  
			  var companyMarkerImage= "/bmb_logodark.gif";  
			  var companyLatLng     = new GLatLng(51.881,-0.41339);  
			  var companyMarkerSize = new GSize(50, 31); //width, height  
			
			  var defaultZoomLevel  = 15;  
			  //end settings  
			
			  //setup elements  
			  var map   = new GMap2(document.getElementById("map")); 
			  map.setUIToDefault();
			  gdir  = new GDirections(map, document.getElementById("directions"));  
			
			  //error handler  
			  GEvent.addListener(gdir, "error", function (){  
				    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)  
					      alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);  
					    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)  
					      alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);  
					    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)  
					      alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);  
					    else if (gdir.getStatus().code == G_GEO_BAD_KEY)  
					      alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);  
					    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)  
					      alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);  
					    else alert("An unknown error occurred.");  
				  });  
			
			  createMarker = function(latlng, imageURL, imageSize)  
			  {  
			    
			      var marker      = new GIcon(G_DEFAULT_ICON, imageURL);  
			      marker.iconSize = imageSize;  
			    
			      return new GMarker(latlng, { icon: marker });  
			    
			  }
			  
			  //set company marker  
			  var companyMarker = createMarker(companyLatLng, companyMarkerImage, companyMarkerSize);  
			
			  //set map center  
			  map.setCenter(companyLatLng, defaultZoomLevel);  
			  map.addOverlay(companyMarker);  
			  
			  
			    
			   
			  $('#getDirections').bind("click", function(e){ 
			      gdir.load("from: " + $('#from').get(0).value + " to: " + "51.881,-0.41339");  
			  });
		}
	 
	 
		/* End Luton Map Replace */	
		 	
		/* Start Bath Map Replace */	
		 if ($("#mapbath").length ==1 && GBrowserIsCompatible()) {
			      //settings  
				  var companyMarkerImage= "/bmb_logodark.gif";  
				  var companyLatLng     = new GLatLng(51.447273,-2.201479);  
				  var companyMarkerSize = new GSize(50, 31); //width, height  
				
				  var defaultZoomLevel  = 15;  
				  //end settings  
				
				  //setup elements  
				  var map   = new GMap2(document.getElementById("mapbath")); 
				  map.setUIToDefault();
				  gdir  = new GDirections(map, document.getElementById("directions"));  
				
				  //error handler  
				  GEvent.addListener(gdir, "error", function (){  
					    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)  
						      alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);  
						    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)  
						      alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);  
						    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)  
						      alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);  
						    else if (gdir.getStatus().code == G_GEO_BAD_KEY)  
						      alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);  
						    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)  
						      alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);  
						    else alert("An unknown error occurred.");  
					  });  
				
				  createMarker = function(latlng, imageURL, imageSize)  
				  {  
				    
				      var marker      = new GIcon(G_DEFAULT_ICON, imageURL);  
				      marker.iconSize = imageSize;  
				    
				      return new GMarker(latlng, { icon: marker });  
				    
				  }
				  
				  //set company marker  
				  var companyMarker = createMarker(companyLatLng, companyMarkerImage, companyMarkerSize);  
				
				  //set map center  
				  map.setCenter(companyLatLng, defaultZoomLevel);  
				  map.addOverlay(companyMarker);  
			}
	 	});
	/* End Bath Map Replace */	
	 		
	 if ($("#primary").length ==1) {
		
		var scroll = $('html').scrollTop() || $(window).scrollTop();
		
		$('#stay-top').data('sBottom', $('#stay-top').innerHeight() + 15);
		$('#stay-top').data('sTop', $('#stay-top').offset().top);
		
		var windowHeight = window.innerHeight || document.documentElement.clientHeight;
		
		stayTop=function()
		{
			var scroll = $('html').scrollTop() || $(window).scrollTop();
			var contentHeight = $('#content').innerHeight();
			stBottom = scroll + $('#stay-top').data('sBottom');
			
			if(stBottom > contentHeight) {
				$('#stay-top').css({
					position: 'absolute', 
					bottom: 15, 
					top: null
				});
			} else if ((scroll + 12) < $('#stay-top').data('sTop')) {
				$('#stay-top').css({
					position: 'static'
				});
			} else {
				$('#stay-top').css({
					position: 'fixed',
					top : 12
				});
			}
			
			$('#primary').css({'height': $('#content').innerHeight()-18});
			setTimeout("stayTop()", 30);
		}
		stayTop();
	}
});