/*====================================*\
|| ################################## ||
|| # iDeal 2.0 Ajax Core            # ||
|| # ------------------------------ # ||
|| # Copyright ©2008 MediaPulse     # ||
|| # ------------------------------ # ||
|| # Revision Alpha                 # ||
|| ################################## ||
\*====================================*/

/**
 * Singleton Class instance, an anchor point for all functions and variables
 * we use.
 */
var iDeal = {
	/**
	 * Flag of whether we are in debugging mode.
	 * @var boolean
	 * @access public
	 */
	debug: false,
	
	/* Console object. We start with a null object so console calls don't produce errors.
	 *
	 * @var object
	 * @access public
	 */
	console: {
		log: function(){},		
		debug: function(){},
		info: function(){},
		warn: function (){},
		error: function(){},
		assert: function(){},
		dir: function(){},
		dirxml: function(){},
		trace: function(){},
		group: function(){},
		groupEnd: function(){},
		profile: function(){},
		profileEnd: function(){},
		count: function(){}		
	},
	
	/**
	 * Initialize Function
	 *
	 */
	initialize: function() 
	{
		// If Firebug is available we will use it's console, otherwise we use the null console above.
		if (typeof(console) == 'object' && typeof(console.group) == 'function') 
		{
			this.console = console;
		}
		
		// Console Greeting Message
		this.console.group ('iDeal Platform started');
		this.console.log('(c) 2008 mediaPulse \n Knoxville TN \n www.mediapulse.com');
		
		// Notify that we are debugging.
		if (this.debug)
		{
			this.console.log( 'Debugging Mode Activated.' );
		}
				
		// This ends the page opening stuff
		this.console.groupEnd();
		
		// Now fire the onload events specific to the page.
		this.onLoad();
	},
	
	/**
	 * onLoad Function. Pages will populate this function as needed. 
	 * 
	 * @param event object (optional)
	 * @return void
	 * @access public
	 */
	onLoad: function() { },
	
	/**
	 * Final Error handler. When in debug mode we'll display errors normally,
	 * otherwise cover them up.
	 *
	 * @return boolean
	 * @access public
	 */
	onError: function(e)
	{
		if (!this.debug)
		{
			return true;
		}
		else
		{
			this.console.log(e.message);
		}
	}
};

Event.observe( window, 'load', iDeal.initialize.bindAsEventListener(iDeal));

window.onerror = iDeal.onError.bindAsEventListener(iDeal);