/////////////////////////////////////////////////////////////////
/////  EDIT THE FOLLOWING VARIABLE VALUES  //////////////////////
/////////////////////////////////////////////////////////////////
 
// set the list selector
var setSelector = "#sortable";
// set the cookie name
var setCookieName = "listOrder";
// set the cookie expiry time (days):
var setCookieExpiry = 7;
 
/////////////////////////////////////////////////////////////////
/////  YOU PROBABLY WON'T NEED TO EDIT BELOW  ///////////////////
/////////////////////////////////////////////////////////////////
 
// function that writes the list order to a cookie
function getOrder() {
	// save custom order to cookie
	setCookie("drag",$(setSelector).sortable("toArray")[0],30);
}

function restoreOrder(){
	
	var order = getCookie("drag");

	var child1 = $("#sortable").children("#tat");
	var child2 = $("#sortable").children("#hed");
	//child1.remove();
	//child2.remove();
	if (order.indexOf("tat") != -1){
		$("#sortable").append(child1);
		$("#sortable").append(child2);
	}
	else{
		$("#sortable").append(child2);
		$("#sortable").append(child1);
	}

}

// code executed when the document loads
$(function() {
	// here, we allow the user to sort the items
	$(setSelector).sortable({
		axis: "y",
		opacity: 0.6,
		cursor: "move",
		update: function() { getOrder(); }
	});
 
	// here, we reload the saved order
	restoreOrder();
});
