// JavaScript Document

$(function() {

if (jQuery.browser.mozilla){
	$('#contactBanner').css({'margin-top' : '-20px'});
}


//home page image transition plugin
$('#imgSlide_cont').crossSlide({
	sleep:5,
	fade: 3
}, [
  { src: 'images/m_pic/paladino_excavation_img1.jpg' },
  { src: 'images/m_pic/paladino_excavation_img2.jpg' },	
  { src: 'images/m_pic/paladino_excavation_img3.jpg' },
  { src: 'images/m_pic/paladino_excavation_img4.jpg' }
]);


//mouseover left navigation
$('#navLeft_cont li a').hover(function() {
									   $(this).css({'cursor' : 'pointer'});
									   })
$('#navLeft_cont li').hover(
							function(){
								$(this).css({'background-color' : '#830101', 'cursor' : 'pointer'})
								.find('.navLeft_link .item').css({'color' : '#ffcc14'});
									 },
									 function() {
										if (!($(this).hasClass('selected'))){
										 $(this).css({'background-color' : '#4d2400'})
										 .find('.navLeft_link .item').css({'color' : '#d77d31'});
															 }
							})
							
				
$('[name=submit]').click(function(e) {
								  e.preventDefault();
								 var name = $('[name=name]').val(),
								 phone = $('[name=phone]').val(),
								 email = $('[name=email]').val();
								 
								 if (name == '') {
									$('#errorName').html('You need to enter a name');
									setTimeout(function() {
														$('#errorName').html('');
														}, 2000);
									return false;
								 }
								 
								 if (phone == '' && email == '') {
									 $('#errorEmail').html('Please enter an email or <br /> phone number');
									 setTimeout(function() {
														$('#errorEmail').html('');
														}, 2000);
 									return false;
								 }
								 
								 if (!(validateNames(name))) {
															 $('#errorName').show().html('Invalid name, please try again');
									setTimeout(function() {
														$('#errorName').html('');
														}, 2000);
									return false;
								 }
								 
								 if (!(phone == '')) {
								 if (!(validatePhone(phone))) {
															 $('#errorPhone').show().html('Invalid number, please try again');
									setTimeout(function() {
														$('#errorPhone').html('');
														}, 2000);
									return false;
								 }
								 }
								 
								 if (!(email == '')) {
								 if (!(validateEmail(email))) {
															 $('#errorEmail').show().html('Invalid email, please try again');
									setTimeout(function() {
														$('#errorEmail').html('');
														}, 2000);
									return false;
								 }
								 }
								 
								 if (email == ''){
									 email = 'Didn\'t leave one';
								 }
								 
								 if (phone == ''){
									 phone = 'Didn\'t leave one';
								 }
								 
								 datastring = 'name='+name+'&phone='+phone+'&email='+email;
								 console.log(datastring);
								 $.ajax({
										type:'POST',
										url:'phpScripts/sendEmail.php',
										data:datastring,
										success:function(data) {
											if (data == 1){ 
											$('.featureContact_cont').fadeOut('fast');
											setTimeout(function(){
																$('<div>').addClass('thankyou').prependTo('#featureContact');
																$('<div>').addClass('thankyou_header').html('Thank you.').appendTo('.thankyou');
																$('<div>').addClass('thankyou_text').html('We will be in contact soon.').appendTo('.thankyou');
																}, 400)
											setTimeout(function() {
																$('.thankyou').hide();
																$(':input').val('');
																$('[name=submit]').val('Send');
																$('.featureContact_cont').prependTo('#featureContact').fadeIn()
																},10000);
										}else{
											$('#errorEmail').html('Sorry, there was a problem<br />dealing with your form.<br />Please try again.');
											setTimeout(function(){
																$('#errorEmail').html('');
																}, 4000);
										}
										}
										
										});
								 		
								  });

$('#loadingDiv')
    .ajaxStart(function() {
		$('#submit').hide();
		var image = $('<img />').attr('src', 'images/ajax-loader.gif').attr('id', 'loadingDiv_img');
        $(this).append(image);
    })
    .ajaxStop(function() {
        $('#loadingDiv_img').hide();					   
		setTimeout(function() {
		$('#submit').show();
							},5000);
    })

$('.featureItems a').hover(function(){
									$(this).css({'text-decoration':'underline'});
									}, function() {
									$(this).css({'text-decoration':'none'});	
									});

$('#footerLinks li:last').css({'border-right-style' : 'none'});
$('#footerLinks li a').mouseover(function() {
										$(this).css({'text-decoration' : 'underline'});
										}).mouseout(function() {
										$(this).css({'text-decoration' : 'none'});	
										});
});
