var ppcdFlash = {
	config: {
		cookieName: 'ppcdShowFlash'
	},

	init: function() {
		this.showDialog();
		if (this.isShow()) this.show();

		this.link();
	},

	show: function() {
		swfobject.embedSWF("/images/flash/index2.swf", "flash", "970", "305", "8.0.0");
//		var so = new SWFObject("/images/flash/index2.swf", "flash_head", "1600", "250", "8", "#fff", "high");
//		so.addParam("wmode", "opaquo");
//		so.write("flash");
	},

	isShow: function() {
		return (1 == this.getCookie( this.config.cookieName ));
	},

	turnOff: function() {
		this.setCookie( this.config.cookieName, 0 );
		window.location.reload();
		return false;
	},

	turnOn: function() {
		this.setCookie( this.config.cookieName, 1 );
		window.location.reload();
		return false;
	},

	link: function() {
		if ($('ppcdFlashLink')) $('ppcdFlashLink').remove();

		var a = new Element('A', {
			'class': 'ppcdFlash',
			'href': '',
			'id': 'ppcdFlashLink'
		});
		a.setStyle({
			color: 'red',
			fontWeight: 'bold',
			fontSize: '11px',
			left: '0px',
			bottom: '0px',
			padding: '2px',
			marginLeft: '13px',
			position: 'absolute',
			whiteSpace: 'nowrap'
		});

		if (this.isShow()) {
			a.onclick = this.turnOff.bind(this);
			a.update('Убрать анимацию');
		} else {
			a.onclick = this.turnOn.bind(this);
			a.update('Включить анимацию');
		}

		$('flash').insert({after: a});
	},

	setCookie: function(name, value) {
		document.cookie=name+"="+escape(value)+"; expires=Wed, 31 Dec 2025 23:59:59 GMT; path=/";
	},

	getCookie: function(szName) {
		szName = szName.replace(/\./g, "_");

		var i = 0;
		var nStartPosition = 0;
		var nEndPosition = 0;
		var szCookieString = document.cookie;

		while(i <= szCookieString.length) {
			nStartPosition = i;
			nEndPosition = nStartPosition + szName.length;

			if(szCookieString.substring(nStartPosition,nEndPosition) == szName) {
				nStartPosition = nEndPosition + 1;
				nEndPosition = document.cookie.indexOf(";",nStartPosition);
				if(nEndPosition < nStartPosition) nEndPosition = document.cookie.length;
				return document.cookie.substring(nStartPosition,nEndPosition);
				break;
			}
			i++;
		}
		return '';
	},

	showDialog: function() {
		return; // попросили диалог убрать, Case 3935
		if ('' != this.getCookie( this.config.cookieName )) return;

		var t = this;
		var div = new Element('DIV').addClassName('ppcdFlashDialog');

		var aon = new Element('A');
		aon.onclick = function() {
			div.remove();
			t.setCookie( t.config.cookieName, 1 );
			t.show();
			t.link();
			return false;
		}
		aon.update( 'Показывать анимацию' );

		var aoff = new Element('A');
		aoff.onclick = function() {
			div.remove();
			t.setCookie( t.config.cookieName, 0 );
			return false;
		}
		aoff.update( 'Без анимации' );

		$( document.body ).insert( {'top': div} );
		div.insert( {'top': aon} );
		div.insert( {'bottom': aoff} );
	}
};

Event.observe(window, 'load', ppcdFlash.init.bind( ppcdFlash ));
