// JavaScript Document

function fillForm() {

$('[name=name]').attr('value', 'name..').focus(function(){
														if ($(this).attr('value') == 'name..'){
															$(this).attr('value', '').css({'color':'#333'})
														}
														}).blur(function(){
														if ($(this).attr('value') == ''){
															$(this).attr('value', 'name..').css({'color':'#999'});
														}
														});


$('[name=emailAddress]').attr('value', 'email..').focus(function(){
														if ($(this).attr('value') == 'email..'){
															$(this).attr('value', '').css({'color':'#333'})
														}
														}).blur(function(){
														if ($(this).attr('value') == ''){
															$(this).attr('value', 'email..').css({'color':'#999'});
														}
														});

$('[name=phoneNumber]').attr('value', 'phone..').focus(function(){
														if ($(this).attr('value') == 'phone..'){
															$(this).attr('value', '').css({'color':'#333'})
														}
														}).blur(function(){
														if ($(this).attr('value') == ''){
															$(this).attr('value', 'phone..').css({'color':'#999'});
														}
														});

$('[name=notes]').attr('value', 'additional information..').focus(function(){
														if ($(this).attr('value') == 'additional information..'){
															$(this).attr('value', '').css({'color':'#333'})
														}
														}).blur(function(){
														if ($(this).attr('value') == ''){
															$(this).attr('value', 'additional information..').css({'color':'#999'});
														}
														});

														$('[name=submit]').val('Send').css({'color':'#333'});
}

$(function() {



fillForm();
$('#slideCont ul li:last').css({'border-right-style':'none'});

$('#submitBtn').click(function(e) {
							   e.preventDefault();
							   var tickEmail = $('[name=checkEmail]').is(':checked'),
							   tickPhone = $('[name=checkPhone]').is(':checked'),
							   name = $('[name=name]').val(),
							   phone = $('[name=phoneNumber]').val(),
							   email = $('[name=emailAddress]').val(),
							   comments = $('[name=notes]').val();
								
							   	if (name == '' || name == 'name..') {
								$('.formError').html('Please enter a name').slideDown();
								$('[name=name]').focus();
									setTimeout(function() {
														$('.formError').slideUp();
														}, 4000);
									return false;
								 }
								 
								 if (!(validateNames(name))) {
															 $('.formError').show().html('Invalid name, please try again').slideDown();
															 $(['name=name']).focus();
									setTimeout(function() {
														$('.formError').slideUp();
														}, 4000);
									return false;
								 }
								 
								 
								 if (tickEmail == true) {
									 if (email == '' || email == 'email..') {
									 						$('.formError').html('You have chosen to be contacted by email but not left an email address.  Please amend this.').slideDown();
															$('[name=emailAddress]').focus();
									 setTimeout(function() {
														$('.formError').slideUp();
														}, 6000);
 									return false;
								 }
								 }
								 
								 
								 if (tickPhone == true) {
									 if (phone == '' || phone == 'phone..') {
									 						$('.formError').html('You have chosen to be contacted by phone but not left a phone number.  Please amend this.').slideDown();
															$('[name=phoneNumber]').focus();
									 setTimeout(function() {
														$('.formError').slideUp();
														}, 6000);
 									return false;
								 }
								 }
								 								 
								 if (email != '' && email != 'email..') {
								 if (!(validateEmail(email))) {
															 $('.formError').show().html('Invalid email, please try again').slideDown();
															 $('[name=emailAddress]').focus();
									setTimeout(function() {
														$('.formError').slideUp();
														}, 4000);
									return false;
								 }
								 }
								 
								 
								 if (phone != '' && phone != 'phone..') {
								 if (!(validatePhone(phone))) {
															 $('.formError').show().html('Invalid number, please try again').slideDown();
															 $('[name=phoneNumber]').focus();
									setTimeout(function() {
														$('.formError').slideUp();
														}, 4000);
									return false;
								 }
								 }
								 
								 
								 if (email == '' || email == 'email..'){
									 email = 'Didn\'t leave one';
								 }
								 
								 if (phone == '' || phone == 'phone..'){
									 phone = 'Didn\'t leave one';
								 }
								 
								 if (comments == '' || comments == 'additional information..') {
									comments = 'Didn\'t leave any info'; 
								 }
								 								 
								 
								 dataString = 'name='+name+'&phone='+phone+'&email='+email+'&mess='+comments;

								 $.ajax({
										type:'POST',
										url:'scripts/sendEmail.php',
										data:dataString,
										success:function(data) {
											if (data == 1){
											$('#sideColConForm').slideUp();
											setTimeout(function(){
																$('<div>').addClass('thankyou').prependTo('#conHolder').slideDown('slow');
																$('<div>').addClass('thankyouHeader').html('Thank you.').appendTo('.thankyou');
																$('<div>').addClass('thankyouText').html('We will be in contact soon.').appendTo('.thankyou');
																}, 1500)
											setTimeout(function() {
																$('.thankyou').slideUp();
																fillForm();
																$('#sideColConForm').prependTo('#conHolder').slideDown()
																}, 10000);
										}else{
											$('.formErrorEmail').html('Uh oh, there was a problem.<br />Your details were not sent.<br />Please try again.').slideDown();
											setTimeout(function(){
																$('.formErrorEmail').slideUp();
																}, 4000);
										}
										}
										});
							   });



$('li.footerLinks:last').css({'border-right-style':'none', 'padding-right' : '0px'});

$('li.menuItems:last').css({'border-right-style':'none'});
$('li.menuItems:first').css({'margin-left':'3px'});
$('li.menuItems ul li:first').css({'border-top-style':'none'});
$('li.menuItems ul li:last').css({'border-bottom-style':'none'});

$('li.menuItems').hover(function() {
									var width = $(this).innerWidth();
									if($.browser.msie && $.browser.version=="7.0"){
									  $('ul', this).css({'width':width, 'margin':'24px 0 0 -50px'}).show();
									  $('ul.menuUL', this).css({'width':width, 'margin':'24px 0 0 -76px'}).show();
									}else{
									  $('ul', this).css({'width':width, 'margin':'10px 0 0 -21px'}).show();
									}
									  },function() { 
									  $('ul', this).hide(); 
									  })
										.filter(':last').css({'border-right-style' : 'none'});

$('li.menuItems ul li').hover(function() {
					$(this).css({'background-color' : '#AB4545', 'color' : '#000'});
											}, function() {
					$(this).css({'background-color' : '#000', 'color' : '#fff'});
											})


function signalContact(info, msg) {
	if (info == 'website'){
	$('[name=notes]').attr('value', 'Please contact me about a website similar to \''+msg+'\'.').css({'color':'#333'});
	}else if (info == 'service'){
	$('[name=notes]').attr('value', 'Please contact me about \''+msg+'\'.').css({'color':'#333'});
	}else if(info == 'maintenance'){
	$('[name=notes]').attr('value', 'Please contact me about website \''+msg+'\'.').css({'color':'#333'});
	}else if(info == 'flare'){
	$('[name=notes]').attr('value', 'Please contact me about adding some \'flare\' to my website.').css({'color':'#333'});
	}else if(info == 'takeaway'){
	$('[name=notes]').attr('value', 'Please contact me about the \'takeaway website\'').css({'color':'#333'});
	}
	$('#contactBG').animate({backgroundColor : '#f90'},1000).animate({backgroundColor : '#E8E9EE'}, 2000);
}

$('span.takeawayClick').click(function() {
									  var id = $(this).attr('id');
									  signalContact('takeaway', id);
									  });

$('span.clickForFormFlare').click(function() {
									  var id = $(this).attr('id');
									  signalContact('flare', id);
									  });

$('span.clickForFormMaint').click(function() {
									  var id = $(this).attr('id');
									  signalContact('maintenance', id);
									  });

$('.portBtns').each(function() {
							$(this).click(function(){ 
				  					var id = $(this).attr('id');
									signalContact('website', id);
							 });
				  });

$('.websitesBtnRightCont, .websitesBtnRightContH').each(function() {
										 $(this).hover(function() {
															$(this).css({'background-color' : '#fff'})
																}, function(){
													$(this).css({'background-color':'#efefef'})
										 });
										 });

$('.websitesBtnRightCont').each(function() {
										 $(this).click(function() {
																var id = $(this).attr('id');
																signalContact('service', id);
																});
										 });

$('.indexPortIndReq').click(function() {
									 var name = $(this).siblings('.indexPortIndTitle').text();
									 signalContact('website', name);
									 });

$('.btnRightContReq').click(function() {
									 var name = $(this).parents('#mBod').find('#caseHeader').text();
									 signalContact('website', name);
									 });

var top = 115;
$('.portIndTab').css({'margin-top' : top});

$('.portIndImg').each(function() {
							   var tab = $(this).find('.portIndTab'),
							   height = tab.height() - 30,
							   dist = parseInt(top - height);
							   $(this).mouseover(function() {
							   				$(this).find('.portIndTab').stop().animate({marginTop : dist}, 100);
														  }).mouseout(function() {
											$(this).find('.portIndTab').stop().animate({marginTop : top}, 300);				  
														  });
							   });


$('.leftPlus_details').hide();

$('#sideColFeatCon li').each(function() {
				
				var i = $(this),
				header = i.find('.liHeader'),
				info = i.find('.leftPlus_details'),
				title = i.find('.itemHeader'),
				delay = 500;
				
				header
				.css({'cursor' : 'pointer'});
				
				header.bind('click', function() {
					if ($(this).children('div').hasClass('minus')) {										 
							$(this).siblings(info).slideUp();
							$(this).children('.minus').removeClass('minus').addClass('plus');
							return false;
					}else{
							i
							.find('.plus')
							.removeClass('plus')
							.addClass('minus');
							info
							.slideDown()
							return false;
					}
								});
				
				$('.leftPlus_backUp')
				.css({'cursor' : 'pointer'})
				.bind('click', function() {
							$(this)
							.parent(info)
							.slideUp();
							
							$(this)
							.parent()
							.parent()
							.find('.minus')
							.removeClass('minus')
							.addClass('plus');
							return false;
								});
							})


$('.indexPortIntView, .indexPortIndReq, .btnRightCont, .btnRightContReq').hover(function() {
									 $(this).css({'background-color':'#fff'}); 
									  }, function() {
										  $(this).css({'background-color':'#e8e9ee'});
									  })

$('.portBtns').hover(function() {
							$(this).css({'background-color':'#fff'}); 
								}, function() {
							$(this).css({'background-color':'#f7f7f7'});
								});

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


})
