jQuery.fn.center = function () {
	this.css("position","fixed");
	this.css("top", ( $(window).height() - this.outerHeight() ) / 2 + "px");
	this.css("left", ( $(window).width() - this.outerWidth() ) / 2 + "px");
    return this;
}

jQuery.jwbox_Video = {
	lightbox	:	null,
	player	: null,
	toggle	: function(context) {
		if (!$.jwbox_Video.lightbox) {
				$.jwbox_Video.lightbox = $(".jwbox_hidden", context);
				$.jwbox_Video.center();
				$("#jwboxVideo_background").fadeIn("fast");
				$.jwbox_Video.lightbox.css("display","block")
				$.jwbox_Video.center();
				$("#jwboxVideo_background").fadeTo(0, 0.5);
				$("object", context).each(function(){
					$.jwbox_Video.player = document.getElementById(this.id);
				});
		} else if ((context.className == 'jwbox_content')) {
		} else {
			try {
				$.jwbox_Video.player.sendEvent("STOP");
				$.jwbox_Video.player = null;
			} catch (err) {  
			}
			$.jwbox_Video.lightbox.css("display","none");
			$.jwbox_Video.lightbox = null;
			$("#jwboxVideo_background").fadeOut("fast");
		}
	},
	center	: function() {
		if ($.jwbox_Video.lightbox) {
			$.jwbox_Video.lightbox.center();
		}
	}
}

$(document).keyup(function(event){
    if (event.keyCode == 27 && $.jwbox_Video.lightbox) {
		$.jwbox_Video.toggle($("#jwboxVideo_background"));
    }
});

$(document).ready(function () {
	$("body").append('<div id="jwboxVideo_background">&nbsp;</div>');
	$(".jwbox_Video").click(function () {$.jwbox_Video.toggle(this); return false;});
    $(".btnCloseVideo").click(function () {$.jwbox_Video.toggle(this); return false;});
    $("#jwboxVideo_background").click(function () {$.jwbox_Video.toggle(this); return false;});
	$(".jwbox_content").click(function () {$.jwbox_Video.toggle(this); return false;});
	$(window).resize(function() {$.jwbox_Video.center();});
});