





// termek kep kinagyito   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
function termek_pics()
{
	var pics = $A($$('img.termek_foto_thumb'));

	pics.each
	(
		function(p)
		{
			p.addEvent('click', function()
			{
				// nagykep src
				var termek_id = p.getProperty('name').replace('tpic', '').toInt();

				//alert(termek_id);
				popwindow(625, 675, '/popup_content/termekgaleria.php?t='+termek_id);
			});
		}
	);
}
//










// termek ajanlas layer   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
var Termek_ajanlas = new Class
({

	initialize: function()
	{
		// hozzarendeli
		var ajanlasbutton = $E('a.ajanlas');
		ajanlasbutton.addEvent('click', function(){this.ajanl(ajanlasbutton)}.bind(this));

	},

	ajanl: function(button)
	{
		// termek id
		var termek_id = button.getProperty('id').replace('ajanlas_', '').toInt(); //alert(termek_id);

		//
		this.ajlayer = new PopDialog();

		// tartalom ajaxosan
		new Ajax('/remote/recommend_product.php',
		{
			method: 'post',
			data: 'action=start&termek=' + termek_id,
			evalScripts: true,
			onComplete: function(response)
			{//alert(response);

				// kirakjuk a dialogot
				this.ajlayer.show(response);
				//this.remote_process(this);
	
			}.bind(this)
		}).request();
		//
	}
	//


});
// END termek ajanlas layer










// kosar gombok  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
var Kosarbuttons = new Class
({

	initialize: function ()
	{
		// hozzarendeljuk ha van kosargomb
		if (k = $E('input.addToCart_btn'))
			k.addEvent('click', function(){this.add_to_cart(k)}.bind(this));
	},



	//
	add_to_cart: function(k)
	{
		// termek id
		var termek_id = k.id.replace('addToCart_btn_', ''); //alert(termek_id);

		// termek szam
		var termek_num = $('addToCart_num_'+termek_id).getValue(); //alert(termek_num);


		// berakas siker ajax
		if (termek_num>0)
		{
			// kosar
			new Ajax('/remote/add_to_cart.php',
			{
				method: 'post',
				data: 'termek=' + termek_id + '&num=' + termek_num,
				//update: $('cartQuantity')//,
				onComplete: function(response)
				{//alert(response);

					var Addttocart_dialog = new PopDialog();
					//Addttocart_dialog.show(350, 250, response);
					Addttocart_dialog.show(response);

					$('addtocart_close').addEvent('click', function(){Addttocart_dialog.hide()});
				},
				evalScripts: true
			}).request();
		}
		// ha nem oke a termekszam, akkor figyelmeztetjuk
		else
		{
			var d = new PopDialog()
			//d.show(350, 120, '<div class="addcart_error">Adja meg a darabszámot</div>');
			d.show('<div class="add2cart_content"><div class="title add2cart_title "></div><div class="text"><br/><br/>Adja meg a darabszámot!</div></div>');
		}
	}
});










// subtermek adat berako fuggveny  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
function subtermek(id)
{
	// dropdown elem
	var drop = $(id);

	// valasztott subtermek id
	var sub_id = drop.getValue(); //alert(sub_id);

	// termek id
	var termek_id = drop.id.replace('sub_dropdown_', '');	//alert(termek_id);

	// data container
	var s1Cnt = $('dyn1_data_'+termek_id); //sCnt.setHTML('t:'+termek_id+'s'+sub_id);
	// ikon container
	var s2Cnt = $('dyn2_data_'+termek_id); //sCnt.setHTML('t:'+termek_id+'s'+sub_id);

	// adaokt ajaxbul
	new Ajax('/remote/subtermek_data.php',
	{
		method: 'post',
		data: 'blokk=' + termek_id + '&sub=' + sub_id,
		//update: s1Cnt
		onComplete: function(response)
		{
			//alert(response);
			var respS = response.split('|||');
			s1Cnt.setHTML(respS[0]);
			s2Cnt.setHTML(respS[1]);
		}
	}).request();

}










// betoltes utan lefut
window.addEvent('load', function(){

	// kosar gombok
	Kosarbuttons_obj = new Kosarbuttons();

	// termekfotok
	if ($$('img.termek_foto_thumb'))
		termek_pics();

	// termek ajanlas
	if ($E('a.ajanlas'))
		Termek_ajanlas_obj = new Termek_ajanlas();

/*
	// termek tooltips MAR NEMKELL
	if ($$('a.ajanlas'))
		TermekTooltips = new Termektooltip_();
*/

});
