﻿FloatingVoter = function()
{

	var _obj;
	var _generalErrors = 0;
	var _callee;
	return {
		init : function(obj)
		{
			_obj = obj;

			$(document).ready(function(){
				if($el("floatingVoter") == null)
				{
					$("body").append("<div id=\"floatingVoter\"></div>");
				}
				$("#floatingVoter").hide();
				$(".like-link a").each(function(){
					var url = $(this).attr("href");
					$(this).click(function(){
						FloatingVoter.launch({url:url, callee:$(this)});
					});
					$(this).attr("href", "javascript:void(0)");
				});
			});

		},
		launch : function(obj)
		{
			_callee = obj.callee;

			$.ajax({
				url: obj.url,
				beforeSend: function(xhrObj){
					xhrObj.setRequestHeader("X-Request-Type", "application/remote-form");
					waitMessage($so("TextRemoteWaitMessage"));
				},
				error: function(XMLHttpRequest, textStatus, errorThrown)
				{
					generalError($so("ErrorGeneralNetworkIssue"));
				},
				success: function(data)
				{
					$("#floatingVoter").html(data);
					FloatingVoter.render();
				},
				complete: function()
				{
					killWaitMessage();
				}
			});
		},
		render : function()
		{
		$("#floatingVoter").hide();
			blockForms(false);
			DropShadows.addShadow($el("floatingVoter"), "drop-shadow-message");
			addCloseToPopup("#floatingVoter", FloatingVoter.close);

			jQuery('#floatingVoter').center();

			RemoteVote.init(_obj, FloatingVoter.voted);

			replaceSubmits($el("floatingVoter"));

			replaceLinks($el("#floatingVoter"));

			$("#floatingVoter").show();

			RemoteVote.vote();

		},
		voted : function(obj)
		{
			_callee.find(".count").text(obj.count);
			FloatingVoter.close();
		},
		close : function()
		{
			$("#floatingVoter").hide();
			unBlockForms(false);
		}
	}
}();

