explanation datepicker event

explanation datepicker event

Hello,
could someone explain too me how this code will work

Because, I don't know if I should put the code in the pluginfile
or de head section off the page

what else do I need too pay attention for

the code is from http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCloseMouseOut.html

thanks in advance, Richard

$(function()
{
   var cal;
   var $this;

   var checkForMouseout = function(event)
   {
      var el = event.target;
      
      while (true){
         if (el == cal) {
            return true;
         } else if (el == document) {
            $this.dpClose();
            return false;
         } else {
            el = $(el).parent()[0];
         }
      }
   };

   $('.date-pick')
      .datePicker()
      .bind(
         'dpDisplayed',
         function(event, datePickerDiv)
         {
            cal = datePickerDiv;
            $this = $(this);
            $(document).bind(
               'mouseover',
               checkForMouseout
            );
         }
      ).bind(
         'dpClosed',
         function(event, selected)
         {
            $(document).unbind(
               'mouseover',
               checkForMouseout
            );
         }
      );

});