function theRotator() {
	//Set the opacity of all images to 0
	jQuery('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = (jQuery('div#rotator ul li.show')?  jQuery('div#rotator ul li.show') : jQuery('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#rotator ul li:first') :current.next()) : jQuery('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};


$(document).ready(function() {
 
    function isValidEmailAddress(emailAddress) {
     var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
     return pattern.test(emailAddress);	
   }
 
   $("#sendemailbtn").click(function(e){
          
     e.preventDefault();
     
     error='';
     
     if ($("#name").val()==''){
     
       error=error+'Your name is required\n';
     
     }
     
     if(isValidEmailAddress($("#email").val())){
     
     } else {
       error=error+'Your e-mail address appears invalid\n';
     }

     if ($("#subject").val()==''){
     
       error=error+'Subject is required\n';
     
     } 

     if ($("#message").val()==''){
     
       error=error+'You need to enter a message\n';
     
     }
     
     if (error==''){ $('#sendemail').submit(); } else { alert(error); }
   
   });
   
function getUrlVars() {
	var vars = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		vars[key] = value;
	});
	return vars;
}

var first = getUrlVars()["page_id"];

if (first==129){

if (GBrowserIsCompatible()) {

  // A function to create the marker and set up the event window
  // Dont try to unroll this function. It has to be here for the function closure
  // Each instance of the function preserves the contends of a different instance
  // of the "marker" and "html" variables which will be needed later when the event triggers.
  function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

  // Display the map, with some controls and set the initial location
  var map = new GMap2(document.getElementById("map-1"));
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(52.928083, 1.27),13);

  var point = new GLatLng(52.931131, 1.300078);
  var marker = createMarker(point, '<b>Icarus Hines Cromer<\/b><br/>69 Church Street<br/>Cromer<br/>Norfolk<br/>NR27 9RN<br/>01263 514541<br/><br />');
  map.addOverlay(marker);

  var map2 = new GMap2(document.getElementById("map-2"));
  map2.addControl(new GSmallMapControl());
  map2.addControl(new GMapTypeControl());
  map2.setCenter(new GLatLng(52.94382806432169, 1.2079811096191406),13);

  var point2 = new GLatLng(52.94321, 1.21017);
  var marker2 = createMarker(point2,'<b>Icarus Hines Sheringham<\/b><br/>3 Church Street<br/>Sheringham<br/>Norfolk<br/>NR26 8QR<br/>01263 823268<br/><br />');
  map2.addOverlay(marker2);
 

}
// display a warning if the browser was not compatible
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

}

if (first==216){

  theRotator();

}
   
 });

