
	
	$j.scf.behavior.add("smlPoll", {
	attach: function(el, settings, div) {
		var sml = $j.scf.smartlet.get(el);
		var sbm = $j("#" + el.id + " input[type=submit]");
		
		var ajaxBtn = $j("<button type=\"button\">" + sbm.val() + "</button>");
		
		sbm.replaceWith(ajaxBtn);
		
		ajaxBtn.click(
			function() {
				var radio = $j("[name=" + el.id + "]:checked");
				
				if (radio.length == 0) {
					alert("Make a selection first"); return;
				}
				var s="";
				
				radio.each(function(i,el){
					if(s.length > 0) s += ",";
					s += $j(el).val();
				});
				
				sml.set("vote", s);
				sml.ajax({
					busy: $j("#" + sml.id("frm")),
					ready: function() {
						var tally = sml.get("tally");
						if (tally.length !=0) {
							$j("#" + el.id + " form").replaceWith(tally);
						}
					}
				});
			}
		);
		
		div.find(".smlWarning").click(function(event){
			if (!confirm("You will not be able to vote after viewing the current results. Continue anyway?")) {
				event.preventDefault();
			}
		});
	}
});
