// JavaScript Document
/*
/////////////////////////////////////////////////////////////////
/////  EDIT THE FOLLOWING VARIABLE VALUES  //////////////////////
/////////////////////////////////////////////////////////////////

// set the list selector
var setSelector2 = "#newsSort";
// set the cookie name
var setCookieName2 = "NewsBlocksOrder";
// set the cookie expiry time (days):
var setCookieExpiry2 = 7;
 
/////////////////////////////////////////////////////////////////
/////  YOU PROBABLY WON'T NEED TO EDIT BELOW  ///////////////////
/////////////////////////////////////////////////////////////////
 
// function that writes the list order to a cookie
function getOrder2() {
	// save custom order to cookie
	$.cookie(setCookieName2, $(setSelector2).sortable("toArray"), { expires: setCookieExpiry2, path: "/" });
	$.cookie(setCookieName2, $(setSelector2).sortable("toArray"), { expires: setCookieExpiry2, path: "/" });
}
 
// function that restores the list order from a cookie
function restoreOrder2() {
	var list = $(setSelector2);
	if (list == null) return
	
	// fetch the cookie value (saved order)
	var cookie = $.cookie(setCookieName2);
	if (!cookie) return;
	
	// make array from saved order
	var IDs = cookie.split(",");
	
	// fetch current order
	var items = list.sortable("toArray");
	
	// make array from current order
	var rebuild = new Array();
	for ( var v=0, len=items.length; v<len; v++ ){

		rebuild[items[v]] = items[v];

	}

	

	for (var i = 0, n = IDs.length; i != n; i++) {
		
		// item id from saved order
		var itemID = IDs[i];
		
		if (itemID in rebuild) {
		
			// select item id from current order
			var item = rebuild[itemID];
			
			// select the item according to current order
			var child = $("ul.ui-sortable").children("#" + item);
			
			// select the item according to the saved order
			var savedOrd = $("ul.ui-sortable").children("#" + itemID);
			
			// remove all the items
			child.remove();
			
			// add the items in turn according to saved order
			// we need to filter here since the "ui-sortable"
			// class is applied to all ul elements and we
			// only want the very first!  You can modify this
			// to support multiple lists - not tested!
			$("ul.ui-sortable").filter(":first").append(savedOrd);
		}
	}

}



	$(document).ready(function() {
		if($("#newsSort").attr("id") == "newsSort") {
			$("#newsSort").sortable({
				handle: 'div.title',
				axis: 'y',
				distance: 5,
				update: function() { getOrder2(); }
			});
			restoreOrder2();
		}
	});

*/

