//  @import com.hedgehoglab.application.controller.BaseController;
//  @import com.hedgehoglab.events.Thread;

function ActivityController(scope){
	
	//	setup a thread to ping the service every ? interval
	//	Update the model
	//	update the view
	scope.user_service.get_all_users(function(data){
		scope.user_model.model(data);
		start();
	});
	
	scope.activity_view.subscribe_to('on_request_activity_data',function(event){
		// alert($.toJSON(event.activity));
		// switch(event.type){
		// 	case "CONTACT_CREATED":contact_created(event);break;
		// }
		// // event.callback("hehehe");
		// // switch(event.)
		// function contact_created(event){
		// 	//	Get the contact info
		// 	// scope.contact_service.get_contact_by_id(event)
		// };
	});
	
	function start(){
		var _thread=new Thread(function(e){
			scope.activity_service.get_latest(20,function(data){
				//	Aggregate the data
				scope.activity_model.aggregate(data);
			
				//	Render the view
				scope.activity_view.update({
					activity:scope.activity_model,
					users:scope.user_model
				});
						// _thread.stop();
			});
		});
	
		//	Start the thread
		_thread.start(scope.interval);

	}
}