/**
	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).
	
	Window (Global) Variables:
	
		yuiObj - This is the YUI instance created.  It will have requested the
				 'node' and 'cookie' modules though it is not guaranteed nor
				 likely to have them at the time the containing page first 
				 has access to it - therefore you should still follow the YUI
				 approach of 'use'ing those modules and putting your app code
				 into the 'use' callback.
	
	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();
	}

	// If the browser is IE and there's a jsdebug cookie, then fire up a new
	// LogReader widget.
	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.onDOMReady( function()
			{
				var
					// Create a new LogReader widget for IE logging
					ieLogReader = new YAHOO.widget.LogReader
							( null,  { width: "300px", height: "30em" } ),
					
					// 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( "IE debug is ON" );
			} );

		
	}
	
	YAHOO_isInited = true;
}
