Confused about what to include

Confused about what to include

I'm fairly new to jquery. I'm using the code shown below for a dialog. I found it on the web and it said to include
  1. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
That works fine. But then I thought I should use a later version of jquery so I replaced the above with
  1. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
That prevented the dialog from working at all. I found that if I included both of the above it will work. This is confusing to me. Shouldn't there just be one include of the latest jquery? Or do I need to keep all previous includes to ensure the code always works? And if I keep them all, are the improvements in the lastest version used or is it first come, first used? If the problem I am having is because the code for the dialog is old code that is no longer supported, is there a way for me to know that or is it just a matter of having to be familiar enough with jquery to recognize it?

  1.      $('.dia').click(function() {
        var id = ($(this).attr('id'));
        $("#dialog").html(id); 
        $('#dialog').load('mybox_details.php?id='+$(this).attr('id'));
        $("#dialog").dialog({modal: true, buttons: [{
                                                     text: "Ok",
                                                     click: function() {
                                                      $(this).dialog("close"); }
                                                    }]  , closeOnEscape: false ,
                                                          draggable: true,
                                                          height: 600,
                                                          width:800,
                                                          resizable: true,
                                                          title: 'My Box',                                   
                                                          zIndex: 9999   
                                                    });
          return false;  // prevent the default action, e.g., following a link
      });