var $x = jQuery.noConflict();
jQuery.fn.center = function () {
	this.css("position","fixed");
	this.css("top", ( $x(window).height() - this.outerHeight() ) / 2 + "px");
	this.css("left", ( $x(window).width() - this.outerWidth() ) / 2 + "px");
    return this;
}

jQuery.jwbox = {
	lightbox	:	null,
	player	: null,
	toggle	: function(context) {
		if (!$x.jwbox.lightbox) {
				$x.jwbox.lightbox = $x(".jwbox_hidden", context);
				$x.jwbox.center();
				$x("#jwbox_background").fadeIn("fast");
				$x.jwbox.lightbox.css("display","block")
				$x.jwbox.center();
				$x("#jwbox_background").fadeTo(0, 0.8);
				$x("object", context).each(function(){
					$x.jwbox.player = document.getElementById(this.id);
				});
		} else if ((context.className == 'jwbox_content')) {
		} else {
			try {
				$x.jwbox.player.sendEvent("STOP");
				$x.jwbox.player = null;
			} catch (err) {
			}
			$x.jwbox.lightbox.css("display","none");
			$x.jwbox.lightbox = null;
			$x("#jwbox_background").fadeOut("fast");
		}
	},
	center	: function() {
		if ($x.jwbox.lightbox) {
			$x.jwbox.lightbox.center();
		}
	}
}

$x(document).keyup(function(event){
    if (event.keyCode == 27 && $x.jwbox.lightbox) {
		$x.jwbox.toggle($x("#jwbox_background"));
    }
});

$x(document).ready(function () {
	$x("body").append('<div id="jwbox_background">&nbsp;</div>');
	$x(".jwbox").click(function () {$x.jwbox.toggle(this); return false;});
	//$x("#jwbox_background").click(function () {$x.jwbox.toggle(this); return false;});
	$x(".jwbox_content").click(function () {$x.jwbox.toggle(this); return false;});
	$x(window).resize(function() {$x.jwbox.center();});
});

