/**
 * Function to show/hide an overlay + popup
 *
 * @package 	DigiCMS v3.x
 * @file		js/functions/overlay_popup.js
 * @version		3.0.0
 * @author		Digitalization
 * @email		info@digitalization.nl
 * @link		http://www.digitalization.nl/
 * @copyright	All code copyright 2009,2010 by Digitalization
 */

function popup_show(title, contents, width, height) {

	//Initialize the overlay and popup vars
	var overlay = $("div#overlay");
	var popup   = $("div#popup");

	//Create and append the elements to the HTML if they don't exist yet
	if ($(overlay).length == 0) {
		overlay = $("<div id='overlay'></div>").appendTo($('body'));
	}
	if ($(popup).length == 0) {
		popup = $("<div id='popup'></div>").appendTo($('body'));
	}

 	//Set the title and contents of the pop-up

 	$(popup).html("<div id='popup_header'><h1>"+title+"</h1><div class='close'><a href='javascript:void(0);' onclick='popup_hide();'>X</a></div></div><div class='clear'></div><div class='content'>"+contents+"</div>");

 	//Determine width/heigh (or take manual input)
 	if (!width) {
 		width = $(popup).css('width');
	}
 	if (!height) {
 		height = $(popup).css('height');
	}

	//Determine margins
	$(popup).css('width', 	 	width);
	$(popup).css('margin-left', -1 * (width / 2) );
	$(popup).css('height', 	 	height);
	$(popup).css('margin-top', 	-1 * (height / 2) );

 	//Display the overlay and popup
 	$(overlay).fadeIn(250);
 	$(popup).fadeIn(250);
}

function popup_hide() {
	$("div#popup").fadeOut(250);
	$("div#overlay").fadeOut(250);
}
