$(document).ready(function(){
						   
	
	// the search
	var so = 0.8;
	var pretext = 'search';
	
	$('#navservices a:first, #navabout a:first').click(function(){
		return false;								 
	});
	
	
	$('#searchbox').css({'opacity':so});
	
	$('#search').focus(
	function(){
		$('#searchshadow').show();
		$('#searchbox').fadeTo('fast', 1.0);
		
		currtext = $('#search').val();
		if($.trim(currtext) == $.trim(pretext)){
			$(this).val('');
		}
		
	}).blur(function(){
		$('#searchshadow').hide();
		$('#searchbox').fadeTo('fast', so);

		currtext = $('#search').val();
		if($.trim(currtext) == ''){
			$(this).val(pretext);
		}
	});
	
	
	$('#searchform').submit(function(){
		if($.trim($('#search').val()) == ''
			|| $.trim($('#search').val()) == 'search'){
			return false;
		}
	});
	
	// the helpful links
	var prelinktext = $('#links').text();
	var postlinktext = 'Hide helpful links';
	
	$('#links').toggle(
		function(){
		$('#helpfulllinks').slideDown('slow',function(){
			$.scrollTo($('#helpfulllinks'), 800);
		});
		$(this).text(postlinktext);
	},
		function(){
		$('#helpfulllinks').slideUp();
		$(this).text(prelinktext);
	});
	
	
	// the ajax form 
	var restext = '';
	
	
	checkF = function(){
				
		req = ['#name','#phoneore'];
		reqp = ['Name','Phone or Email'];
		
		errors = '';
		
		for(i=0;i<req.length; i++){
			
			$field = $(''+req[i]);
			if($.trim($field.val()) == ''){
				errors+=reqp[i]+' is a required field'+"\n";
			}
			
		}
		
		if(errors.length > 0){
			alert(errors);
			return false;
		}else{
			return true;	
		}
	}
	
	
	$('#sendbt').click(function(){
		
		if(!checkF()){
			return false;
		}
		
		$(this).hide();
		$('#ajaxactivity').show();
		
		$.post(homedir+"_lib/php/ajax_sendemail.php", 
			{ name: $('#name').val(), 
			  phoneore: $('#phoneore').val(),
			  email: $('#email').val(),
			  serviceinterest: $('#serviceinterest').val(),
			  comments: $('#comments').val()
			},
			function(response){
				if(response != '1'){
					restext = response;
				}else{
					restext = 'Form sent. Thank you.';
				}
		});
		return false;
	});
	
	
	$('#ajaxactivity').ajaxStop(function(){
		$(this)
		.css({'backgroundImage':'none','height':'auto'})
		.addClass('formres')
		.text(restext);					 
	});	
	
});
