/////////////////////////////////////////////////////////////////
/////  EDIT THE FOLLOWING VARIABLE VALUES  //////////////////////
/////////////////////////////////////////////////////////////////

// set the list selector
var setSelector = "#list1";
// 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 restores the list order from a cookie
function restoreOrder() {
	var list = jQuery(setSelector);
	if (list == null) return
	
	// fetch the cookie value (saved order)
	var cookie = jQuery.cookie(setCookieName);
	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 = jQuery("div.ui-sortable").children("#" + item);
			
			// select the item according to the saved order
			var savedOrd = jQuery("div.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!
			jQuery("div.ui-sortable").filter(":first").append(savedOrd);
		}
	}
}

// function that writes the list order to a cookie
function getOrder() {
	
	// save custom order to cookie
	jQuery.cookie(setCookieName, jQuery(setSelector).sortable("toArray"), { expires: setCookieExpiry, path: "/" });
	
}



// code executed when the document loads
jQuery(function() {
	// here, we allow the user to sort the items
	jQuery(setSelector).sortable({
                                handle                  : 'h6',
                                appendTo		: 'body',
				helper			: 'clone',
				start: function(e, ui)  { jQuery(ui.helper).addClass('ui-draggable-helper'); },
				forcePlaceholderSize	: true,
				placeholder		: 'dragAjuda',
				scroll			: true,
				scrollSensitivity	: 40,
                                opacity                 : 0.8,
                                tolerance		: 'pointer',
				cursor			: 'move',
				update			: function() { getOrder(); }
	});
	// here, we reload the saved order	
	restoreOrder();
	jQuery(setSelector).disableSelection();
});

//FishEYE menu
    var js = jQuery.noConflict();
        js(document).ready(
                function()
                {
                        js('#fisheye2').Fisheye({
                                        maxWidth: 40,
                                        items: 'a',
                                        itemsText: 'span',
                                        container: '.fisheyeContainter',
                                        itemWidth: 70,
                                        proximity: 20,
                                        alignment : 'left',
                                        valign: 'bottom',
                                        halign : 'center'
                                })
                        });