$(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 = docHeight/2 - $(".popup").height()/2;
	var popLeft = docWidth/2 - $(".popup").width()/2;
	*/
			
	$(".galleryVoteBut, .showPopup").click(function(e){
		e.preventDefault();
		
		var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset;
		var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset;
		
		var voteLeft =  (docWidth - $("#voting").width())/2;
		//var voteTop =  (docHeight - $("#voting").height())/2;	
		var voteTop =  scrolledY + 30;
		
		var popLeft = (docWidth - $(".popup").width())/2;
//		var popTop =  (docHeight - $(".popup").height())/2;	
		var popTop =  scrolledY + 30;
		
		//alert ("voteTop = " + voteTop + ", voteLeft = " + voteLeft + ", rollWidth = " + scrolledX + ", rollHeight = " + scrolledY);

		
		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);
}
