$(function(){ /* onload */ });

_make_sortable = function() {

  $('#sort_container').Sortable({
    accept      : 'sortDiv',
    helperclass : 'sortHelper',
    activeclass : 'sortableactive',
    hoverclass  : 'sortablehover',
    containment : '#sort_container'
  });
  
};

jSorter = function(node_id) {
  var hash = $.SortSerialize('sort_container').hash.replace(/sortDiv_/g,'');
  jLoader('node.php?op=save_children&_node_id='+node_id+'&'+hash, 'replace', 'li-'+node_id);
};


jLoader = function(url,replace_or_append,container_id,callback) {

	if( arguments.length < 3 ) {
		alert('need at least 3 args...');
		return;
	}

	var loader = $(                        // create and save the loading image
	'<div class="loading">'+
		//'<image src="images/loading.gif" />'+
	'</div>').appendTo('#'+container_id);      // it is removed in the replacement

	$.get(url, {}, function(resp) {        // make async call to the <a>'s url
		loader.remove();

		if( replace_or_append == 'replace' )
			$('#'+container_id).replaceWith(resp); // * replace with the response
		else if( replace_or_append == 'append' )
			$('#'+container_id).append(resp);      // * replace with the response

		if( callback !== undefined )
			callback();
	}); 

	//$('ul').sortable(sortable_options);
	return false;                          // dont actually follow the link
};

jFormer = function(form_id,url,replace_or_append, container_id, method ){

	if( arguments.length < 4 ) { 
		alert('need 3'); return; 
	} else {
	}

	var container = $('#'+container_id);
	var method = method || 'post'; // default value
	
	//alert('jFormer called');

	var loader = $(                        // create and save the loading image
	'<div class="loading">'+
		'<image src="images/loading.gif" />'+
	'</div>').appendTo('#'+container_id);      // it is removed in the replacement


	$('#'+form_id).ajaxForm({ 
		type: method,
		success: function(resp){
			loader.remove();

			if( replace_or_append == 'replace' )
				container.replaceWith(resp); // * replace with the response
			else if( replace_or_append == 'append' )
				container.append(resp);      // * replace with the response
		}
	}).submit();

	
};
