var popup = {
    current: null,
	init: function()
	{
		$('#popup-background').click(popup.close);
        this.current.find('.close').unbind('click');
		this.current.find('.close').click(function ()
		{
			popup.close();
			return false;
		});
	},
	open: function(id)
	{
        if (this.current != null)
        {
            this.close();
        }
        this.current = $('#' + id);

        var top = $(window).scrollTop();
        if (this.current.height() < ($(window).height() - 100))
        {
            top += ($(window).height() - this.current.height()) / 2;
        }
        else
        {
            top += 50;
        }

		this.current
            .css('left', (($(document).width()/2)-(this.current.width()/2)) + 'px')
            .css('top', top + 'px')
            .show();

		this.showBackground();
		popup.init();

	},
	close: function()
	{
        if  (popup.current != null)
        {
            popup.current.find('.close').unbind('click');
            popup.current.hide();
        }
        popup.hideBackground();
	},
    showBackground: function()
    {
      $('#popup-background').css('height', $(document).height() + 40).show();
    },
    hideBackground: function()
    {
        $('#popup-background').hide();
    }
}
