
/**
* This is our Resource class.
*/
function PromoResource() {
}

/**
* Our main function that is called to intialize the class.
*/
PromoResource.prototype.init = function(root) {

	this.debug = {};

	this.root = root;
	this.action = action;
	this.using_campaign = using_campaign;
	this.category_id = category_id;
	this.studio_id = studio_id;

	//
	// Store our old program from a past run
	//
	var old_program = '';

	//
	// Set a static variable that points to our object.  This is so that
	// code exeucted from a jQuery handler can interact with object methods.
	//
	PromoResource.prototype.obj = this;

    //
    // If we have a campign form/page, then call the initCampaign() function.
    //
    var callback_function2 = this.initResource;
    $("#resource_category_sort_form").each(function() {
        callback_function2(root);
        });

} // End of init()


/**
* This function is caled if we actually have a resource form.
*/
PromoResource.prototype.initResource = function(root) {

	//
	// Change the cursor so the user knows that the boxes can be moved.
	//
	$(".draggable").css("cursor", "move");

	//
	// Make all elements in the sortable class sortable.
	//
	$(".sortable").sortable({
		start: function(e, ui) {
			}
		});

	var form = $("#resource_category_sort_form");

	//
	// Changing the category does a new search
	//
	$("#CategoryTag").change(function() {

		//
		// There doesn't seem to be a way to remove the elements themselves,
		// only what is in an element.  So I'll have to call remove() on the 
		// parents for now...
		//
		form.find("input[name='resource_ids[]']").parent().empty();

		form.submit();

		});

	//
	// Clicking the save button saves the current order.
	//
	$("#button_save").click(function() {
		var form = $("#resource_category_sort_form");

		//form.find("input[name='resource_ids[]']").each(function() {
		//	alert($(this).attr("name") + " " + $(this).val() );
		//	});

		form.submit();

		});

	//
	// Cancel editing a category.
	//
	$("#button_cancel").click(function() {

		//
		// Nullify the category tag, then submit theform.
		//
		$("#CategoryTag").val("");

		var form = $("#resource_category_sort_form");
		form.submit();

		});


} // End of initResource()



/**
* Return the current instance of our object.
*/
PromoResource.prototype.getObj = function() {
	return(this.obj);
}


