




// promo box kezelo
var PromoPager = new Class 
({
	// optionok
	Implements: Options,
	options: {
		container: false,
		interval: 4000
	},


	initialize: function(options)
	{
		// optionok jonnek
		this.setOptions(options);

		// ha jott kontener es jo is
		if (this.options.container)
			this.promo = $(this.options.container);
		if (this.promo)
		{
			// promo box
			this.promo = $(this.options.container);
			
			// tartalmak a promo boxban
			this.contents = this.promo.getElements('div.PromoContent');

			// alap az elso content
			this.active_ser = 0;

			// prev/next gomb ha van
			if (next_button = this.promo.getElement('a.arrow_next'))
				next_button.addEvent('click', function(e){e.stop();this.turnContent('next');}.bind(this));
			if (prev_button = this.promo.getElement('a.arrow_prev'))
				prev_button.addEvent('click', function(e){e.stop();this.turnContent('prev');}.bind(this));

			// oladlszamokra ugras (ha vannak gombok)
			this.promo.getElements('a.page').each
			(
			function(btn)
			{
				btn.addEvent('click', function(e)
				{
					e.stop();
					var p = btn.get('class').replace('page p', '').toInt();
					p = p-1;
					this.slideShowControl('stop')
					this.setContent(p);
					this.slideShowControl('start')
				}.bind(this));
			}.bind(this)
			);

			// elindul a slideshow
			this.slideShowControl('start');
		}
	},


	// content lapozas (elore, vagy hatra)
	turnContent: function(direction)
	{
		var turn_ser = 0;

		if (direction=='next')
		{
			turn_ser = ((this.active_ser+1)<this.contents.length) ? this.active_ser+1 : 0;
		}

		if (direction=='prev')
		{
			turn_ser = (this.active_ser>0) ? this.active_ser-1 : this.contents.length-1;
		}

		//
		this.slideShowControl('stop')
		this.setContent(turn_ser);
		this.slideShowControl('start')
		//alert(turn_ser);
	},


	// beallitja az aktiv contentet
	setContent: function(ser)
	{
		// ha van adott sorszamu content
		if (this.contents[ser] && this.contents[this.active_ser])
		{
			// a jelenlegi aktiv eltunik
			this.contents[this.active_ser].setStyle('display', 'none');

			// uj aktiv latszik
			this.contents[ser].setStyle('opacity', 0);
			this.contents[ser].setStyle('display', 'block');
			this.contents[ser].fade('in');

			// az uj lesz az aktiv
			this.active_ser = ser;
		}
	},


	// slideshow vezerles
	slideShowControl: function(control)
	{
		if(control=='start')
			this.slideShowId = this.slideShow.periodical(this.options.interval, this);

		if (control=='stop')
		{
			if (this.slideShowId)
				$clear(this.slideShowId);
		}
	},


	// slideshow fuggveny
	slideShow: function()
	{
		// a jelenlegi aktivrol indul
		var s = this.active_ser;

		// kovetkezo aktiv megallapitas
		if (s<this.contents.length-1)
			s++;
		else
			s = 0;

		// beallito fuggveny
		this.setContent(s);
	}
});










window.addEvent('domready', function()
{
	new PromoPager({
	  container: 'Promo1',
	  interval: 5000
	});

	new PromoPager({
	  container: 'Promo2',
	  interval: 3000
	});
});






