//  @import com.hedgehoglab.application.model.BaseModel;

function TaskListModel(scope){
    BaseModel.call(this,scope);
    var _this=this;
    var _model=null;
    var _revserse_lookup=null;

    this.model=function(model){
        if(arguments.length>0){
			_model=model;
			if (model) {
			  _model.task = _model.task.sort(function(a,b){
          if (a.dueOn == b.dueOn) return 0;
          else return (a.dueOn > b.dueOn) ? 1 : -1;
        });
      }
			this.raise_event('model_changed',{
				model: _model
			});
		}
		return _model;
	};

    this.update=function(){
        this.raise_event('model_changed',{
            model: _model
        });
  	};

    this.task_by_id=function(id){
        if(!_revserse_lookup){
            _revserse_lookup={};
        }

        $.each(_model.task,function(i,n){
            _revserse_lookup[n.id]={index:i,item:n};
        })

        return _revserse_lookup[id].item;
    };
    
    this.update_task=function(task){
        var index = __revserse_lookup[task.id].i;
        model[i]=task;
    };
};