$(function(){

	//create toogles, tabs panels, twitter feed, posts widget, testimonials widget, lightboxes, etc..
	if($('#testimonial').length > 0) $('#testimonial').testimonials();
	
	// Top of page scroll
	$('.scroll-top').click(function(){ 
		$('html, body').animate({scrollTop:0}, 600); return false; 
	});
	
	//add input replacement and hover
	$('input, textarea').each(function(){
	
		if($(this).attr('id') != 'submitButton'){
			$(this).attr('data-value', $(this).val())
				.focus(function(){
					$(this).addClass('focusInput');
					if($(this).val() == $(this).attr('data-value')){
						$(this).val('');
					} else {
						$(this).select();
					}
				})
				.blur(function(){
					$(this).removeClass('focusInput');
					if($(this).val() == ''){
						$(this).val($(this).attr('data-value'));
					}
				});
		}
		
	});
	
	//menu animation
	$('#top ul > li').each(function(){;
		if($(this).children('div').length > 0){
		
			var $li = $(this).find('li');
			
			$li.animate({'opacity': '0'}, 0);
			$(this).find('div').animate({'opacity': '0'}, 0);
			
			$(this).hover(function(){
				
				$(this).find('div').animate({'opacity': '1'}, 300);
				$li.each(function(){
					$(this).stop().delay($(this).index()*100).animate({'opacity': '1'}, 300);
				});
			
			}, function(){
			
				$li.animate({'opacity': '0'}, 0);
			
			});
		
		}
	});
	
	// equipment imageSwitcher
	$("#tear-off").click(function(){
		var src = $("#current_equipment").attr("src");
		$("#current_equipment").hide();
		$("#current_equipment").attr("src","images/tear-off-box.png").fadeIn(1000);;
		$("#equipment_name").html("Tear Off Box");
		$("#description").html("This is a Brute Manual Roofing Tear Off Box. It's demensions are 4' X 6.5' X 18\" cubic yards.");
	});
		
	$("#two-man").click(function(){
		var src = $("#current_equipment").attr("src");
		$("#current_equipment").hide();
		$("#current_equipment").attr("src","images/two-man-basket.png").fadeIn(1000);
		$("#equipment_name").html("Two Man Platform");
		$("#description").html("This is a two man work platform attachment. 30\" X 90\" with hydraulic brake.");
	});	
		
	$("#one-man").click(function(){
		var src = $("#current_equipment").attr("src");
		$("#current_equipment").hide();
		$("#current_equipment").attr("src","images/one-man-basket.png").fadeIn(1000);;
		$("#equipment_name").html("One Man Basket");
		$("#description").html("This is a one man basket attachment. It's made of 20\" X 30\" Steel with a pin lock.");
	});	
		
	$("#block-forks").click(function(){
		var src = $("#current_equipment").attr("src");
		$("#current_equipment").hide();
		$("#current_equipment").attr("src","images/crane-block-forks.png").fadeIn(1000);;
		$("#equipment_name").html("Crane Block Forks");
		$("#description").html("This is block fork attachment. It has six 48\" adjustable forks with a 48\" by 60\" adjustable throat.");
	});	
		
	$("#pallet-forks").click(function(){
		var src = $("#current_equipment").attr("src");
		$("#current_equipment").hide();
		$("#current_equipment").attr("src","images/crane-pallet-forks.png").fadeIn(1000);;
		$("#equipment_name").html("Crane Pallet Forks");
		$("#description").html("This is pallet fork attachment. It has a max capacity of 4,000lbs ( 60\" ).");
	});		
	
	//function that handles a contact form

		
		var $first = $('#first');
		var $last = $('#last');
		var $phone = $('input#phone');
		var $email = $('input#email');
		var $message = $('#message');
		
		$('.button').click(function(){
		
			var ok = true;
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
			if($first.val().length < 3 || $first.val() == 'First'){
				$("p#error").css("display","block");
				$("p#error").html("Please enter your full first name.");
				ok = false;
			}
			
			if($last.val().length < 3 || $last.val() == ''){
				$("p#error").css("display","block");
				$("p#error").html("Please enter your full last name.");
				ok = false;
			}
			
			if($phone.val().length < 3 || $phone.val() == ''){
				$("p#error").css("display","block");
				$("p#error").html("Please enter a valid phone number.");
				ok = false;
			}
			
			if(!emailReg.test($email.val())){
				$("p#error").css("display","block");
				$("p#error").html("Please enter a valid email");
				ok = false;
			}
			
			if($message.val().length < 5 || $message.val() == ''){
				$("p#error").css("display","block");
				$("p#error").html("Please enter a message.");
				ok = false;
			}
			
			if(ok){
				
				$.ajax({
					type: 'POST',
					url: 'http://gulfcoastcranes.com/bin/process.php',
					data: 'first=' + $first.val() + '&last=' + $last.val() + '&phone=' + $phone.val() + '&email=' + $email.val() + '&message=' + $message.val(),
					success: function(){
						$('#success').css("display","block");
						$('#success').html("Message Sent!").hide().fadeIn(2500, function() {  
							$('#success').append(" We will be in touch.");
							$(this).delay(5000).fadeOut(2000);
						});
						
						// reset
						$(':input','#quoteBox')
							.not(':button, :submit, :reset, :hidden')
							.val('')
					}
				});
				
			}
			
			return false;
		
		});
		


	
});
