function fetchToDos(tag_id) {
	// Check for Filter
	var tag_id = tag_id;				
	if (tag_id) {
		plain_tag_id = tag_id;
		tag_id = 'tag_id='+tag_id;
		showClearButton();
	} else {					
		plain_tag_id = '';
		hideClearButton();
	}

	// Load List
	$('#ToDoArea').load('./inc/classes/ajax.getToDoList.php?'+tag_id, function() {

		// Checkmark					
		$('#ToDoArea input:checkbox').click(function () {
			$('.loading_icon').show();
			$.post('./inc/classes/ajax.saveData.php', { action:'setState', todoid:$(this).attr("name") }, function (data) {								
				fetchToDos(plain_tag_id);
				fetchDones();		
				fetchTags();
				fetchStats();											
			});		
	    });
		
		
		// Hover effect
		$("#todo-list li").hover(  
			function() {  
			$(this).animate({"backgroundColor": "#dbdbdb"}, "fast");						
			},  
			function() {  
			$(this).animate({"backgroundColor": "#efefef"}, "fast"); 
			  
		}); 
		    
		// Delete
		$('#todo-list .listDelIcon').click(function() {
			var answer = confirm('Delete this?');
			if (answer) {						
				$('.loading_icon').show();
				$.post('./inc/classes/ajax.saveData.php', { action:'delete', todoid:$(this).attr("id") }, function (data) {										
					fetchToDos(plain_tag_id);				
					fetchDones();
					fetchTags();
					fetchStats();
				});
			}
			$('.loading_icon').show();
		});

		// Prio
		$('#todo-list .listPrioIcon').click(function() {
			$('.loading_icon').show();
			$.post('./inc/classes/ajax.saveData.php', { action:'prio', todoid:$(this).attr("id") }, function (data) {										
				fetchToDos(plain_tag_id);
				fetchDones();
				fetchTags();
				fetchStats();							
			});
			$('.loading_icon').show();												
		});					

		// Sortable		
	    $('#todo-list').sortable({
		      handle : '.handle',
		      update : function () {				    		
				var order = $('#todo-list').sortable('serialize');										  
		  		$("#info").load('./inc/classes/ajax.sort.php?'+order);					  							  		
		      }
	    });  

		// ToDo Edit in Place
		$('.todoEntry').editInPlace({						
		    url: './inc/classes/ajax.saveData.php',
		    params: 'action=update',					    
		    saving_image: './layout/images/ajax-loader.gif',
		    show_buttons: true					    
		});				

		// Filter by Tag
		$('.byTag').click(function(e) {			
		 	e.preventDefault();
			fetchToDos($(this).attr("id"));
			$('.loading_icon').show();
			showClearButton();
		});		

		// Search
		$('#searchByTag').search('#todo-list li', function(on) {			
			on.all(function(results) {
				var size = results ? results.size() : 0
				$('#count').text(size + ' ToDos');
			});
			on.reset(function() {
				$('#none').hide();
				$('#todo-list li').show();
			});
			on.empty(function() {
				$('#none').show();
				$('#todo-list li').hide();								
			});
			on.results(function(results) {				
				$('#none').hide();																		
				$('#todo-list li').hide();														
				results.show();			
			});			
		});
		
		$('.loading_icon').hide();		
		
	});			
}
