$(document).ready(function()
{	
    $('.cameronbox').live('click', function(event)
    {
        event.preventDefault();
        $('.darken_screen').height($(document).height());
        var div = $(this).attr('href');
        $('body').append($(div).clone(true).addClass('cameronbox_box').hide().fadeIn(400));
        $('.popup_overlay').css('top', $(document).scrollTop() + 100 + 'px')
    });
    
    $('.close_popup').live('click', function()
    {
        $('.cameronbox_box').fadeOut(400, function() { $(this).remove() });
    });
    	
	var color = $('.email_share_success_story input').eq(0).css('border-color');
	$('.email_share_success_story input, .email_share_success_story textarea').live('focus', function() { $(this).css('border-color', color); });
	$('.email_share_success_story').submit(function(event)
	{
		$('input, textarea', this).each(function()
		{
			if($(this).val() == $(this).attr('placeholder') || $.trim($(this).val()) == '')
			{
				event.preventDefault();
				$(this).css('border-color', 'red');
				$('.cameronbox_box .popup_error').text('Please enter valid information. Errors were found and fields you need to fix are outlined in red.')
                // console.log($(this).val());
			}
			else if($(this).attr('name') == 'your_email' || $(this).attr('name') == 'friends_email')
			{
				if(!$(this).val().match(/.+@.+\..+/))
				{
					event.preventDefault();
					$(this).css('border-color', 'red');
					$('.cameronbox_box .popup_error').text('Please enter valid emails. Errors were found and fields you need to fix are outlined in red.')
                    // console.log($(this).val());
				}
			}
			else
			{
				$(this).css('border-color', color);
			}
		});
	});
});
