window.vBulletin=window.vBulletin||{};window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=$.merge(window.vBulletin.phrase.precache,["vote_failed","vote_now","voters_lower"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["maxpolloptions"]);(function(A){A(document).ready(function(){function E(F){var I=window.vBulletin.options.get("maxpolloptions"),H=(I>3)?3:I;A('[name="viewpollresults"]',F).live("click",function(L){L.preventDefault();var K=A(this).attr("data-nodeid"),J=A(this).closest("form");A.get(pageData.baseurl+"/poll/get",{nodeid:K},function(M){B(J,M)},"json")});A('[name="backtopoll"]',F).live("click",function(K){K.preventDefault();var J=A(this).parents(".list-item-body").eq(0);J.find("div.pollresults").addClass("hide");J.find("form.poll").show()});A("a#addanswer",F).live("click",function(K){var L=A(".polloptioncontainer:first").clone(),J=A(".polloptioncontainer:not(:hidden)",F).length;L.css("display","table").find("input").attr("name","polloptions[new][]").val("").placeholder();A(this).prev(".polloption-list").append(L.css("display","")).find(".polloptioncontainer:last input").focus();if(J+1==I){A(this).hide()}return false});A(".polloptioncontainer button.remove",F).live("click",function(){var J=A(".polloptioncontainer:not(:hidden)",F).length;A(this).closest(".polloptioncontainer").remove();A("a#addanswer",F).show();return false});A(".pollsettings .timeout input").live("click",function(J){A(this).closest(".polloptions-container").next(".datepickercontainer")[this.checked?"removeClass":"addClass"]("hide")});A("form.poll",F).live("submit",function(M){M.preventDefault();var J=A(this);var L=J.find('[name="polloptionid"]:checked').val();var K=[];J.find('[name="polloptionids[]"]:checked').each(function(){K.push(A(this).val())});A.post(J.attr("action"),{polloptionid:L,"polloptionids[]":K},function(O){if(O==false){openAlertDialog({title:vBulletin.phrase.get("vote_now"),message:vBulletin.phrase.get("vote_failed"),iconType:"warning"})}else{B(J,O);var N=J.parent();A("div.pollresults",N).find('[name="backtopoll"]').remove()}},"json")});A(".pollresults-data tr td.pollvoter-cell .voter-icon").live("click",function(){var J=A(this);if(J.find(".voters").is(":visible")){return false}A(".pollresults-data tr td.pollvoter-cell .voter-icon .voters").hide();var M=J.attr("data-node-id");var L=J.attr("data-polloption-id");var K=J.closest("form");A.get(pageData.baseurl+"/poll/get-voters",{nodeid:M,polloptionid:L},function(N){if(N){if(!N.error){C(K,N,L,J)}else{D({message:N.error,type:"error"},J)}}else{D({message:"Error retrieving voters.",type:"error"},J)}},"json")}).find(".voters").live("click",function(J){J.stopPropagation();return true});if(A(".polloptioncontainer.new",F).length>0){for(var G=0;G<H-1;G++){A("a#addanswer",F).click()}if(H==I){A("a#addanswer",F).hide()}}}vBulletin.conversation.bindEditFormEventHandlers("poll");function D(H,G){var I=G.find(".voters");if(H.message){var F=A("<span />").addClass(H.type).text(H.message);I.html(F)}else{I.html(H.voters)}I.fadeIn("slow");A("body").bind("click.voterpopup",function(J){if(A(J.target).closest(".voter-icon").length==0){I.hide();A("body").unbind("click.voterpopup")}})}function C(F,H,K,I){var M=false;if(H.options){B(F,H);var J=H.options[K];if(J){M=true;if(!A.isEmptyObject(J.votersinfo)){var L=[];for(var G in J.votersinfo){L.push('<a href="{0}">{1}</a>'.format(pageData.baseurl+J.votersinfo[G].profileUrl,J.votersinfo[G].username))}D({voters:L.join(", ")},I)}else{D({message:"No one has voted for this option yet. Be the first one to vote.",type:"note"},I)}}}if(!M){D({message:"Error retrieving voters.",type:"error"},I)}}function B(G,K){var F=G.parent();var H=K.options;for(var I in H){var J=A(".pollresults-option-"+H[I].polloptionid);J.find(".title").html(JShtmlEncode(H[I].title));J.find(".bar-container .bar").css("width",H[I].percentage+"%");J.find(".percentage").html(H[I].percentage+"%");J.find(".votes span").html(H[I].votes)}A(".pollresults .pollvote-count span",F).html(K.poll_votes);if(K.poll_votes>1){A(".pollresults .pollvote-count label",F).html(vBulletin.phrase.get("voters_lower"))}G.hide();A("div.pollresults",F).removeClass("hide")}E(A("body"))})})(jQuery);