fl.voting = {
	'toggle_class': 'voting',
	'vote_url'    : '/next-door-search/vote.php',
	'thanks_copy' : [
			'<h5>Thanks For Voting!</h5>',
			'<p>We\'ll let you know when the results are in.</p>',
			'<p>In the meantime, be sure to check our current <a target="_blank" href="/fleshjack-boys/" title="Fleshjack Boy series Fleshjacks">Fleshjack Boys</a>.</p>'
		].join(''),
	'voted_copy'  : [
			'<h5>You already voted</h5>',
			'<p>You have already voted, but we appreciate your enthusiasm!</p>',
			'<p>We\'ll let you know when the results are in.</p>'
		].join(''),
	'error_copy'  : [
			'Oops!  Looks like you forgot to enter your email address.'
		].join('')
};


$(function () {
	// change interface over to voting when clicked
	$('.button.vote,.cancel').click(function () {
		$(this).closest('.tile,.details').toggleClass(fl.voting.toggle_class);

	// submitting vote
	}).closest('.tile,.details').find('.follow-up .button').click(function () {
		// unless of course they clicked cancel..
		if ( $(this).hasClass('cancel') ) {
			return false;
		}

		var payload = {
		 	email: $(this).siblings('.email').val(),
			slug:  $(this).siblings('[name="slug"]').val()
		};
		var $t = $(this);
		if (!payload.email) {
			alert(fl.voting.error_copy);
			return false;
		};

		$.post(fl.voting.vote_url, payload, function (r) {
			$t.closest('.follow-up').html((r == '1') ? fl.voting.thanks_copy : fl.voting.voted_copy);
		});

	// email field click, remove default text once
	}).siblings('.email').click(function () {
		$(this).val('').unbind('click');
	});

	// detail/preview view
	$('#stage').siblings('a').mouseover(function () {
		$('#stage').attr('src', $(this).find('img').attr('src').replace(/thumb/, 'large'));
	});
});

