



// 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'))
		{
			// recept id-ja: a container classaban
			this.recept_id = this.container.get('class').replace('R', '').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/recept_vote',
			method: 'post',
			data: 'recept='+this.recept_id+'&vote=' + vote,
			//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 receptet (pontszámod: '+vote+')');

				// kis eredemenyjelzo teruleten jeloljuk
				if (small_res_area = $('Ertkeles_result_small'))
				{
					// "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.setStyle('display', 'none');
				}
			}
			}.bind(this)
		}).send();
	}
});
//










// osszes szolas megmuatasa   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
function show_all_comments(button)
{
	if (cnt = $('More_comments'))
	{
		button.addEvent('click', function(e)
		{
			//
			cnt.setStyle('display', 'block');

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










// fuggvenyek betolteskor  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
window.addEvent('domready', function()
{
	// szavazas
	if (cnt_ = $('Szavazas_box'))
	{
		Szavazas_ = new Szavazas(
		{
			vote_butt_wid: 31,
			max_vote: 5
		},
		cnt_
		);
	}

	//
	if (comment_btn_  = $('More_comments_show'))
		show_all_comments(comment_btn_);
}
);




