//MVC


var Class = {
	create : function(klass) {
		var _class=function() {
			this.initialize.apply(this, arguments);
		}
		_class.prototype=klass;
		return _class;
	},
	extend : function(parent,klass) {
		var parentObjClone= jQuery.extend(true,{}, parent.prototype);
		parentObjClone['parent']=[];
		for(property in  parentObjClone){
			parentObjClone['parent'][property]=  parentObjClone[property];		
		};
		for(property in  klass){
			parentObjClone[property]= klass[property];
		};
		return this.create(parentObjClone);
	}
};



// MVC
var AbstractMVC = Class.create({
	registerdControllers:[],
	initialize : function() {
		
	},
	dispatch : function() {
		for (var i = 0, length = this.registerdControllers.length; i < length; i++) {
		   this.registerdControllers[i].startMVC();
		}
	},
	registerControllers :function(arg){
		for (var i = 0, length = arg.length; i < length; i++) {
			this.registerdControllers.push(arg[i]);
		}
	}
});


//Abstract Controller
var AbstractController =Class.create({
	registerdModels:[],
	registerdViews:[],
	initialize : function() {
		
	},
	startMVC : function() {
		this.sendChange('start');
	},

	registerModels :function(arg){
			for (var i = 0, length = arg.length; i < length; i++) {
				arg[i].registeredController=this;
				this.registerdModels.push(arg[i]);
				
			}
	},
	registerViews :function(arg){
			for (var i = 0, length = arg.length; i < length; i++) {
				arg[i].registeredController=this;
				this.registerdViews.push(arg[i]);
			}
	},
	getEvent:function(type,arg){
		this.sendChange(type,arg);
	},  
	sendChange:function(type,arg){
		for (var i = 0, length = this.registerdViews.length; i < length; i++) {
			this.registerdModels[i].getChange(type,arg);
		}
	},
	sendUpdate: function(type,arg) {
		for (var i = 0, length = this.registerdViews.length; i < length; i++) {
			this.registerdViews[i].update(type,arg);
		}
	}

});


//Abstract View
var AbstractView = Class.create({
	registeredController:null,
	initialize : function() {
	
    }, 
    render: function() {},
    update:function() {},
	sendEvent:function(type,arg){
		this.registeredController.getEvent(type,arg);
	}

});


//Abstract Model
var AbstractModel = Class.create({
	registeredController:null,
	initialize : function() {
	
    }, 
    getChange: function(type,arg) {

  },
    sendUpdate: function(type,arg) {
      this.registeredController.sendUpdate(type,arg);

  }

});

