/**
 * AS4Login
 * AJAX powered login functions for the AS4 application
 */

// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
// Document-load events

document.observe('dom:loaded', function() 
{
		
})


// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
// Class declaration

var AS4Login = Class.create({
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

	/**
	 * @type {string} The current display mode
	 */ 
	displayMode: null,


	/**
	 * @type {integer} currentChannel The currently loaded channel/folder id. Null will load the ROOT_PATH.
	 */
	currentChannel: null,

	// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
	
	/**
	 * @constructor
	 */
	initialize: function()
	{
		this.currentChannel = this.ROOT_PATH;
		this.displayMode = this.LIST_DISPLAY;
	},

	// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
	// AJAX methods

	/**
	 * Event triggered when the loadFolderContents returns content
	 */
	showLoginLightbox: function()
	{
		// show a lightbox login form
			var params = {
				callback: this.onShowLoginLightbox.bind(),
				width: 400,
				height: 200
			};
			
			if(AS4Shell.getInstance().userLoggedIn === false)
				AS4Shell.getInstance().showLightbox(params); 
				
		return;
	},

	// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
	// AJAX callback methods
	
	/**
	 * Callback method to load the add panel content into the shell lightbox
	 * @return string
	 */
	onShowLoginLightbox: function()
	{
		var url = '/secure/login';
		var params = {
			renderMode: 'lightbox',
      http_referer: window.location.href
		};
		
		AS4Shell.getInstance().ajaxUpdate(url, params, 'secure_login_lightbox', $A(), {showIndicator: false});
		
		return	'<div id="secure_login_lightbox">' +
					'<div class="centre" style="padding-top: 40%">' +
						'<img src="/app/common/assets/images/ajax-loader.gif" alt="Loading..>" width="24" height="24" /><br />Loading...' +
					'</div>' +
				'</div>';
		
	}
	
});


 
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
// Static Methods & Properties

// Static instance of the AS4Login object
AS4Login.instance = null;

/**
 * Return a singleton instance of the AS4Login object
 * @return AS4Login
 */
AS4Login.getInstance = function()
{
	if(!AS4Login.instance)
		AS4Login.instance = new AS4Login();
		
	return AS4Login.instance;
}
 

