$(function() {

	
	// Social Icons Hover
	$('ul.sociallinks li a').hover(function() {
		$(this).find('img.hover').fadeIn(400);
	}, function() {
		$(this).find('img.hover').fadeOut(400);
	});
	
	$('ul.sociallinks li span').css({"opacity":"0.0"});
	$('ul.sociallinks li span img').css({"display":"none"});

	$('.sharethiswindow .close').click(function() {
		$('.sharethiswindow').fadeOut();
	});
	
	$('ul.sociallinks li.sharethis a').click(function() {
		$('.sharethiswindow').toggle();
		return false;
	});
	
	$('#twitter #twitter_update_list li:last').css({"marginRight":"0px"});
	
	$('#gallery a').hover(function() {
		$(this).find('span').fadeIn(500);
	}, function() {
		$(this).find('span').fadeOut(500);
	});
	
	
	$('.contactform #submit').remove();
    $('.contactform .submit').append('<input type="button" name="submit" id="submit" value="&nbsp;" />');
    	
    $('.contactform #submit').click(function() {
        var name = $('.contactform input#name').val();
        var email = $('.contactform input#email').val();
        var phone = $('.contactform input#phone').val();
        var message = $('.contactform textarea#message').val();
        
        var formlocation = $('.contactform').attr("action");
       

        $.ajax({
            type: 'post',
        	url: formlocation,
        	data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&message=' + message,

            success: function(results) {
        	
        	$('label.name').html('Name');
        	$('label.email').html('Email');
        	$('label.phone').html('Telephone');
        	$('label.message').html('Please let us know your desired Date, Time, Number of Guests etc.');
        	$('label.name').parent('p').removeClass('error');
        	$('label.email').parent('p').removeClass('error');
        	$('label.phone').parent('p').removeClass('error');
        	$('label.message').parent('p').removeClass('error');
        	
        	var result_name = results.search('name');
        	if(result_name != -1) {
        		$('label.name').parent('p').addClass('error');
            	$('label.name').html('Please add a name');
        	}
        	
        	var result_email = results.search('email');
        	if(result_email != -1) {
            	$('label.email').parent('p').addClass('error');
            	$('label.email').html('Email looks wrong!');
        	}
        	
        	var result_phone = results.search('phone');
        	if(result_phone != -1) {
            	$('label.phone').parent('p').addClass('error');
            	$('label.phone').html('No Number');
        	}
        	
        	var result_message = results.search('message');
        	if(result_message != -1) {
            	$('label.message').parent('p').addClass('error');
        	}
        	
        	var result_success = results.search('success');
        	if(result_success != -1) {
            	$('.contactform .success').css({"opacity":"0.8"});
            	$('.contactform .success').fadeIn();
        	}
        	
            }
        }); 
    });
    
    
    $('#subForm .submit').click(function() {
		var testresults;
		var str=$('#hyyuhj-hyyuhj').val();
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str)) { testresults=true; } else { testresults=false; }
		if(testresults == true) {  } else { $('#subForm small').remove(); $('#subForm').append('<small style="line-height:20px;display:block;">Please enter a valid email address</small>'); return false; }
	});
    
    $('.success').click(function() { $(this).fadeOut();  });

	$('.taf_email_your').hide();
	$('.tellafriend textarea').hide();
	$('#bottomboxes .widgets .widget').css({"height":"82px"});

	$('.tellafriend input').focus(function() {
		$('.taf_email_your').slideDown();
		$('.tellafriend textarea').slideDown();
		$('#bottomboxes .widgets .widget').animate({"height":"232px"});
		$('.tellafriend .submit').animate({"marginTop":"76px"});
		$('.tellafriend .close').fadeIn();
	});
	
	$('.tellafriend .close').click(function() {
		$('.taf_email_your').slideUp();
		$('.tellafriend textarea').slideUp();
		$('#bottomboxes .widgets .widget').animate({"height":"82px"});
		$('.tellafriend .submit').animate({"marginTop":"0px"});
		$(this).hide();
		return false;
	});
	
	$('#subForm input').focus(function() {
		if($(this).attr("value") == "Your email please") { $(this).attr("value",""); }
	});
	$('#subForm input').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Your email please"); }
	});
	$('.tellafriend #taf_email').focus(function() {
		if($(this).attr("value") == "Their email please") { $(this).attr("value",""); }
	});
	$('.tellafriend #taf_email').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Their email please"); }
	});
	$('.tellafriend #taf_email_your').focus(function() {
		if($(this).attr("value") == "Your email please") { $(this).attr("value",""); }
	});
	$('.tellafriend #taf_email_your').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Your email please"); }
	});
	
	
	$('.tellafriend #taf_submit').remove();
    $('.tellafriend').append('<input type="button" name="taf_submit" id="taf_submit" class="submit" value="&nbsp;" />');
    	
    $('.tellafriend #taf_submit').click(function() {
        var email = $('.tellafriend input#taf_email').val();
        var youremail = $('.tellafriend input#taf_email_your').val();
        var message = $('.tellafriend textarea#taf_message').val();
        
        var formlocation = $('.tellafriend').attr("action");
       

        $.ajax({
            type: 'post',
        	url: formlocation,
        	data: 'email=' + email + '&youremail=' + youremail + '&message=' + message,

            success: function(results) {
            var result_success = results.search('success');
        	if(result_success != -1) {
            	$('.taf_email_your').slideUp();
				$('.tellafriend textarea').slideUp();
				$('#bottomboxes .widgets .widget').animate({"height":"82px"});
				$('.tellafriend .submit').animate({"marginTop":"0px"});
				$('.tellafriend .close').hide();
				$('#taf_email').val("Thank you, sent!");
			} else {
            	$('.results').html("");
            	var resulttext = "<div class='results'>"+results+"</div>";
        		$('.tellafriend').append(resulttext);
        	}
            }
        }); 
    });


});