/*!
 * Мини-контрол для управления презентациями
 */

if (Object.isUndefined(eRabota)) { var eRabota = { } };

eRabota.promoManager = Class.create({
	
	initialize: function(name, element) {
		this.name = name;
		this.element = $(element);
		this.teaser = this.element.down('.promo-teaser');
		this.links = this.element.down('.promo-links');
		this.slides = this.element.down('.promo-slides');
		
		this.is_hidden = Cookie.get(this.name) || false;
		this[this.is_hidden ? 'hide' : 'show']();
	},
	
	show: function() {
		if (this.teaser) {
			this.teaser.hide();
		}
		this.links.show();
		this.slides.show();
		new Carousel(this.slides, this.slides.select('ul li'), this.element.select('.promo-links ul li a.carousel-jumper, .promo-slides li a.carousel-jumper'), {duration: 0.5, wheel: false});
		if (this.element.down('.closer')) {
			this.element.down('.closer').observe('click', this.hide.bindAsEventListener(this));
		}
		Cookie.erase(this.name);
	},
	
	hide: function() {
		if (this.teaser) {
			this.teaser.show();
		}
		this.links.hide();
		this.slides.hide();
		this.teaser.observe('click', this.show.bindAsEventListener(this));
		Cookie.set(this.name, true, 365);
	}
	
});

