function menu_create_sortable(container, siteid){
	$(container+" ul li").css('cursor','move');
	
	var ids = [];
	$(container).find("ul").each(function(){ ids.push(this.id); });
	
	for (i = 0; i < ids.length; i++) {
		$('#'+ids[i]).sortable({
			opacity: 0.6,
			items : 'li',
			placeholder: 'sortable_highlight',
			update: function(event, ui){
				var order = $(this).sortable('toArray');
				menu_order(order,siteid )
			}
		});
	}
}

function menu_create_sortable_cat(container, siteid){
	$(container+" li").css('cursor','move');
	
	$(container).sortable({
		opacity: 0.6,
		items : 'li',
		placeholder: 'sortable_highlight',
		update: function(event, ui){
			var order = $(this).sortable('toArray');
			menu_cat_order(order,siteid )
		}
	});
}

function showMenuWindow(id, userid, mode, siteid){
	$.ajax({
		url		:	"/menu/new",
		type	: 	"POST",
		data	:	({
			id			: id,
			mode		: mode,
			userid		: userid,
			siteid		: siteid,
			use_ajax	: true,
			showWindow	: true
		}),
		datatype: 'html',
		success : function(data){
			$('body').append(data);
			$(".window_inner").width(850); 
			$(".window_inner").height(550); 
			$("#window[name='menuwindow']").fadeIn();
		}
	})
}

function showMenuCatWindow(id, userid, siteid){
	$.ajax({
		url		:	"/menu/newcat",
		type	: 	"POST",
		data	:	({
			id			: id,
			userid		: userid,
			siteid		: siteid,
			use_ajax	: true,
			showWindow	: true
		}),
		datatype: 'html',
		success : function(data){
			$('body').append(data);
			$(".window_inner").width(550); 
			$(".window_inner").height(300); 
			$("#window[name='menucatwindow']").fadeIn();
		}
	})
}

function deleteMenu(id, siteid){
		$('html').append("<div id='menu_dialog' title='Gericht entfernen'>Möchten Sie dieses Gericht wirklich entfernen?</div>");
		$('#menu_dialog').dialog(
		   {"option":"modal",
		   	zIndex: 3999 ,
		   	buttons: {
		   		"Abbrechen": function(){
		   			$(this).dialog("close");
					goTo("/index/site/nr/"+siteid+"/showcats/false");
		   		},
		   		"Ok": function(){
		   				$.ajax({
							url		:	"/menu/delete",
							type	: 	"POST",
							data	:	({
								id			: id,
								siteid		: siteid,
								use_ajax	: true,
								showWindow	: true
							}),
							datatype: 'html',
							success : function(data){
								goTo("/index/site/nr/"+siteid+"/showcats/false");
							},
							error: function(data){
					
							}
						})
		   		}
		   	}
		   }
		)		
}

function deleteMenuCat(id,userid, siteid){
		$('html').append("<div id='menu_dialog' title='Kategorie entfernen'>Möchten Sie diese Kategorie wirklich entfernen?</div>");
		$('#menu_dialog').dialog(
		   {"option":"modal",
		   	zIndex: 3999 ,
		   	buttons: {
		   		"Abbrechen": function(){
		   			$(this).dialog("close");
					goTo("/index/site/nr/"+siteid+"/showcats/true");
		   		},
		   		"Ok": function(){
		   				$.ajax({
							url		:	"/menu/deletecat",
							type	: 	"POST",
							data	:	({
								id			: id,
								userid		: userid,
								siteid		: siteid,
								use_ajax	: true,
								showWindow	: true
							}),
							datatype: 'html',
							success : function(data){
								goTo("/index/site/nr/"+siteid+"/showcats/true");
							},
							error: function(data){
							}
						})
		   		}
		   	}
		   }
		)	
}


function menu_incPosition(arr, pos, siteid){
	
	tmp = arr[pos+1];
	arr[pos+1] = arr[pos];
	arr[pos] = tmp;
	
	
	$.ajax({
		url		:	"/menu/position",
		type	: 	"POST",
		data	:	({
			siteid		: siteid,
			arr			: (arr),
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
			$('body').html(data);
		}
		
	})	 
}




function menu_decPosition(arr, pos, siteid){
	if (pos > 0) {
		tmp = arr[pos - 1];
		arr[pos - 1] = arr[pos];
		arr[pos] = tmp;
		
		$.ajax({
			url: "/menu/position",
			type: "POST",
			data: ({
				siteid: siteid,
				arr: (arr),
				use_ajax: true
			}),
			datatype: 'html',
			success: function(data){
				$('body').html(data);
			}
		})
	}
}

function menu_order(arr, siteid){
	$.ajax({
		url		:	"/menu/position",
		type	: 	"POST",
		data	:	({
			siteid		: siteid,
			arr			: arr,
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
		}
	})	 
}


function menu_cat_order(arr, siteid){
	$.ajax({
		url		:	"/menu/catposition",
		type	: 	"POST",
		data	:	({
			siteid		: siteid,
			arr			: arr,
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
		}
	})	 
}

function menu_incCatPosition(arr, pos, siteid){
	
	tmp = arr[pos+1];
	arr[pos+1] = arr[pos];
	arr[pos] = tmp;
	
	
	$.ajax({
		url		:	"/menu/catposition",
		type	: 	"POST",
		data	:	({
			siteid		: siteid,
			arr			: (arr),
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
			$('body').html(data);
		}
		
	})	 
}

function menu_decCatPosition(arr, pos, siteid){
	if (pos > 0) {
		tmp = arr[pos - 1];
		arr[pos - 1] = arr[pos];
		arr[pos] = tmp;
		
		$.ajax({
			url: "/menu/catposition",
			type: "POST",
			data: ({
				siteid: siteid,
				arr: (arr),
				use_ajax: true
			}),
			datatype: 'html',
			success: function(data){
				$('body').html(data);
			}
		})
	}
}


