var cValaszto = Class.create(cView, {
	initialize: function($super, _name, _container, _reference) {
		$super(_name, _container, _reference);
		this.tablak = [];
		this.filters = {};
		this.highlighted = 0;
	},
	// feltolti tartalommal
	init: function($super) {
		$super();
		this.tablak.push(new cTable('movie', 'template_movie_big', 0, 0, 0, 1, $('output0'), $$('.lapozo0'), $('fejlec0'), this, this.reference + '.tablak[0]'));
		this.tablak.push(new cTable('ppl', 'template_ppl_small', 0, 0, 1, 1, $('output1'), $$('.lapozo1'), $('fejlec1'), this, this.reference + '.tablak[1]'));
		this.tablak[0].refreshContent(this.tablak[0].tipus, 0, 0);
	},
	getFilters: function($super) {
		var filters = Object.clone($super());
		filters.count_per_page = Math.max(Math.floor(this.getAvailableHeight() / 170), 2);

		filters.highlighted = this.highlighted;
		
		// name searches
		if (filters.searchCategory) {
			switch (filters.searchCategory) {
				case 'creative':
					filters.actorName = filters.searchQuery;
					break;
				case 'serie':
					filters.sorozatok = '1';
					filters.movieTitle = filters.searchQuery;
					break;
				case 'movie':
				default:
					filters.notseries = '1';
					filters.movieTitle = filters.searchQuery;
					break;
			}
		}
		
		return filters;
	},
	resetAllElement: function($super) {   // osszes elemet ujrarajzolja, ez mondjuk bejelentkezes utan hasznos, mert ott uj funkcio gombok jelennek meg
		$super();
		var ik = 0;
		for (ik=0; ik<this.tablak.length; ik++) {
			this.tablak[ik].resetAllElement();
		}
	},
	resizeView: function($super) {
		$super();
		var i = 0;
		for (i=0; i<this.tablak.length; i++) {
			this.tablak[i].resizeFrame();
		}
	},
	clearNextBlock: function(blokk) {
		if (this.tablak.length > blokk) {
			this.tablak[blokk].clearThisBlock();
		}
	},
	updateNextBlock: function(blokk, tipus, parent_fokusz) {
		if (blokk >= this.tablak.length) return;
		this.tablak[blokk].template = this.getBlockTemplate(this.switchType(tipus), blokk);
		this.tablak[blokk].refreshContent(tipus, 0, parent_fokusz);
	},
	putElementToPri: function(_tipus, _fokusz) {
		// uj elem kerul a kiemel elso pozicioba
		// az elso tablanal elinditjuk a folyamatot egy refreshContent-el, ami lekeri az uj tartalmat a listajaba,
		// majd a fokusz elem alapjan keri a kovetkezo blokkok frissiteset
		this.highlighted = _fokusz;
		this.tablak[0].tipus = _tipus;
		this.tablak[0].template = this.getBlockTemplate(_tipus, 0);
		
		this.tablak[0].refreshContent(_tipus, _fokusz, 0);
	},
	updateOpinion: function(assess_id, opinion) {
		this.tablak[1].updateOpinion(assess_id, opinion);
	},
	drawAttends: function() {
		var i=0;
		for (i=0; i<this.tablak.length; i++) {
			this.tablak[i].drawAttends();
		}
	},
	getBlockTemplate: function(tipus, blokk) {
		var tpl = 'template_' + tipus;
		if (blokk == 0) {
			tpl += '_big';
		} else {
			tpl += '_small';
		}
		return tpl;
	},
	requestRet: function(url, reference, blokk) {
		//userer.showEgyeb(url);
		universe.showDebugger('getData.php?'+url);
		var keres = new Ajax.Request('getData.php?'+url, {
		method:'get',
			onSuccess: function(transport){
				var ret = transport.responseText.evalJSON();
				universe.showDebugger(transport.responseText);
				//var s = tabla.reference + ".parseRet('" + ret + "');";
				//eval(s);
				eval(reference).parseRet(ret);
				if (ret.topKeywords) {
					searchKeywords.updateSearchKeywords(ret.topKeywords, 'top');
				}
				if (ret.freshKeywords) {
					searchKeywords.updateSearchKeywords(ret.freshKeywords, 'fresh');
				}
			}
		});
		// unique keres, csak egy futhat belole
		universe.addRequest('blokk', keres, true, blokk);
	},
	onParamsChange: function($super, filters) {
		$super(filters);
		this.highlighted = 0;
		this.tablak[0].template = this.getBlockTemplate('movie', 0);
		this.tablak[0].refreshContent('movie', 0, 0);
	},
	/*onParamsChange: function($super, opj) {
		$super(opj);
		if (opj != null && opj.id == 'milyet' && opj.value == 100) {
			this.showNewMovieAgePage();
			return false;
		}
		if ($('milyet').value != 100) {
			this.hideNewMovieAgeButton();
		}
		this.onExecParamsChange();
	},
	onParamsChangeHidden: function(opj) {
		this.reloadFilters(null);
		this.highlighted = 0;
		this.tablak[0].template = this.getBlockTemplate('movie', 0);
		this.tablak[0].refreshContent('movie', 0, 0);
	},*/
	switchType: function(mi) {
		if (mi == 'movie') return 'ppl';
		return 'movie';
	}
	/*,showNewMovieAgePage: function() {
		menuer.showTartalom('history');
	},
	hideNewMovieAgeButton: function() {
		if ( $('new_movieage_button') ) {
			$('new_movieage_button').hide();
		}
	},
	onExecParamsChange: function() {
		if (menuer.aktualis != 'kategoria' && menuer.aktualis != 'szabad' && menuer.aktualis != 'kerdezes') {
			menuer.changeIt('kategoria');
		}
		//universe.activateViewByName('valaszto');
		//menuer.showTartalom('valaszto');
		this.highlighted = 0;
		this.tablak[0].template = this.getBlockTemplate('movie', 0);
		this.tablak[0].refreshContent('movie', 0, 0);
		//this.tablak[0].changePage(1);
	}*/
});

