/**
 * @param String container
 * @param Model model
 * @param Controller controller
 */
function DayView(container, model, controller){
	this.container = container;
	this.model = model;
	this.controller = controller;
	this.grid = null;
	
	this.model.addEventListener("appStateChange", BoundMethod.create(this, this.appStateChangeHandler));
}

DayView.prototype.createChildren = function(){
	this.grid = new DataGrid(this.container, "gridTable", 
			[{title:this.model.getDictionary().hourTitle, labelFunction:
				function(item, column){
					var time = "-";
					if(item && item.airDateTime){
						var time = item.airDateTime.slice(11,16);
					}
					return time;
				}
			 }, 
			 /*{title:this.model.getDictionary().showTitle, dataField:"title"}],*/
			 {title:this.model.getDictionary().showTitle, labelFunction:
				function(item, column){
				 	return '<div class="title">'+item.title+'</div><div class="originalTitle">'+item.originalTitle+'</div>';
			 	}
			 }],
			 BoundMethod.create(this, this.itemClickHandler));
}

DayView.prototype.updateMode = function(){
	if(this.model.getMode()==Model.MODE_DAY){
		$("#"+this.container).show();
	}else{
		$("#"+this.container).hide();
	}
}

DayView.prototype.itemClickHandler = function(index){
	this.controller.selectShow(index);
}

DayView.prototype.showListChangeHandler = function(event){
	this.grid.setData(this.model.getScheduleDay().getShowList());
}

DayView.prototype.modeChangeHandler = function(index){
	this.updateMode();
}

DayView.prototype.appStateChangeHandler = function(event){
	if(this.model.getAppState()==AppStateTypes.DOCUMENT_READY){
		this.createChildren();
		this.updateMode();
		this.model.getScheduleDay().addEventListener("showListChange", BoundMethod.create(this, this.showListChangeHandler));
		this.model.addEventListener("modeChange", BoundMethod.create(this, this.modeChangeHandler));
	}
}

