/*  Copyright 2008  Christian Huellmann  (www.huellmann.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/ 



var dbug = {
	firebug: false, 
	enabled: false,
	logsOutput: null,
	
	log: function( string ) 
	{
		if( dbug.enabled && dbug.firebug ) console.log( string );
		if( dbug.logsOutput != null )
		{
			dbug.logsOutput.innerHTML += '<li>' + string + '</li>';  
		}
	},
	
	enable: function( enable ) 
	{
		if( !enable )
		{
			dbug.log( "Debugging disabled..." );
			// !!! disable alternative console
			dbug.enabled = true;
			return;
		}
		else
		{
			if( typeof console != "undefined" && console.warn )
				dbug.firebug = true;
			else if( typeof console == "undefined" )
				dbug.initAlternativeConsole();
			
			dbug.log( "Debugging enabled..." );
			dbug.enabled = true;
		}
	},
	
	initAlternativeConsole: function()
	{
		// !!! Check if exists and skip or create
		
		var container = new Element( "div", { id:"dbug-console" } );

		container.inject( $( document.body ) );
		
		container.setStyles({
			width: "25%",
			padding: "10px",
			color: "#222222",
			fontSize: "10px",
			lineHeight:"12px",
			border: '1px solid #ffffff',
			backgroundColor: "#dddddd",
			opacity: "0.75",
			zIndex: "9999"
			});
		
		var h1 = new Element( 'p', { html:"dbug-console" } );
		h1.setStyles({fontWeight:"bold"});
		h1.inject( container );
		
		dbug.logsOutput = new Element( 'ul' );  
		dbug.logsOutput.inject( container );
		
		new Drag.Move( container );
	
	}
}