/*  Class Informer
/*--------------------------------------------------------------------------*/
var Informer = Class.create();

Informer.prototype = {
	initialize: function () {
		var options = Object.extend({
			showTime: 1,
			duration: 0.5
		}, arguments[0] || {});

		var body_node = $$('body')[0];

		body_node.appendChild($(Builder.node('div', {id: 'informer'}, [
			Builder.node('div', {className: 'wrap'}, [
				Builder.node('h4', {id: 'informer_caption'}),
				Builder.node('p', {id: 'informer_message'}),
				Builder.node('div', {className: 'button'}, [
					Builder.node('a', {id: 'informer_button_continue', href: '#'})
				]),
				Builder.node('div', {className: 'button'}, [
					Builder.node('a', {id: 'informer_button_order', href: '/cart/'})
				])
			])
		])).hide());

		this.container = $('informer');
		this.caption = $('informer_caption');

		this.message = $('informer_message');
		this.message.update('Спасибо.<br/>Товар добавлен в Ваш заказ.');

		this.buttons = [];
		this.buttons['continue'] = $('informer_button_continue');
		this.buttons['order'] = $('informer_button_order');
		this.buttons['continue'].update('Продолжить покупки');
		this.buttons['order'].update('Начать оформление заказа');

		this.buttons['continue'].observe('click', function (event) {
			event.stop();
			this.container.hide();
			this.stopTimer();
			this.stopEffect();
		}.bindAsEventListener(this));

		this.effect = null;
		this.timer = null;
		this.options = options;
	},

	show: function (caption, message, continue_text, order_text, order_link) {
		if (caption) this.caption.update(caption);
		if (message) this.message.update(message);

    // Разные надпися
		if(continue_text) this.buttons['continue'].update(continue_text);
		if(order_text) this.buttons['order'].update(order_text);
		if(order_link) this.buttons['order'].setAttribute('href',order_link);

		var scroll_offsets = document.viewport.getScrollOffsets();

		x = (document.viewport.getWidth() - this.getWidth()) / 2 + scroll_offsets[0];
		y = (document.viewport.getHeight() - this.getHeight()) / 2 + scroll_offsets[1];

		if (x) this.container.setStyle({left: x+'px'});
		if (y) this.container.setStyle({top: y+'px'});

		this.container.show();

		//this.reset();
		//this.startTimer();
	},

	showError: function (caption, message, x, y) {
		this.show(caption, '<span style="color:#f00">'+ message +'</span>', x, y);
	},

	reset: function () {
		this.stopTimer();
		this.stopEffect();

		if (this.container) {
			this.container.setStyle({opacity: 0.9999});
			this.container.show();
		}
	},

	startTimer: function() {
		this.timer = new PeriodicalExecuter(function (timer) {
			this.startEffect();
			timer.stop();
		}.bind(this), this.options.showTime);
	},

	stopTimer: function() {
		if (this.timer) {
			this.timer.stop();
			this.timer = null;
		}
	},

	startEffect: function () {
		this.effect = new Effect.Fade(this.container, {duration: this.options.duration});
	},

	stopEffect: function () {
		if (this.effect) {
			this.effect.cancel();
			this.effect = null;
		}
	},

	getWidth: function() {
		return this.container.getDimensions().width;
	},

	getHeight: function() {
		return this.container.getDimensions().height;
	}
}

