function TaskViewHelper(scope){
	var _this=this;
	
	/*
	*	
	*/
	this.task_behaviour=function(model,view,controller){
		var _more_node=$('div.Actions',view).remove();
		
		controller.render_template_with_view('contact_task_holder',{},controller,function(tasks_markup){
			view.html(tasks_markup);
		 	render_task_from_groups(model.tasks);
		});

		function render_task_from_groups(tasks){
			$.each(tasks,function(task_index,task){
				add_task_to_group(task);
			});
		}



		function add_task_to_group(task){
			var group=controller.which_task_group(task);
			$('.'+group.css,view).removeClass('hide');
			var m={task:task,task_types:model.task_types};
			controller.render_template_with_view('contact_task',m,controller,function(task_markup){
				var n=$(task_markup);
				add_actions_to_task(n,task);
				var dt=$('.'+group.css+' dt',view);
				n.insertAfter(dt);
				$('.due-date abbr',n).timeago();
			});
		}

		function add_actions_to_task(element,task){
	        $('.task-checkbox',element).bind("click",function(){
	            controller.raise_event('on_task_complete_change',{
					task:task,
					paint:function(e){
					    element.remove();
					    add_task_to_group(e);
					}
				});
	        });
		}
	
		$("input[name='due']",scope.element).val((Date.today().toString('dd MMM yyyy')));

		$("input[name='due']",scope.element).datepicker({
			clickInput:true,
			constrainInput:true,
			dateFormat:'dd M yy',
			minDate:Date.today(),
			showButtonPanel:true,
			numberOfMonths:1
		});
	
		$('#add-task-action',scope.element).bind('click',function(e){

			//	Disable the UI
			$('#add-task-action',scope.element).attr('disabled',true);
			$('#add-task-action',scope.element).hide();
			$('#add-task-action',scope.element).parent().parent().append('<li class="ajax-loading">Adding Task</li>');

			//	Get the properties needed for a task
			var _current_user_id=$("meta[name='current_user_id']").attr('content');
			
			var type=$("select[name='taskType']",scope.element).val();
		
			var assignedTo=$("select[name='assignTo']",scope.element).val();
			var dueOn=$("input[name='due']",scope.element).val();
			dueOn = Date.parse(dueOn);

			//	The time has to be at the end of the current LOCALE today BUT! it has to localalised too!
			// Set the time as 1 minute to midnight then server UTC it!
			// dueOn.setHours(0);
			// dueOn.setMinutes(0);
			// console.warn(dueOn);


			// var utc_dueOn = _view.server_time(dueOn);
			// console.log("THE TASK IS DUE ON ",utc_dueOn);
			// Turn it back into a String (nice ISO format)
			utc_dueOn = dueOn.toString("yyyy-MM-ddTHH:mm:ssZ");

			var title=$("#contact-tasks #add-task-form input[name='description']",scope.element).val();
			
			// model={
					 	// 		
					 	// task:{
					 	// 	type:parseInt(type),
					 	// 	assignedTo:parseInt(assignedTo),
					 	// 	dueOn:utc_dueOn,
					 	// 	title:title,
					 	// 	complete:false,
					 	// 	deal:parseInt(model.deal)
					 	// }
			// Delegate the on event
			controller.on_add_task_clicked({
				// "body":$('#add-note-body',scope.element).val(),
				task:{
			 		type:parseInt(type),
			 		assignedTo:parseInt(assignedTo),
			 		dueOn:utc_dueOn,
			 		title:title,
			 		complete:false
			 		// deal:parseInt(model.deal)
			 	},
				paint:function(new_task){
					$("#contact-tasks #add-task-form input[name='description']",scope.element).val("");
					$('#add-task-action',scope.element).attr('disabled',false);
					$('#add-task-action',scope.element).removeAttr('disabled');
					$('#add-task-action',scope.element).show();
					$('.ajax-loading',$('#add-task-action',scope.element).parent().parent()).remove();
					add_task_to_group(new_task);
			 	}
			});

			//	Raise an event for the controller
			// controller.raise_event('on_add_new_task',{
			// 			
			// 			});

			return false;
		});
	}
	
}