var cItem = Class.create({
	initialize: function(_element, _tree, _type) {
		this.azon = _tree.azon;
		this.tree = _tree;
		this.element = _element;
		this.type = _type;  // movie, ppl, movie_assess, ppl_assess
		this.child_azon = _tree.azon;
		this.child_type = _type;
		if (this.type == 'ppl_assess') {
			this.child_azon = this.tree.ajanlo.azon;
			this.child_type = 'ppl';
		} else if (this.type == 'movie_assess') {
			this.child_azon = this.tree.film.azon;
			this.child_type = 'movie';
		}
	},
	showElementDetails: function() {
		// megmutatja az elem adatlapjat
		//openNewLayer(this.tree.onpopup_url);
		universe.getViewByName('datasheet').showDataSheet(this.child_type, this.child_azon);
		this.addToHistory(this);
	},
	toggleElementDetails: function(melyik) {
		// elemen belul adatfulet valt
		var el = this.tree;
		var out = this.element;
		var template = 'template_';
		var faj = this.child_azon;
		
		if ((melyik == 'im' || melyik == 'list') && userer.isGuest()) {
			userer.showLogin();
			return;
		}
		
		if (this.type == 'movie') {
			template += 'movie_big';
		} else if (this.type == 'ppl') {
			template += 'ppl_big';
		} else if (this.type == 'ppl_assess') {
			template += 'ppl_small';
		} else if (this.type == 'movie_assess') {
			template += 'movie_small';
		}
			
		template += '_'+melyik;
		var alma = {m: this.tree};
		// a user listai
		if (melyik == 'list') {
			alma.listak = userer.getListsWithMovie(faj);
		}
		templater.render(out, template, alma, this.afterRender.bind(this, melyik));
	},
	afterRender: function(melyik) {
		if (melyik == 'im') {
			var e = this.tree.azon+'_uzenet';
			//alert(document.getElementById(e));
			document.getElementById(e).focus();
		}
	},
	addToHistory: function() {
		var a = null;
		if (this.type == 'movie') {
			a = this.tree;
			a.onpopup_url = this.tree.onpopup_url;
			userer.addMovie(a);
		} else if (this.type == 'movie_assess') {
			a = this.tree.film;
			userer.addMovie(a);
		} else if (this.type == 'ppl') {
			a = this.tree;
			userer.addPPL(a);
		} else if (this.type == 'ppl_assess') {
			a = this.tree.ajanlo;
			a.onpopup_url = this.tree.onpopup_url;
			userer.addPPL(a);
		}
	},
	getTrailer: function() {
		// kikeresi a trailert a filmhez, es feldobja layerben
		var obj = null;
		if (this.type == 'movie') {
			obj = this.tree.linkek;
		} else if (this.type == 'movie_assess') {
			obj = this.tree.film.linkek;
		} else {
			return "Nincs trailer";
		}
		var j = 0;
		for (j=0; j<obj.length; j++) {
			if (obj[j].name == 'trailer') {
				return obj[j].url.unescapeHTML();
			}
		}
		return "Nincs trailer";
	}
});
