$(function(){
	$(".hiddencomment").click(function(){
		
		$(this).parent().next('div').show();
		
		$(this).parent().hide();
		
		return false;
	});
});

$(function(){
$("a.user_fact_vote_up").click(function(){
 //get the id
 the_id = $(this).attr('id');

 // show the spinner
 $("span#user_fact_btns_"+the_id).html("<img src='http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/img/spinner.gif'/>");

 //fadeout the vote-count 
 $("span#user_fact_votes_"+the_id).fadeOut("fast");

 //the main ajax request
  $.ajax({
   type: "POST",
   data: "action=vote_up&id="+$(this).attr("id"),
   url: "http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/user_fact_vote.php",
   success: function(msg)
   {
    $("span#user_fact_votes_"+the_id).html(msg);
    //fadein the vote count
    $("span#user_fact_votes_"+the_id).fadeIn();
    //remove the spinner
    $("span#user_fact_btns_"+the_id).remove();
   },
	timeout: 5000,
	complete: function() {
	    //remove the spinner
	    $("span#user_fact_btns_"+the_id).remove();
	}
  });
 });
});
$(function(){
$("a.user_fact_vote_down").click(function(){
 //get the id
 the_id = $(this).attr('id');

 // show the spinner
 $("span#user_fact_btns_"+the_id).html("<img src='http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/img/spinner.gif'/>");

 //fadeout the vote-count 
 $("span#user_fact_votes_"+the_id).fadeOut("fast");

 //the main ajax request
  $.ajax({
   type: "POST",
   data: "action=vote_down&id="+$(this).attr("id"),
   url: "http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/user_fact_vote.php",
   success: function(msg)
   {
    $("span#user_fact_votes_"+the_id).html(msg);
    //fadein the vote count
    $("span#user_fact_votes_"+the_id).fadeIn();
    //remove the spinner
    $("span#user_fact_btns_"+the_id).remove();
   },
	timeout: 5000,
	complete: function() {
		//remove the spinner
		$("span#user_fact_btns_"+the_id).remove();
	}
  });
 });
});

$(document).ready(function(){  
	$("form#add_user_fact_form").submit(function(){ 
		$("#add_user_fact_response").html("<img src='http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/img/spinner.gif'/>");
	 	 $.ajax({
		   type: "POST",
		   data: ({fact : $("#add_user_fact_content").val(), country_code : $("#country_code").val(), user_name : $("#add_user_fact_name").val(), user_email : $("#add_user_fact_email").val()}),
		   url: "http://www.miniatlas.se/wp-content/themes/Miniatlas2/user_fact/add_user_fact.php",
		   dataType: "html",
		   success: function(msg)
		   {
				$("#add_user_fact_response").html(msg);
				if(msg == "<p>Tack! Ditt bidrag väntar nu på moderering och kommer synas på sidan om en till två dagar.</p>") {
					$("#add_user_fact_form").hide();
				}
		   }
		  });
		return false;
	 });
});
