--- todolist.js	Sun Oct 28 18:52:51 2007
+++ todolist.js	Wed Feb 13 09:23:48 2008
@@ -13,24 +13,28 @@
           type: this.type,
           url: this.url,
           data: this.data,
-          dataType: this.dataType,
+          dataType: this.dataType
         });
       } else
         alert('Unknown AJAX Error: ' + status + ' Status:' + xml.status + ' ' + xml.statusText);
-    },
+    }
   });
-
-  $('#todolist-add-task-form').submit(function() {
+//$('#todolist-add-task-form').submit(function() {
+$("form").each(function() { if($(this).attr("action") == "/todolist/create_task"){ 
+	//console.log($('input, select', this).serialize() + '&order='+($('.todolist.incomplete .task').length+1));
+  $(this).submit(function() {
     $.ajax({
       type: 'POST',
       url: getBaseUrl() + 'index.php?q=todolist/create_task',
       data: $('input, select', this).serialize() + '&order='+($('.todolist.incomplete .task').length+1),
-      dataType: 'json',
+      dataType: 'json'
     });
     this.reset();
     return false;
   });
-
+}
+}
+);
   // Bind event hooks to complete/uncomplete a task.
   $('.todolist .task').each(TodoList.bind_task);
 });
@@ -47,25 +51,46 @@
     // create one nub for each incomplete list item
     $('.todolist.incomplete .task').each(TodoList.add_nub);
 
-    if (!$('.todolist.incomplete').isSortable) {
-      // make every incomplete todolist sortable
-      $('.todolist.incomplete').Sortable({
+    $('.todolist.incomplete').each(function(){
+       if(!$(this).isSortable){
+       	 var tmp = $(this).attr('id');
+       	 tmp = tmp.substring(tmp.indexOf('-')+1);
+       	 $(this).Sortable({
         accept: 'task',
         axis: 'vertically',
         revert:  true,
         handle: '.reorder',
         onchange: TodoList.incomplete_list_reorder,
-//      containment: 'parent', // having trouble
+	        tolerance: 'intersect',
+	   //     containment: 'parent',
+	        fit: true
       });
     }
+    });
+//    if (!$('.todolist.incomplete').isSortable) {
+//      // make every incomplete todolist sortable
+//      $('.todolist.incomplete').Sortable({
+//        accept: 'task',
+//        axis: 'vertically',
+//        revert:  true,
+//        handle: '.reorder',
+//        onchange: TodoList.incomplete_list_reorder,
+//        tolerance: 'intersect',
+//        containment: 'parent'
+//      });
+//    }
   },
 
   incomplete_list_reorder: function(obj) {
     serial = $.SortSerialize(obj[0].id);
+    if(obj[1] != null && obj[1].id != null){
+    	serial2 = $.SortSerialize(obj[1].id);
+    	serial.hash += "&" + serial2.hash;
+    }
     $.ajax({
       type: 'POST',
       url: getBaseUrl() + 'index.php?q=todolist/reorder_task',
-      data: serial.hash,
+      data: serial.hash
     });
   },
 
@@ -73,6 +98,7 @@
    * Bind event hooks to complete/uncomplete a task.
    */
   bind_task: function() {
+  	//$('input[@type=checkbox]', this).unbind('click');
     $('input[@type=checkbox]', this).click(function() {
       var element = $(this).parent();
       $.ajax({
@@ -81,7 +107,7 @@
         data: 'id='+this.name+'&checked='+(this.checked? '1' : '0')+'&order='+(this.checked? -1 : $('.todolist.incomplete .task').length+1),
         dataType: 'json',
         beforeSend: function() { $(element).addClass('loading'); },
-        complete: function() { $(element).removeClass('loading'); },
+        complete: function() { $(element).removeClass('loading'); }
       });
     });
   },
@@ -94,13 +120,14 @@
       data: 'id='+id,
       dataType: 'json',
       beforeSend: function() { $(element).addClass('loading'); },
-      complete: function() { $(element).removeClass('loading'); },
+      complete: function() { $(element).removeClass('loading'); }
     });
     return false;
   },
 
   edit_task: function(id) {
-    if (id instanceof Object) {
+    //if (id instanceof Object) {
+    if (id.type != null && id.type == "submit") {
       var element = $(this).parent();
       $.ajax({
         type: 'POST',
@@ -108,7 +135,7 @@
         data: $('input, textarea, select', this).serialize(),
         dataType: 'json',
         beforeSend: function() { $(element).addClass('loading'); },
-        complete: function() { $(element).removeClass('loading'); },
+        complete: function() { $(element).removeClass('loading'); }
       });
     } else {
       var element = $('#'+id);
@@ -117,7 +144,7 @@
         url: getBaseUrl() + 'index.php?q=todolist/edit_task&id='+id,
         dataType: 'json',
         beforeSend: function() { $(element).addClass('loading'); },
-        complete: function() { $(element).removeClass('loading'); },
+        complete: function() { $(element).removeClass('loading'); }
       });
     }
     return false;
@@ -201,16 +228,23 @@
      */
     exec: function() {
       $('.todolist .nub').css('display', 'none');
+      if(this.tid != undefined){
       this.stop();
     }
   }
+  }
 };
 
 
 function getBaseUrl() {
   var url = '';
   var script = $.grep($('head > script'), function(i) {
-    return $(i).attr('src').indexOf('todolist.js') > -1
+  	//console.log($(i));
+  	if($(i).attr('src')!= null){
+      return $(i).attr('src').indexOf('todolist.js') > -1;
+  	} else {
+  		return false;
+  	}
   });
   url = $(script).attr('src');
   url = url.substring(0, url.indexOf('modules/'));
