/*
	Source: classbehaviours.console.js
	ClassBehaviours is a javascript framework based on class-name parsing.
	Copyright 2011 by Maurice van Creij and published on http://www.woollymittens.nl/
	This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/

	// CLASSBEHAVIOURS CLASS
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(classBehaviours)=='undefined') classBehaviours = {};

		// COMMON CONSOLE FUNCTIONS
		// create the utilities child object if it doesn't already exist
		if(typeof(classBehaviours.console)=='undefined') classBehaviours.console = {
			id : 'debugConsole0',
			limit : 32,
			debug : function(){
				if(document.body!=null){
					// create the debug console if it doesn't exist yet
					debugConsole = document.getElementById(classBehaviours.console.id);
					if(debugConsole==null){
						// create a new console node
						newConsole = document.createElement('div');
						newConsole.id = classBehaviours.console.id;
						newText = document.createTextNode('-- newest at top --');
						newConsole.appendChild(newText);
						document.body.appendChild(newConsole);
						debugConsole = document.getElementById(classBehaviours.console.id);
					}
					// set the console's properties
					if(debugConsole.style.background=='') 	debugConsole.style.background = '#ffffff url(../images/button_passive.png) no-repeat 0px 0px';
					if(debugConsole.style.color=='') 		debugConsole.style.color = '#000000';
					if(debugConsole.style.border=='') 		debugConsole.style.border = 'solid 1px #000000';
					if(debugConsole.style.bottom=='') 		debugConsole.style.bottom = 'auto';
					if(debugConsole.style.height=='') 		debugConsole.style.height = (navigator.userAgent.indexOf('MSIE 6')>-1) ? '580px' : '98%' ;
					if(debugConsole.style.left=='') 		debugConsole.style.left = 'auto';
					if(debugConsole.style.overflow=='') 	debugConsole.style.overflow = 'auto';
					if(debugConsole.style.padding=='') 		debugConsole.style.padding = '1% 1% 1% 1%';
					if(debugConsole.style.position=='') 	debugConsole.style.position = (navigator.userAgent.indexOf('MSIE 6')>-1) ? 'absolute' : 'fixed' ;
					if(debugConsole.style.right=='') 		debugConsole.style.right = '-1px';
					if(debugConsole.style.top=='') 			debugConsole.style.top = '-1px';
					if(debugConsole.style.width=='') 		debugConsole.style.width = '128px';
					debugConsole.onclick = classBehaviours.console.move;
					if(typeof(classBehaviours.fader)!='undefined') classBehaviours.fader.setFade(debugConsole, 75);
					// send all the incoming arguments to the debug console
					newList = document.createElement('ul');
					for(var a=0; a<arguments.length; a++){
						// create a list item for each argument
						newListItem = document.createElement('li');
						newListText = document.createTextNode(arguments[a]);
						newListItem.appendChild(newListText);
						newList.appendChild(newListItem);
					}
					debugConsole.insertBefore(newList, debugConsole.firstChild);
					// if there are too many enties, remove a few
					allLists = debugConsole.getElementsByTagName('ul');
					if(allLists.length>classBehaviours.console.limit)
						for(var a=allLists.length-1; a>classBehaviours.console.limit; a--)
							removedChild = debugConsole.removeChild(allLists[allLists.length-1]);
				}
			},
			clear : function(){
				// clear the entries
				debugConsole = document.getElementById(classBehaviours.console.id);
				if(debugConsole!=null){
					allLists = debugConsole.getElementsByTagName('ul');
					for(var a=allLists.length-1; a>=0; a--)
						removedChild = debugConsole.removeChild(allLists[allLists.length-1]);
				}
			},
			html : function(string){
				string = '<xmp>' + string + '</xmp>'
				this.debug(string)
			},
			move : function(that){
				var node = (typeof(this.nodeName)=='undefined') ? that : this ;
				// get the console
				debugConsole = document.getElementById(classBehaviours.console.id);
				// toggle through several console positions
				if(debugConsole.style.right == '-1px' && debugConsole.style.width == '128px'){
					debugConsole.style.bottom = 'auto';
					debugConsole.style.height = (navigator.userAgent.indexOf('MSIE 6')>-1) ? '580px' : '98%' ;
					debugConsole.style.left = '-1px';
					debugConsole.style.right = 'auto';
					debugConsole.style.top = '-1px';
					debugConsole.style.width = '128px';
					debugConsole.style.zIndex = '100000';
				}else if(debugConsole.style.left == '-1px' && debugConsole.style.width == '128px'){
					debugConsole.style.bottom = '-1px';
					debugConsole.style.height = '128px';
					debugConsole.style.left = '-1px';
					debugConsole.style.right = 'auto';
					debugConsole.style.top = 'auto';
					debugConsole.style.width = '98%';
					debugConsole.style.zIndex = '100000';
				}else if(debugConsole.style.bottom == '-1px' && debugConsole.style.width == '98%'){
					debugConsole.style.bottom = 'auto';
					debugConsole.style.height = (navigator.userAgent.indexOf('MSIE 6')>-1) ? '580px' : '98%' ;
					debugConsole.style.left = 'auto';
					debugConsole.style.right = '-1px';
					debugConsole.style.top = '-1px';
					debugConsole.style.width = '128px';
					debugConsole.style.zIndex = '100000';
				}
			}
		}

		// short-cut wrapper functions
		debug = classBehaviours.console.debug;
		debugClear = classBehaviours.console.clear;

