/************************************************ 
 * Copyright © 2009 FL-2. All Rights Reserved.  *
 * Updated by: Matt Wiggins, 26-Feb-2009        *
 *                                              *
 * Simple class to open and close modals on a   *
 * semi-opaque background with a simple fade.   *
 *                                              *
 * NOTE: Requires jQuery.                       *
 ************************************************
/                                              */
ModalController = {
	_ready:false,
	_objModalBg:null,
	_currentOpen:null,
	
	/************************************************ 
	 * init:void                                    *
	 *                                              *
	 * NOTE: a call to this method is required and  *
	 * must be made after the document is ready     *
	 ************************************************
	/                                              */
	init: function()
	{	
		if(typeof($) == 'undefined')
		{
			// if jQuery hasn't joined the party ...
			throw("Error: jQuery is required for this page to function properly.");
			return;
		}
		ModalController._objModalBg = document.createElement("div");
		ModalController._objModalBg.id = "fl2-modal-bg";
		
		// append the modal bg div to the body
		document.body.appendChild(ModalController._objModalBg);
		
		$(ModalController._objModalBg).click(function() {
			ModalController.closeModal();
		});
		
		ModalController._ready = true;
	},
	
	/************************************************ 
	 * openModal:void                               *
	 *                                              *
	 * fade in bg, open passed modal on             *
	 * fade callback                                *
	 *                                              *
	 * modal:Object - modal to open                 *
	 ************************************************
	/                                              */
	openModal: function(modal)
	{
		if(!ModalController._ready || !ModalController._currentOpen == null) return;
		
		ModalController._currentOpen = modal;
		ModalController._objModalBg.style.width = "100%";
		ModalController._objModalBg.style.height = $(document).height() + 'px';
		ModalController._currentOpen.style.top = $(document).scrollTop() + '50%';
		
		$(ModalController._objModalBg).css('filter','alpha(opacity=85)').fadeIn("slow", function() {
			ModalController._currentOpen.style.display = "block";
			
			// NOTE: hacked for Alem
			if(showPlayer) $('#media').html(playerEmbed);
		});
	},
	
	/************************************************ 
	 * closeModal:void                              *
	 *                                              *
	 * close passed modal, fade out bg              *
	 ************************************************
	/                                              */
	closeModal: function()
	{
		if(!ModalController._ready || ModalController._currentOpen == null) return;
		
		// NOTE: hacked for Alem
		if(showPlayer) $('#media').html('');
		
		ModalController._currentOpen.style.display = "none";
		$(ModalController._objModalBg).fadeOut("slow");
	}
};