$(document).ready(function(){

	popup();

});

function popup(){
	
	$("body").append("<div class='overlay'></div>");
	$(".overlay").animate({opacity:"0"},"slow");
	$("#voting").prepend("<a class='close' href='#'>Close</a>");
	$(".popup").append("<a class='close' href='#'>Close</a>");
	var docWidth = $(document).width();
	var docHeight = $(document).height();
	var voteTop = docHeight/2 - $("#voting").height()/2;
	var voteLeft = docWidth/2 - $("#voting").width()/2;
	var popTop = 200;//docHeight/2 - $(".popup").height()/2;
	var popLeft = docWidth/2 - $(".popup").width()/2;
	
	$(".galleryVoteBut, .showPopup").click(function(e){
		e.preventDefault();
		var overlayCss = {
			"width":docWidth,
			"height":docHeight
		}
		var voteCss = {
			"top":voteTop,
			"left":voteLeft
		}
		var popCss = {
			"top":popTop,
			"left":popLeft
		}
		$(".overlay").css(overlayCss).animate({opacity:"0.8"},"slow");
		$("#voting").css(voteCss).fadeIn("slow");
		$(".popup").css(popCss).fadeIn("slow");
	});
	
	$(".close, .overlay").click(function(e){
		e.preventDefault();
		$("#voting, .popup").hide("");
		$(".overlay").animate({opacity:"0"},"slow");
		$(".overlay").css({"height":"0px","width":"0px"});
	});
	
}

function setVote (entrant) {
	 $('#competitionentrant_id').attr('value', entrant);
}