$(document).ready(function()
{
	var photo_id = $('#var-photo-id').text();
	var base_url = $('#var-base-url').text();

	//mouseover/out controls show/hide (prev-next)
	var config = 
	{
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 400, // number = milliseconds for onMouseOver polling interval    
		over: hide_controls, // function = onMouseOver callback (REQUIRED)    
		timeout: 1500, // number = milliseconds delay before onMouseOut    
		out: show_controls // function = onMouseOut callback (REQUIRED)    
	};
	$('.photo-container').hoverIntent(config);

	//vote for this photo
	$('#vote-container a').click(function(event)
	{
		event.preventDefault();
		$('#product-vote-status-success').hide();
		$('#product-vote-status-failed').hide();
		$('#product-vote-status-invalid').hide();
		
		$('.product-vote-status').slideDown('normal');
		
		var uri_vote = base_url + 'votes/photo/' + photo_id + '/ajax/1337' + Math.floor(Math.random()*9999999);
		$.get(uri_vote, function(data)
		{
			if(data == 'SUCCESS') 
			{
				$('#product-vote-status-success').show();
				
				//update the current amount of votes
				var counter = parseInt($('#product-vote-count').html()); 
				counter++;
				$('#product-vote-count').html(counter);
			}
			else if(data == 'FAILED')
			{
				$('#product-vote-status-failed').show();
			}
			else
			{
				//(data == 'NOT_FOUND')
				$('#product-vote-status-invalid').show(); 
			}
		});
		$('.product-vote-status').slideUp(1);

		$('#vote-container a').unbind('click').click(function()
		{ 
			$('#product-vote-status-success').slideUp('fast');
			$('#product-vote-status-invalid').slideUp('fast');
			$('#product-vote-status-failed').slideUp('fast');
			$('.product-vote-status').hide();
			
			$('#vote-container a').unbind('click').click(function()
			{
				$('#product-vote-status-success').hide();
				$('#product-vote-status-invalid').hide();
				$('.product-vote-status').hide();
				$('#product-vote-status-failed').slideToggle('normal');
				return false; 
			})
			return false;
		});
		$('.product-vote-status').hide();
	    return false;
	});

});

function hide_controls()
{  
	$('#action-browse-prev').fadeOut();
	$('#action-browse-next').fadeOut();
}
function show_controls()
{
	$('#action-browse-prev').fadeIn();
	$('#action-browse-next').fadeIn();
}
