
		$(document).ready(function(){
			$('#banner-imgs').cycle({ 
				timeout: 7000 ,
				fx: 'fade' ,
				pagerEvent: 'mouseover' ,
				pauseOnPagerHover: true,
				fastOnEvent: true
			});

			$('#case-study-scroll').cycle({ 
				fx:     'fade', 
				speed:  'fast', 
				timeout: 0, 
				next:   '#case-study-next', 
				prev:   '#case-study-prev',
				after:	changeLink
			});

			$("#frmDateBookIn").datepicker( { dateFormat: 'dd/mm/yy' });

			$("#frmDateQuote").datepicker( { dateFormat: 'dd/mm/yy' });
			
			$('#frmMailingList').ajaxForm( { beforeSubmit: validateMailingListForm, success: handleResponse } ); 
			$('#frmBookIn').ajaxForm( { beforeSubmit: validateBookInForm, success: handleResponse } ); 
			$('#frmQuote').ajaxForm( { beforeSubmit: validateQuoteForm, success: handleResponse } );
			$('#frmQuickQuote').ajaxForm( { beforeSubmit: validateQuickQuoteForm, success: handleResponse } ); 

		});

		$(function() {
			$('.case-study-work-pics a').lightBox();
		});

		
		function validateMailingListForm(formData, jqForm, options) {

			var form = jqForm[0];

			if (trim(form.frmNameMailingList.value) == '')	{
				form.frmNameMailingList.focus();
				alert('Please enter your name');
				return false;
			}
			
			if (!checkEmail(form.frmEmailMailingList.value))
			{
				form.frmEmailMailingList.focus();
				alert('Please enter a valid email address');
				return false;
			}

		}
		
		function validateQuickQuoteForm(formData, jqForm, options) {

			var form = jqForm[0];

			if (trim(form.frmNameQuickQuote.value) == '')	{
				form.frmNameQuickQuote.focus();
				alert('Please enter your name');
				return false;
			}
			
			if (!checkEmail(form.frmEmailQuickQuote.value))
			{
				form.frmEmailQuickQuote.focus();
				alert('Please enter a valid email address');
				return false;
			}

		}


		function validateBookInForm(formData, jqForm, options) {

			var form = jqForm[0];

			if (trim(form.frmFNameBookIn.value) == '')	{
				form.frmFNameBookIn.focus();
				alert('Please enter your first name');
				return false;
			}
			
			if (trim(form.frmSNameBookIn.value == ''))	{
				form.frmSNameBookIn.focus();
				alert('Please enter your Surname');
				return false;
			}

			if (!checkEmail(form.frmEmailBookIn.value))
			{
				form.frmEmailBookIn.focus();
				alert('Please enter a valid email address');
				return false;
			}

						
			if (trim(form.frmDaytimeTelephoneBookIn.value) == '')	{
				form.frmDaytimeTelephoneBookIn.focus();
				alert('Please enter your daytime telephone number');
				return false;
			}

			if (trim(form.frmRegistrationBookIn.value) == '')	{
				form.frmRegistrationBookIn.focus();
				alert('Please enter your registration number');
				return false;
			}

			if (trim(form.frmSecurityCodeBookIn.value) == '')	{
				form.frmSecurityCodeBookIn.focus();
				alert('Please enter the security code');
				return false;
			}

		}

		function validateQuoteForm(formData, jqForm, options) {

			var form = jqForm[0];

			if (trim(form.frmFNameQuote.value) == '')	{
				form.frmFNameQuote.focus();
				alert('Please enter your first name');
				return false;
			}
			
			if (trim(form.frmSNameQuote.value) == '')	{
				form.frmSNameQuote.focus();
				alert('Please enter your Surname');
				return false;
			}

			if (!checkEmail(form.frmEmailQuote.value))
			{
				form.frmEmailQuote.focus();
				alert('Please enter a valid email address');
				return false;
			}
						
			if (trim(form.frmDaytimeTelephoneQuote.value) == '')	{
				form.frmDaytimeTelephoneQuote.focus();
				alert('Please enter your daytime telephone number');
				return false;
			}

			if (trim(form.frmRegistrationQuote.value) == '')	{
				form.frmRegistrationQuote.focus();
				alert('Please enter your registration number');
				return false;
			}
			
			if (trim(form.frmRepairsRequiredQuote.value) == '')	{
				form.frmRepairsRequiredQuote.focus();
				alert('Please enter your repairs required');
				return false;
			}

			if (trim(form.frmSecurityCodeQuote.value) == '')	{
				form.frmSecurityCodeQuote.focus();
				alert('Please enter the security code');
				return false;
			}
		}

		function handleResponse(responseXML) {
			var code = $('code', responseXML).text(); 
			if (code != 0)	{
				var message = $('message', responseXML).text(); 
				alert(message);
			}
			else 
			{
				var message = $('message', responseXML).text(); 
				alert(message);		
				tb_remove();

				$('#frmMailingList').find(':input').each(function() { $(this).val(''); });
				$('#frmBookIn').find(':input').each(function() { $(this).val(''); });
				$('#frmQuote').find(':input').each(function() { $(this).val(''); });
				$('#frmQuickQuote').find(':input').each(function() { $(this).val(''); });
				
			}		
			return false;
		}

		function checkEmail(strEmail) {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(strEmail)) {
				return false;
			}
			return true;
		}


		function trim(strValue) {
			return $.trim(strValue);
		}

		function changeLink() {
			$('#case-study-link').attr('href', $(this).attr('rel'));
			$('#case-study-title').html($(this).attr('title'));
		}

		function initialize() {
			var latlng = new google.maps.LatLng(55.588459, -4.60649);
			
			var myOptions = {
			  zoom: 12,
			  center: latlng,
			  mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

			var marker = new google.maps.Marker({
				position: latlng, 
				map: map,
				title:"Planet Performance"
			});  
		  }

		function CreateBookmarkLink() {
			title = "Planet Performance"; 
			url = "http://www.planetperformance.co.uk";
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			} 
			else if( window.external ) { // IE Favorite
				window.external.AddFavorite( url, title); }
			else if(window.opera && window.print) { // Opera Hotlist
				var elem = document.createElement('a');
				elem.setAttribute('href',url);
				elem.setAttribute('title',title);
				elem.setAttribute('rel','sidebar');
				elem.click(); 
			}
			return false;
		}

		function showVideo(videoId) {
			$('#ytObj').attr('src', 'http://www.youtube.com/v/' + videoId + '&hl=en_GB&fs=1&color1=0x3a3a3a&color2=0x999999');
			return false;
		}
		 

