$(document).ready(function(){
    $(".sortable").sortable({
        placeholder: 'ui-state-highlight',
        update: function(event, ui){
    		$('#loading').show(0);
    		ajax_reorder_pages();
    	}
    });
    //$(".sortable").disableSelection();
    $("#search_page").autocomplete('searchpage');
    $('#search_page').focus();
		$('#form\\.content').addClass('mceEditor');
		$('ul.pages_list li').mouseenter(function(){
			hide_all_action_containers();
			show_action_container(this);
		});
		$('ul.pages_list li').mouseleave(function(){
			hide_all_action_containers();
		});
});

function ajax_reorder_pages(){
    jQuery.post('reorderpages', 
        {'new_order': $('.sortable').sortable('toArray')}, 
        function(response) {
        	$('#ajax_msg').text(response);
            $('#loading').fadeOut(1000);
        });
}

function show_action_container(elem){
  $(elem).find('.ui-icon-arrow-4:first').show();
  $(elem).find('.action_container:first').show();
}

function hide_all_action_containers(){
  $(document).find('ul.pages_list').find('.ui-icon-arrow-4').hide();
  $(document).find('ul.pages_list').find('.action_container').hide();
}
