$(function() {

	$('#tafscreen').css({
		width: '100%',
		height: '100%',
		backgroundColor: '#000000',
		opacity: '0.75',
		position: 'fixed',
		top: '0px',
		left: '0px',
		display: 'none',
		zIndex: 100000
	});

	$('#ftaf input, #ftaf textarea, #fnsu input').example(function() {
		return $(this).attr('title');
	});

	$('#tellafriend, #tellafriend-thanks').css({
		position: 'fixed',
		zIndex: 100001,
		top: '150px',
		left: (($(document).width()-$('#tellafriend').width())/2)+'px',
		display: 'none'
	});
	
	$('#tellafriend-thanks').css('top', '300px');
	
	$('.wtaf_close, #tafscreen').click(function() {
		if (shopify_jump() !== true) {
			$('#tellafriend, #tellafriend-thanks, #tafscreen').hide();
		}
	});
	$('#wtaf_open').click(function() {
		$('#tellafriend, #tafscreen').show();
	});
	
	$('#ftaf').submit(function() {
		$('#ftaf').ajaxSubmit({
			success: function() {
				$('#tellafriend').hide();
				$('#tellafriend-thanks').show();
				setTimeout(function() {
					if (shopify_jump() !== true) {
						$('#tellafriend-thanks, #tafscreen').hide();
					}
				}, 10000);
				$('#ftaf input, #ftaf textarea').each(function() {
					$(this).val($(this).attr('title'));
				});
			}
		});
		return false;
	});
	
	$('#esuscreen').css({
		width: '100%',
		height: '100%',
		backgroundColor: '#000000',
		opacity: '0.75',
		position: 'fixed',
		top: '0px',
		left: '0px',
		display: 'none',
		zIndex: 100000
	});
	
	$('#esumodal').css({
		position: 'fixed',
		zIndex: 100001,
		top: '150px',
		left: (($(document).width()-$('#tellafriend').width())/2)+'px',
		display: 'none'
	});
	
	$('#esumodal, #esuscreen').click(function() {
		$('#esumodal, #esuscreen').hide();
	});
	
	$('#mc-embedded-subscribe').click(function() {
		if ($('#mce-EMAIL').val() != '') {
			$('#esumodal, #esuscreen').show();
		}
	});
	
});

function shopify_jump()
{
	if (location.pathname == '/send-to-friend') {
		location.href = 'https://kfurtadowines.myshopify.com/cart';
		return true;
	} else {
		return false;
	}
}