/**
 * Singleton
 */
function MainApp(){
	this.model = null;
	this.controller = null;
	this.mainView = null;
	this.calendarView = null;
	this.dayView = null;
	this.weekView = null;
	this.detailView = null;
	this.ssv = null;
}

/**
 * @private
 */
MainApp.instance = new MainApp();

/**
 * 
 */
MainApp.getInstance = function(){
	return MainApp.instance; 
}

/**
 * 
 */
MainApp.prototype.getSSV = function(){
	return this.ssv; 
}

/**
 * @param Object ssv server-side vars
 */
MainApp.prototype.init = function(ssv){
	this.ssv = ssv;
	
	$(document).ready(function(event) {
		MainApp.getInstance()._init(config, dictionary);
		delete config;
		delete dictionary;
	});
}

/**
 * @private
 */
MainApp.prototype._init = function(config, dictionary){
	this.model = new Model();
	this.model.setDate(new Date(this.ssv.dateFullYear, this.ssv.dateMonth, this.ssv.dateDate));
	this.model.setFeed(this.ssv.feed);
	this.model.setNetworkFeeds(this.ssv.networkFeeds);
	this.model.setLang(this.ssv.lang);
	this.model.setTheme(this.ssv.theme);
	this.model.setConfig(config);
	this.model.getConfig().cdnPath = this.ssv.cdnPath;
	this.model.setDictionary(dictionary);
	this.model.setMode(Model.MODE_DAY);
	
	this.controller = new Controller(this.model);
	
	this.mainView = new MainView(this.model, this.controller);
	this.calendarView = new CalendarView("calendarView", this.model, this.controller);
	this.dayView = new DayView("dayView", this.model, this.controller);
	this.weekView = new WeekView("weekView", this.model, this.controller);
	this.detailView = new DetailView("detailView", this.model, this.controller);
	
	this.model.setAppState(AppStateTypes.DOCUMENT_READY);
	this.controller.changeDate(this.model.getDate());
}

