// $ID: bvk-video.js, Fri Jan 13 2012 18:37:04 GMT+0300 (MSK), Leonid 'n3o' Knyazev $
var popup = {
	inited : false,
	opened : false,

	flashvars : {
		css: "/f/1/bvk/overview/default.css",
		skin: "/f/1/global/flash/default.swf",
		bgColor: "16777215",
		autoplay: 1,
		video : '/f/1/bvk/overview/bvk-video-1.f4v'
	},

	params : {
		allowFullscreen: "true",
		allowScriptAccess: "always",
		wmode: "transparent"
	},

	layout : null,
	popup	: null,
	obj: null,

	init : function () {
		this.layout = $('.page');
		this.popup = $('<div id="popup" class="popup-hidden"><div class="corner lt"></div><div class="corner rt"></div><div class="shadow right iesizing-scale"></div><div class="icon close"></div><div class="content"><div id="flash_content"/></div><div class="shadow left iesizing-scale"></div><div class="corner lb"></div><div class="corner rb"></div></div>');

		this.popup.css({
			width: '765px',
			height: '406px'
		});

		this.layout.prepend(this.popup);


		this.popup.find('.close').click(function() {
			popup.close();
		});

		this.inited = true;
	},

	open : function () {
		this.popup.removeClass('popup-hidden');
		this.opened = true;
		this.obj = swfobject.embedSWF("/f/1/global/flash/SubtitlesPlayer.swf", "flash_content", "627", "406", "9.0.0", "/f/1/global/flash/expressInstall.swf", this.flashvars, this.params, null);
	},

	close : function () {
		this.opened = false;
		var html = $('#popup .content').html();
		swfobject.removeSWF("flash_content");
		this.popup.addClass('popup-hidden');
		$('#popup .content').html( html );
	},

	toggle : function () {
		if (!this.inited) this.init();

		if (this.opened) {
			this.close();
		} else {
			this.open();
		}
	}
};


$(function () {
	var _video_link = $('.bvk-video-link');

	_video_link.bind('click', function () {
		popup.toggle();

		return false;
	});
});
