(function($) {
$.fn.customToggle = function(speed, callback) {
$(this).toggle(speed, function() {
if(jQuery.browser.msie)
$(this).get(0).style.removeAttribute('filter');
if(callback != undefined)
callback();
});
};
})(jQuery);

$(document).ready(function(){

	$('.showA').click(function()
	{
			
		var parentDiv=$(this).parent().get(0);
	
		if($(parentDiv).find('.answerBody').length<1)
		{
			if($(this).html()=='Show Answers')
			{
				$(this).html('Close Answers');
				var qID=$(parentDiv).attr("id").split('_')[0];
				var d=$(parentDiv).attr("id").split('_')[1];
				var c=$(parentDiv).attr("id").split('_')[2];
			
				$(parentDiv).append('<div id="wait"><img src="http://www.spicypolls.com/assets/js/loading.gif" /></div>');
			   		$.ajax({
					  url: "http://www.spicypolls.com/listing/showQuestionDetails/"+qID+"/"+d+"/"+"/"+c,
					  processData: false,
					  dataType:"html",
					  success:function(data){
					  	$(parentDiv).append(data);
					  	$(parentDiv).find('.answerBody').hide().customToggle('slow');
					  	$('#wait').remove();
					  	}
				});
			}
		}
		else
		{		
			$(parentDiv).find('.answerBody').customToggle('slow');
			if($(this).html()=='Show Answers')
			{
				$(this).html('Close Answers');
			}
			else
			{
				$(this).html('Show Answers');
			}
		}		
	});
});
