Checkbox in table selecting/deselecting using jquerry and html.

Checkbox in table selecting/deselecting using jquerry and html.

I have a table as below:---
"<html>
<head>
    <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">   </script>
    <script language="javascript">
    
$(function(){
 
    $("#selectall").click(function () {
          $('.case').attr('checked', this.checked);
    });
    $(".case").click(function(){
 
        if($(".case").length == $(".case:checked").length) {
            $("#selectall").attr("checked", "checked");
        } else {
            $("#selectall").removeAttr("checked");
        }
 
      });
});

</script>
</head>
<body>
<table border="1">
<tr>
    <th><input type="checkbox" id="selectall"/>Select All</th>
    <th><input type="checkbox" id="selectall1"/>Admin</th>
    <th><input type="checkbox" id="selectall2"/>User</th>
    <th><input type="checkbox" id="selectall3"/>Super Admin</th>
</tr>
<tr>
    <td align="center"><input type="checkbox" class="case" name="case" value="1"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="2"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="3"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="4"/></td>
</tr>
<tr>
    <td align="center"><input type="checkbox" class="case" name="case" value="5"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="6"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="7"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="8"/></td>
</tr>
<tr>
    <td align="center"><input type="checkbox" class="case" name="case" value="9"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="10"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="11"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="12"/></td>
</tr>
<tr>
    <td align="center"><input type="checkbox" class="case" name="case" value="13"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="14"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="15"/></td>
    <td align="center"><input type="checkbox" class="case" name="case" value="16"/></td>
</tr>
</table>
</body>
</html>"

When i click selectall.All the checkboxes are clicked.
I want to do the following functions.
1.If i click the admin checkbox the related column check boxes should be checked. Similarlry the user and super admin checkbox should also function the same.
2.If i click the checkboxes under the selectall. All the checkboxes in the corresponding row should also be checked.

Pls help somebody.I'm new to jquerry.