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

DetailView.prototype.createChildren = function(){
	
	//http://jqueryui.com/demos/dialog/#modal-message
	$('#'+this.container).dialog({
		modal: true,
		autoOpen: false,
		resizable: false,
		width: 550
	});
	
	var dic = this.model.getDictionary();
	
	$('#'+this.container + " .originalTitleLabel").append(dic.originalTitleLabel);
	$('#'+this.container + " .airDateTimeLabel").append(dic.airDateTimeLabel);
	$('#'+this.container + " .castLabel").append(dic.castLabel);
	$('#'+this.container + " .genreLabel").append(dic.genreLabel);
	$('#'+this.container + " .directorLabel").append(dic.directorLabel);
	$('#'+this.container + " .storylineLabel").append(dic.storylineLabel);
	$('#'+this.container + " .rateLabel").append(dic.rateLabel);
}

DetailView.prototype.appStateChangeHandler = function(event){
	if(this.model.getAppState()==AppStateTypes.DOCUMENT_READY){
		this.createChildren();
	}else
	if(this.model.getAppState()==AppStateTypes.SHOW_DETAIL_LOADING){
		var selectedShow = this.model.getSelectedShow();
		$('#'+this.container).dialog("option", "title", selectedShow.title);
		$('#'+this.container).dialog('open');
		$('#'+this.container + " .originalTitle").empty();
		$('#'+this.container + " .originalTitle").append(selectedShow.originalTitle);
		//$('#'+this.container + " .airDateTime").append($.format.date(selectedShow.airDateTime, this.model.getDictionary().dateTimeFormat));
		$('#'+this.container + " .airDateTime").empty();
		$('#'+this.container + " .airDateTime").append(selectedShow.airDateTime.slice(11,16));
		$('#'+this.container + " .cast").empty();
		$('#'+this.container + " .genre").empty();
		$('#'+this.container + " .director").empty();
		$('#'+this.container + " .rate").empty();
		$('#'+this.container + " .storyline").empty();
		$('#'+this.container + " .storyline").append(this.model.getDictionary().storylineLoading);
	}else
	if(this.model.getAppState()==AppStateTypes.SHOW_DETAIL_SUCCESS){
		var showDetail = this.model.getShowDetail();
		$('#'+this.container + " .cast").append(showDetail.actorList);
		$('#'+this.container + " .genre").append(showDetail.genreList);
		$('#'+this.container + " .director").append(showDetail.directorList);
		$('#'+this.container + " .rate").append(showDetail.rate);
		$('#'+this.container + " .storyline").empty();
		$('#'+this.container + " .storyline").append(showDetail.storyline);
	}else
	if(this.model.getAppState()==AppStateTypes.SHOW_DETAIL_ERROR){
		$('#'+this.container + " .storyline").empty();
		$('#'+this.container + " .storyline").append(this.model.getDictionary().storylineLoadingError);
	}
}

