var cDataSheetContainer = Class.create(cView, {
	initialize: function($super, _name, _container, _reference) {
		$super(_name, _container, _reference);
		this.type = '';
		this.id = 0;
		this.dataSheet = null;
		this.history = [];
		this.historyLast = 0;
		this.historyLength = 10;
		this.historyTurn = false;
		userer.on('login', this.userStatusChange.bind(this));
		userer.on('logout', this.userStatusChange.bind(this));
	},
	activateDataSheet: function(type) {
		this.container.innerHTML = '';
		universe.activateViewByName('datasheet');
		this.type = type;
		switch (type) {
			case 'series':
				this.type = 'movie';
			case 'movie':
				this.dataSheet = new cMovieDataSheet(this.container);
				break;
			case 'ppl':
				this.dataSheet = new cAssessorDataSheet(this.container);
				break;
			case 'creative':
				this.dataSheet = new cCreativeDataSheet(this.container);
				break;
		}
	},
	showDataSheet: function(type, id, caller) {
		this.privateAddToHistory(caller);
		this.privateShowDataSheet(type, id);
	},
	privateAddToHistory: function(caller) {
		// compatibility
		/*if (!caller) {
			caller = universe.activeView().name;
		}
		// cycle
		if (caller == 'datasheet') {
			this.history[++this.historyLast] = {type: this.type, id: this.id};
			if (this.historyLast > this.historyLength) this.historyLast = 0;
			this.historyTurn = true;
		} else {
			this.history[0] = caller;
		}*/
	},
	privateShowDataSheet: function(type, id) {
		this.activateDataSheet(type);
		// remove cached data
		this.id = id;
		this.dataSheet.showDataSheet(this.type, id);
	},
	callChangeSubView: function(subPage) {
		this.changeSubView(subPage);
		// kill a href
		return false;
	},
	changeSubView: function(subPage) {
		this.dataSheet.changeSubView(subPage);
	},
	processLinking: function(params) {
		if (params.length > 1) {
			if (this.type != params[0] || this.id != params[1]) {
				this.type = params[0];
				this.id = params[1];
				this.privateAddToHistory();
				this.activateDataSheet(params[0]);
			}
			this.dataSheet.processLinking(params);
		}
	},
	callBackLink: function() {
		/*var prev = this.historyLast;
		if (this.historyLast == 0 && this.historyTurn) {
			prev = this.history.length-1;
			this.historyTurn = false;
			this.historyLast = prev;
		}
		if (!this.history[prev]) prev = 0;
		if (prev == 0) {
			universe.activateViewByName(this.history[0]);
		} else {
			this.privateShowDataSheet(this.history[prev].type, this.history[prev].id);
			this.history[prev] = null;
			this.historyLast--;
		}*/
		historical.back();
	},
	bindBack: function() {
		/*var prev = this.historyLast;
		if (this.historyLast == 0 && this.historyTurn) {
			prev = this.history.length-1;
			this.historyTurn = false;
			this.historyLast = prev;
		}
		if (!this.history[prev]) prev = 0;
		var link = '';
		if (prev == 0) {
			link = '#' + this.history[0];
		} else {
			link = '#datasheet-' + this.history[prev].type + '-' + this.history[prev].id;
		}
		templater.setElements($$('a.datasheetBackLink'), 'href', link);*/
		//universe.buildBackLink($$('a.datasheetBackLink'));
		//templater.observeElements($$('a.datasheetBackLink'), 'click', this.callBackLink.bind(this));
	}
	,updateOpinion: function(assess_id, opinion) {
		if (this.dataSheet) this.dataSheet.refresh();
	}
	,userStatusChange: function() {
		if (this.dataSheet) this.dataSheet.refresh();
	}
});

