/**
* @author cpogorelov
* Semi-transparent console window
*/
window.RFR.Console=function(){
	this.text='';
	this.version='1.0';
	this.shown=0;
	this.strings=[];
	this.maxStrings=50;
	
	this.create = function(){
		if (!$('consolearea')){
			var consolearea= document.createElement('div');
			consolearea.id='consolearea';
			consolearea.style.position='absolute';
			consolearea.style.display='none';	
			//this.area=document.body.appendChild(consolearea);
			this.area=consolearea;
		} else {
			this.area=$('consolearea');			
		}
		this.area.style.position='absolute';
		this.area.style.top=0;
		this.area.style.left=20;
		this.area.style.width=800;// $('workareatd').offsetWidth-40;
		this.area.style.height=600;//$('workareatd').offsetHeight-40;
		this.area.innerHTML='<span class="consoleok">RFRConsole v.'+this.version+'</span>';
		this.area.style.zIndex=100;
		window.r.keyCatchers[window.r.keyCatchers.length]=this.keyCatcher;
	}
	this.show = function(){
		this.shown=1;
		var text;
		for (var i=0;i<this.strings.length;i++){
			text=text+this.strings[i];
		}
		this.area.innerHTML=text;
		this.area.style.display='';
		this.scroll();
	}
	this.hide = function(){
		this.area.style.display='none';
		this.shown=0;
	}
	this.toggle = function(){
		(this.shown) ? 	this.hide() : this.show();
	}
	this.add = function (str,type){
		if (!type){
			type='message';
		}
		var text='<BR><span class="console'+type+'">'+str+'</span>';
		if (this.strings.length>this.maxStrings){
			this.strings.shift();
		}
		this.strings.push(text);

		if (this.shown){
			this.show();
		}
	}
	this.scroll = function(){
		this.area.scrollTop = this.area.scrollHeight;
	}
	this.keyCatcher=function(e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
	
		if (keycode==113){
			r.con().toggle();
			return;
		}
		return 1;
	}
}
