// globalis valtozok
var JATEK_ID;
var ACTIVE_VERSION_ID;










// osszes szolas megmuatasa adott verziohoz  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
function show_all_version_comments(buttons)
{
	buttons.each(function(btn)
	{
		btn.addEvent('click', function()
		{
			//
			var id = btn.id.replace('More_comments_show_', '').toInt();
			$('More_comments_'+id).setStyle('display', 'block');

			btn.set('html', '&#160;');
			btn.setStyles({
				'height': '10px',
				'padding': '0px',
				'margin': '0px'
			});
		});
	});
/*
	{
		button.addEvent('click', function(e)
		{
			//
			cnt.setStyle('display', 'block');

			button.set('html', '&#160;');
			button.setStyles({
				'height': '10px',
				'padding': '0px',
				'margin': '0px'
			});
		})
	}
*/
}
//










// ertekeles class   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
var Szavazas = new Class
({
	// optionok
	Implements: Options,
	options: {
		vote_butt_wid: 31,
		max_vote: 5
	},


	// init
	initialize: function(options, container)
	{
		// optionok behuzasa
		this.setOptions(options);

		// kontener jon kivulrol
		this.container = container;

		// szavazo gomb terulet: ha van, akkor megyunk tovabb
		if (this.vote_area = this.container.getElement('div.szavazas_but'))
		{
			// jatekv id-ja: a container id-jaban
			this.jatekv_id = this.container.id.replace('Jatekv_szavazas_', '').toInt();

			// eredmenyjelzo terulet
			this.result_indicator = container.getElement('div.szavazas_result');

			// szavzas allasa indulaskor (%-ban, benne kell lennie a HTML kodban)
			this.result = this.result_indicator.getStyle('width');

			// nullazzuk a vote jelzest
			this.showVote(0);

			// gombokra eventek (over: megmutatja, mit szavaz, klikk: elkuldi)
			this.vote_area.getElements('a').each
			(
			function(but)
			{
				var vote = but.get('text').toInt();
				but.addEvents({
					'mouseover': function(){this.showVote(vote);}.bind(this),
					'mouseout': function(){this.showVote(0);}.bind(this),
					'click': function(e){e.stop();this.sendVote(vote);}.bind(this)
				});
			}.bind(this)
			);

			// szavazao terulet folotti kurzoran nem kell az eredmeny jeloles
			this.vote_area.addEvents({
				'mouseenter': function() {this.result_indicator.setStyle('width', 0);}.bind(this),
				'mouseleave': function() {this.result_indicator.setStyle('width', this.result);}.bind(this)
			});
		}
		// END ha van szavazo gomb
	},


	// szavazas megmutatasa: jelzi, hogy melyik szavazatlehetoseg fole viszi a kurzort
	showVote: function(vote)
	{
		// hatter pozicioja
		var pos = 0 - ((this.options.max_vote-vote)*this.options.vote_butt_wid);
		// beallijuk
		this.vote_area.setStyle('background-position', pos);
	},


	// szavazat elkuldese
	sendVote: function(vote)
	{
		var req = new Request.HTML(
		{
			url:'/AJAXF/jatek_vote',
			method: 'post',
			data: 'jatekv=' + this.jatekv_id + '&vote=' + vote + '&jatek=' + JATEK_ID,
			//evalScripts:true,
			//update: 'contentLeft',
			onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript)
			{
			if ($chk(responseHTML))
			{
				// kontenerbe beirjuk a koszike szoveget
				this.container.set('html', 'Köszönjük, hogy értékelted a játékot (pontszámod: '+vote+')');

				// kis eredemenyjelzo teruleten jeloljuk
				if (small_res_area = $('Jatekv_ertekeles_small_'+this.jatekv_id))
				{
					// "bekapcsoljuk" a kis teruletet
					small_res_area.getElement('div.szavazas_result').setStyle('width', responseHTML);
					small_res_area.getElement('div.szavazas15').setStyle('display', 'block');

					// minusz eltunik, ha van
					if (minusz = small_res_area.getElement('span.minusz'))
						minusz.setStyle('display', 'none');
				}
			}
			}.bind(this)
		}).send();
	}
});
//










function version_switcher()
{
	// a versionSwitcher classu a-kra kattintva valt a verzio
	if (btns = $$('a.versionSwitcher'))
	{
		btns.each(function(btn)
		{
			// verzio id bent van a gomb id tagjeben
			var version_id = btn.id.replace('version_switcher_', '').toInt();

			// gombokra kattintva nyitott verzio valtas
			btn.addEvent('click', function(e)
			{
				e.stop();

				if (version_id!=ACTIVE_VERSION_ID && btns.length>1)
				{
					// szurke a jelenlegi aktivra
					$('Intro_container_'+ACTIVE_VERSION_ID).addClass('game_container_gray');
					// szurke nemkell az uj aktivra
					$('Intro_container_'+version_id).removeClass('game_container_gray');

					// bezarjuk a jelenlegi aktivot
					$('Detail_container_'+ACTIVE_VERSION_ID).addClass('nodisp');
					// kinyitjuk az uj aktivot
					$('Detail_container_'+version_id).removeClass('nodisp');

					// beallitjuk az uj aktiv verziot
					ACTIVE_VERSION_ID = version_id;

					// ajaxszal elkuldjuk a szervernek az aktiv verziot, hogy be tudja tenni sessionbe
					var req = new Request.HTML(
					{
						url:'/AJAXF/jatek_versionswitcher',
						method: 'post',
						data: 'jatekv=' + version_id + '&jatek=' + JATEK_ID,
						//evalScripts:true,
						//update: 'contentLeft',
						onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript)
						{
							//alert(responseHTML);
						}
					}).send();

				}

			});
		});
	}

	//alert(ACTUAL_VERSION_SER);
}










// betolteskor #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
window.addEvent('domready', function()
{
	// alapok
	var spl = $('Jatek_info').get('text').split('|');
	JATEK_ID = spl[0];
	ACTIVE_VERSION_ID = spl[1];

	// verzio valto
	version_switcher();


	// szavazasok a jatek verziokra
	$$('div.JatekvSzavazas').each(function(cnt_)
	{
		new Szavazas(
		{
			vote_butt_wid: 31,
			max_vote: 5
		},
		cnt_
		);
	});


	//
	if (buttons_ = $$('h5.Jatekv_more_comments_btn'))
		show_all_version_comments(buttons_)
}
);




