$(document).ready(function(){
	$(".results > ul").livequery(function(){
	$(this).tabs();
	});
	$(".answerButtons a").livequery(function(){
		$(this).click(function(){		    
			var elmPicked=$(this).attr("title").substr(5);
			var opPicked=$(this).attr("title");
			var parentElm=$(this).parents("div").eq(2);			
    			$(this).addClass("pickedOptions");    			
			$(parentElm).find("."+elmPicked).removeClass("hide");	
			$(parentElm).find(".options a").each(function(){
				if($(this).attr("title")!=opPicked)
				{
					$(this).removeClass("pickedOptions");
					$(parentElm).find('.'+$(this).attr("title").substr(5)).addClass("hide");
					if(opPicked=="show results")
					{$(parentElm).find(".image").addClass("hide");
					$(parentElm).find(".results > ul").tabs('load',0);
					}
					else{$(parentElm).find(".image").removeClass("hide");}
				}
			})
		});
	});	        
	$(".voteForm li table").livequery(function(){
		$(this).click(function(){
			$(this).find('input:radio').attr("checked", "checked");
			$(this).parents('form').submit();
			$(this).parents('form').reset();
			
		});		
	});
	$('.voteForm').livequery(function(){
		var clickOp=$(this).parent().parent().find("a:contains('Results'):first");
		$(this).ajaxForm(
		{success:
			function(response,status){
			clickOp.click();
				}
		});
	});		
	$(".pickForm li table").livequery(function(){
		$(this).click(function(){
			$(this).find('input:radio').attr("checked", "checked");
			$(this).parents('form').submit();
			$(this).parents('form').reset();
		});
	});	
	$("a.edit").click(function(){
		var id=$(this).attr('id')+'1';
		$('#'+id).removeClass('hide');
	});
	$("a.cancel").click(function(){
		$(this).parents("div:eq(0)").addClass("hide");		
	});
	$(".delete a").click(function(){
		var answer=confirm("Are you sure you want to delete this poll?");
		if(answer)
		{return true;}
		else
		{return false;}
	});
	$(".remove a").click(function(){
		var answer=confirm("Are you sure you want to remove this contact?");
		if(answer)
		{return true;}
		else
		{return false;}
	});
	
});