function initialize_menu_items(){
	$( ".menu_item_row" ).draggable({
		revert:"invalid",
		handle:".grip",
		zIndex: 2700,
		opacity: 0.35,
		cursorAt: { left: 400 },
		//snap: true,
		//snapTolerance: 40,
		helper: 'clone',
		start: function(event, ui) { 
			$( this ).css("background", "#F9F9F9" );
			$( this ).next().droppable( "option", "disabled", true );
			$( this ).prev().droppable( "option", "disabled", true );
		},
		drag: function(){
		},
		stop: function(){
			$( this ).next().droppable( "option", "disabled", false );
			$( this ).prev().droppable( "option", "disabled", false );
			$( this ).css("background", "white" );
		}
	});

	$(".receptable").droppable({
		hoverClass:"hoverhighlight",
		tolerance : "pointer",
		drop: function( event, ui ) {
			ui.draggable.fadeOut();
		
			$.ajax({
				url:"/admin/menu_items/"+ui.draggable.attr("data-menu_item_id")+".js", 
				type: "PUT",
				data: { 
					reorder : true,
					menu_item : {
						parent_id : $(this).attr("data-parent_id")
					} 
				},
				success : function (){
					initialize_menu_items();
				}
			});
			

		}
	});

	$(".receptable_position").droppable({
		hoverClass:"hoverhighlight_position",
		tolerance : "pointer",
		drop: function( event, ui ) {
			ui.draggable.fadeOut();
	
			$.ajax({
				url:"/admin/menu_items/"+ui.draggable.attr("data-menu_item_id")+".js", 
				type: "PUT",
				data: { 
					reorder : true,
					menu_item : {
						position : $(this).attr("data-position")
					} 
				},
				success : function (){
					initialize_menu_items();
				}
			});

		

		}
	});


}

$(document).ready(function(){
	initialize_menu_items();
	
	
	$(".switch").live('click',function(){
		

		$(this).toggleClass("on");
			
	});
		
	$(".menu_item_enabled_switch").live('click',function(){

			
		$.ajax({
			url:"/admin/menu_items/"+$(this).data("menu_item_id")+".js", 
			type: "PUT",
			data: { 
				menu_item : {
					enabled : $(this).hasClass("on")
				} 
			},
			success : function (){
				
			}
		});
			
			
			
	});
	

});