jQuery.noConflict();
var popupStatus = 0;
var loadedPopup = "";

function loadPopup(id){
	if(popupStatus == 0){
		jQuery("#lightbox_bg").css({
			"opacity": "0.8"
		});
		
		centerPopup(id);		
		jQuery("#lightbox_bg").fadeIn("slow");		
		jQuery(id).fadeIn("slow");		
		popupStatus = 1;
		loadedPopup = id;
	}
}

function centerPopup(id){
	var windowWidth = parseInt(document.getElementById('container').offsetWidth);
	var windowHeight = parseInt(document.getElementById('container').offsetHeight);
	var popupHeight = jQuery(id).height();
	var popupWidth = jQuery(id).width();
	
	
	//windowHeight/2-popupHeight/2
	jQuery(id).css({
		"position": "absolute",
		"top": 200,
		"left": windowWidth/2-popupWidth/2
	});
}

function disablePopup(){
	if(popupStatus == 1){
		jQuery("#lightbox_bg").fadeOut("slow");
		jQuery(loadedPopup).fadeOut("slow");
		popupStatus = 0;
		loadedPopup = "";
	}
}

jQuery(document).ready(function(){			
	jQuery("#player_launch").click(function(){
		loadPopup('#lightbox');
		return false;
	});
	
	jQuery("#player_launch_button").click(function(){
		loadPopup('#lightbox');
		return false;
	});
	
	jQuery("#lightbox_bg").click(function(){
		disablePopup();
	});
	
	jQuery("#close_btn").click(function(){
		disablePopup();
	});
	
	jQuery(document).keypress(function(e){
		if(e.keyCode == 27 && popupStatus == 1){
			disablePopup();
		}
	});
});
