$(document).ready(function () {
    $('li.menu_class').click(function () {
	$('ul.the_menu').slideToggle('medium');
    });
});

//form validation here

function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('name');
		var email = document.getElementById('email');
		    var message = document.getElementById('message');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(firstname, "Please enter only letters for your name")){	
	 if(emailValidator(email, "Please enter a valid email address")){
		if(notEmpty(message, "Please enter your message")){
	  return true;
    }
  }
}

	return false;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 9){  //if the message is under '9' characters it won't be sent
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}


function isAlphabet(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z ]+/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

//fade script

$(document).ready(function () {
  $(".our-work-thumbs a img").fadeTo(0.5, 1);
  $(".our-work-thumbs a img").hover(
	function () {
	  $(this).fadeTo("fast", 0.6);
	},
	function () {
	  $(this).fadeTo("normal",1);
	}
  );
});

//this function opens links with rel='external' in a new window

function externalLinks() {
  if (!document.getElementsByTagName && document.getElementById) return;

  var anchors = document.getElementsByTagName("a");

  for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
       anchor.target = "_blank";
 }
}
window.onload = externalLinks;



//<![CDATA[
	
    var WINDOW_HTML = '<div style="width: 210px;padding-right: 10px; color:#777"><img src="http://www.creativedirection.info/images/small-logo.png"><a href="http://www.creativedirection.info">Creative Direction</a> <br />10 Walsingham Place, Truro, Cornwall, TR1 2RP - Tel:01872 279449</div>';	
	
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(50.262656, -5.052759), 16);
	var marker = new GMarker(new GLatLng(50.262656, -5.052759));
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(WINDOW_HTML);
	  });
	marker.openInfoWindowHtml(WINDOW_HTML);			
      }
    }
    //]]>

