How can I deactivate clicking while a function is being run?

How can I deactivate clicking while a function is being run?

I basically want to  not let the function do anything else if something is animating.  If someone clicks too often is messes up some animation I have, because the position of the last clicked element gets changed to an element it doesn't belong to.

Is there a way to set a flag if the click function is running, move the animation code into its own function, and not allow the animation to run if that flag is true?  Or maybe this is a bad way to go.  

I just need to make it safe to click around, so that it doesn't mess up the saved positioning (and thus the animation) when this click function is running.


Thank you.
  1.         $(".clsStartUpNode").click(function() {
  2.              $lastClickedNode = $(this);
  3.              $divID = $(this).attr("id"); // get the attr id inside the div
  4.              $nodeID = $(this).attr("nodeID"); // get the nodeID inside the div
  5.              $nodeLayerNumber = $(this).attr("nodeLayer");
  6.              $nodeTitle = $(this).html();// get the whole div in html format
  7.              CurrentLayer = $nodeLayerNumber; //assign the current layer number to  CurrentLayer
  8.              $nodePosition = $(this).position(); // position = { left: xx, top: xx}

  9.                 //animate main node, clicked node,and mode in child nodes
  10.           if ($divID != "StartUpMainNode") {
  11.                  // set second node data in the breadcrumb
  12.                  $("#NodeTwo").attr("nodeID", $nodeID); // replace $nodeID into "nodeID"
  13.                  $("#NodeTwo").attr("nodeLayer", $nodeLayerNumber);
  14.                  $("#NodeTwo").html("<a nohref alt='" + $nodeTitle + "' title='" + $nodeTitle + "'>" + $nodeTitle + "</a>"); // to show the pointer, used <a> tag
  15.                  if ($nodeLayerNumber < 4) {
  16.                      $CircleNodesLeftPosition = $CircleNodesStartLeftPosition + (($nodeLayerNumber - 1) * 150); // used to calculate the pisition 
  17.                      $("#CircleNodes").css("left", $CircleNodesLeftPosition + "px");
  18.                  }  
  19. $("#StartUpPosition div").not("#StartUpMainNode, #" + $divID).fadeOut(300); 
  20. $("#StartUpMainNode").stop().animate( {left:22}, function() {  
  21.                              $("#StartUpMainNode").hide();
  22.      $("#NodeMain").show();
  23. });
  24. $("#" + $divID).stop().animate( {left:152, top: 145}, function() {
  25.     $("#" + $divID).hide();
  26.                         $("#NodeTwo").show(); 
  27.                     });
  28.                     setTimeout("$('.clsNodeConnector').fadeIn(300)", 250);
  29.                     //$(".clsNodeConnector").fadeIn(300);  //fade in all of their connectors
  30. setTimeout("$.displaySubNodes($nodeID, 1)", 250);
  31.                    // $.displaySubNodes($nodeID, 1);            
  32. }
  33. });
  34.   //when main node is clicked, to go "back", animate it back into place, animate the clicked node to its original place
  35.    $("#NodeMain").stop().click(function() {
  36.             $("#StartUpMainNode").show();
  37.        $("#StartUpMainNode").stop().animate({ left: 250, top: 145 });
  38.             $("#" + $divID).show();
  39. $("#" + $divID).stop().animate( $nodePosition );