// Javascipt, Jquery Functions Calls
jQuery(document).ready(function($) {
		
	//main menu styling	
	$("ul.sf-menu").supersubs({ 
		minWidth:    12,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish();  // call supersubs first, then superfish, so that subs are 
					 // not display:none when measuring. Call before initialising 
					 // containing tabs for same reason.
					 
	//Map location
	if(document.getElementById('map')) {
		var map = new GMap2(document.getElementById('map'));  
	   map.setCenter(new GLatLng(-37.560698, 143.867683), 16);
	   var point = map.getCenter();
	   var Icon = new GIcon();
		  Icon.image = "../wp-content/themes/eastwoodvet/images/mapmarker.png";
		  Icon.iconSize = new GSize(16, 16);
		  Icon.shadow = null;
		  Icon.shadowSize = null;
		  Icon.iconAnchor = new GPoint(16, 16);
		  Icon.infoWindowAnchor = new GPoint(16, 16);
	   markerOptions = { icon:Icon };
	   var marker = new GMarker(point, markerOptions);
	   GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml('<h3>We Are Moving Here</h3><p>Phone (03) 5331 1918<br/>81 Mair Street, <br/>Ballarat East Victoria, <br/>Australia 3350</p><p>Get Directions to our Office, <a href="http://maps.google.com/maps?saddr=&daddr=' + point.toUrlValue() + '" target ="_blank">click here<\/a></p>'); } ); 
	   map.addOverlay(marker);
	   GEvent.trigger(marker, "click");
	}

	//Contact Form Javascript
	$('form#contactForm').submit(function() {
	  $('form#contactForm .error').remove();
	  var hasError = false;
	  $('.requiredField').each(function() {
	   if(jQuery.trim($(this).val()) === '') {
		var labelText = $(this).prev('label').text();
		$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
		hasError = true;
	   } else if($(this).hasClass('email')) {
		var emailReg = '/^([w-.]+@([w-]+.)+[w-]{2,4})?$/';
		if(!emailReg.test(jQuery.trim($(this).val()))) {
		 var labelText = $(this).prev('label').text();
		 $(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
		 hasError = true;
		}
	   }
	  });
	  if(!hasError) {
	   $('form#contactForm li.buttons button').fadeOut('normal', function() {
		$(this).parent().append('<img src="../wp-content/themes/eastwoodvet/images/loading.gif" alt="Loading&hellip;" height="31" width="31" />');
	   });
	   var formInput = $(this).serialize();
	   $.post($(this).attr('action'),formInput, function(data){
		$('form#contactForm').slideUp("fast", function() {       
		 $(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent. We check our email all the time, so we should be in touch soon.</p>');
		});
	   });
	  }
	  
	  return false;
	  
	 });
	
});  
