/**
	Script: yahoo-init.js
	
	The yahoo-init script will handle initial YUI v2 instance setup and will 
	instantiate a debug console for IE, if requested.  It will also attempt to
	find a local browser javascript console and assign the YAHOO.widget.Logger
	to write to it.
	
	Include this script into your page immediately after the inclusion of
	the YUI v2 seed file.
		
	IE Debug:
	
	If there is a cookie named 'jsdebug' and with a value of 1, and the 
	current browser is any version of IE, then an instance of YUI.Console
	will be created and made draggable.  
	
	NOTE: a side effect of this is that they current page's <body> tag will
	have the 'yui-skin-sam' class added to it (not replacing currently 
	classes, if any).
	
	Dependancies:
	
	The IE debug feature depends on YAHOO.util.Cookie, YAHOO.widget.LogReader,
	YAHOO.util.Element, and YAHOO.util.Event.  If those are not included in 
	the page then this feature will be disabled.
	
	
*/

// Variable declarations
// make jslint happy
var 
	YAHOO,
	
	YAHOO_isInited,
	
	// if we're on IE then we'll need to create a LogReader, this is it
	ieLogReader
	;

if ( typeof YAHOO !== 'undefined' && YAHOO && ! YAHOO_isInited )
{

	// If we can log to a standard browser console, do it.
	if ( typeof console !== 'undefined'
		&& typeof YAHOO.widget.Logger !== 'undefined' 
		)
	{
		YAHOO.widget.Logger.enableBrowserConsole();

		YAHOO.log( "Initializing", "info", "yahoo-init" );
	}
	// If the browser is IE and there's a jsdebug cookie, then fire up a new
	// LogReader widget.
	else if (
		YAHOO.env.ua.ie
		&& typeof YAHOO.util.Cookie !== 'undefined'
		&& YAHOO.util.Cookie.get( 'jsdebug' ) == 1
		&& typeof YAHOO.widget.LogReader !== 'undefined'
		&& typeof YAHOO.util.Element !== 'undefined' 
		)
	{
		
		YAHOO.util.Event.addListener(window, "load", function() 
			{
					// Create a new LogReader widget for IE logging
					ieLogReader = new YAHOO.widget.LogReader
							( null,  { width: "300px", height: "30em" } );
				

				YAHOO.log( "Initializing", "info", "yahoo-init" );
				YAHOO.log( "IE debug is ON", "info", "yahoo-init" );
				YAHOO.log( "LogReader instantiated for IE", "info", "yahoo-init" );
			} );

		YAHOO.util.Event.onDOMReady( function() 
			{
				var
					// We need to add the 'yui-skin-sam' class to the <body> tag
					body = new YAHOO.util.Element( document.getElementsByTagName( 'body' )[0] ); 
				
				if ( ! body.hasClass( 'yui-skin-sam' ) )
				{
					body.addClass( 'yui-skin-sam' );
					YAHOO.log( "Adding YUI skin to body", "info", "yahoo-init" );
				}
			} );
		
	}
	
	YAHOO_isInited = true;
}
