(function($) {
	$(function() {
		var popup_cont = $('#popup');
		var video_cont = popup_cont.children();
		var video_object = video_cont.children('object');

		if(video_object.length) {
			var video_code = video_cont.html();
			var popup_cont_width = video_object.attr('width');
			var popup_cont_height = video_object.attr('height');
			popup_cont.css({
				height : popup_cont_height,
				width : popup_cont_width,
				marginLeft : -Math.floor(popup_cont_width / 2),
				marginTop : -Math.floor(popup_cont_height / 2)
			});

			function closePopup() {
				popup_cont.hide('slow', function() {
					popup_bg.hide();
					video_cont.html('');
				});
			};

			var body = $('body');
			var closebtn = $('<div class="closebtn" />').click(closePopup).appendTo(popup_cont);
			var popup_bg = $('<div>').css({
				background : '#FFF',
				position : 'fixed',
				top : 0,
				left : 0,
				zIndex : 1000,
				display : 'none'
			}).click(closePopup).appendTo(body);

			$('.cat_video img').click(function() {
				var w = $(window);
				popup_bg.css({
					height : w.height(),
					width : w.width()
				})
				if(video_cont.html() == '') {
					video_cont.html(video_code);
				}
				popup_bg.fadeTo(0, 0.5, function() {
					popup_cont.show('slow');
				});
			});
		}
	});
})(jQuery)
