Infinite loop - can't find jQuery

Infinite loop - can't find jQuery

I have a weird problem that only happens occasionally.
In my js file there is a section for utility functions. I eventually added a section for jQuery utility functions (shown below). The code is in the middle of the file but not inside of any closure. The script tag for the file comes after the sript tag for jQuery.

Some times, and as of yet I don't know how to reproduce this, the code will run an infinite loop giving the error that it can't find the variable jQuery on line 37 of the code shown below. jQuery is definitely defined as the app is almost entirely jQuery. Also, most of the time there is no problem. 

What on earth could be causing this?
 
  1. (function ($) {
  2.     $.fn._draggable = function (draggable) { // for when html5 draggable and jquery ui draggable are not available. 
  3.         // if there is only one element to be made _draggable an id for that element is not required. 
  4.         // if more than one element is to be made draggable a unique id for each element should be used to avoid event handling collissions.
  5.         var $elm = this;
  6.         var id = $elm.attr("id") ? $elm.attr("id") : "tmp";
  7.         if (draggable == false) {
  8.             $elm.off("mousedown." + id);
  9.             $(document).off("mouseup._draggable." + id);
  10.             $(document).off("mousemove._draggable." + id);
  11.             return;
  12.         }
  13.         else if(draggable == true) {
  14.             $elm.css("position", "absolute");
  15.             $elm.on("mousedown." + id, function() {
  16.                 var position = $elm.position();
  17.                 var oL = event.pageX - position.left;
  18.                 var oT = event.pageY - position.top;
  19.                 $(document).on("mousemove._draggable." + id, function (event) {
  20.                     $elm.css({
  21.                         top: event.pageY - oT,
  22.                         left: event.pageX - oL
  23.                     });
  24.                 });
  25.                 $(document).on("mouseup._draggable." + id, function() {
  26.                     $(document).off("mouseup._draggable." + id);
  27.                     $(document).off("mousemove._draggable." + id);
  28.                 });
  29.             });
  30.         }
  31.     };


  32.     $.fn.tagName = function () {
  33.         return this.prop("tagName").toLowerCase();
  34.     };
  35. })(jQuery);