
/**
 * Provides modal layering for "popups".
 * A modal layer is basically a big black div
 * which is stacked between a popup and the rest
 * of the page giving focus to the popup
 */
Modal = function()
{
	/**
	 * Holds a jQuery pointer to the modal layer 1 element
	 * @type jquery
	 */
	var jLayer1 = null
	
	/**
	 * Holds a jQuery pointer to the modal layer 2 element
	 * @type jquery
	 */
	var jLayer2 = null

	
	/**
	 * Initialise the modal system
	 * @return void
	 */
	function init()
	{
		// create the actual modal element
		jLayer1 = $(document.createElement('div'))
		jLayer1.attr("id", "modalLayer1")
		jLayer1.html("&nbsp;")
		$("body").append(jLayer1)
		
		// create the actual modal element
		jLayer2 = $(document.createElement('div'))
		jLayer2.attr("id", "modalLayer2")
		jLayer2.html("&nbsp;")
		$("body").append(jLayer2)
	}
	
	/**
	 * Activate the modal layer making it visible
	 * @param [int] An integer with the layer to show (defaults to 1)
	 * @return void
	 */
	function on(layerNum)
	{
		/*
		if (typeof(layerNum) == 'undefined')
		{
			layerNum = 1
		}*/
		
		switch (layerNum)
		{
			case 2:
			{
				Debug.trace("modal 2 on")
				jLayer2.show()
				break;
			}
			
			default:
			{
				Debug.trace("modal 1 on")
				jLayer1.show()
				break;
			}
		}
	}
	
	/**
	 * Deactivate the modal layer making it invisible
	 * @param [int] An integer with the layer to hide (defaults to 1)
	 * @return void
	 */
	function off(layerNum)
	{
		switch (layerNum)
		{
			case 2:
			{
				Debug.trace("modal 2 off")
				jLayer2.hide()
				break;
			}
			
			default:
			{
				Debug.trace("modal 1 off")
				jLayer1.hide()
				break;
			}
		}
	}

	return {
		"init" : init,
		"on" : on,
		"off" : off
	}
}()

$(document).ready(function()
{
	Modal.init()
})
