﻿var _31i73_console={
	line:[],
	read:function(){
		if(this.line.length)
			return this.line;
		else{
			var list=document.cookie.split(';')
			for(var i=0;i<list.length;i++){
				var item=list[i];
				while(item.length>0&&item.charAt(0)==' ')item=item.substring(1,item.length);
				if(item.substring(0,8)=='console='){
					var length_max=4;
					this.line=unescape(item.substring(8,item.length)).split('\n');
					if(this.line.length>length_max)
						this.line=this.line.slice(this.line.length-length_max,this.line.length);
					return this.line;
				}
			}
			return line=[];
		}
	},
	add:function(data){
		this.line.push(data);
		this.save();
		return this.line;
	},
	add_unique:function(data){
		this.read();
		if(!this.line.length||this.line[this.line.length-1]!=data)
			this.add(data);
	},
	clear:function(){
		this.line=[];
		this.save();
		return this.line;
	},
	save:function(){
		document.cookie='console='+escape(this.line.join('\n'))+'; domain=31i73.com';
	}
};

var appear_delay=100;
function appear_type(object,parent){if(!object.appear_type){
	var content=object.data;
	function frame(object,parent,content){
		parent.style.visibility='visible';
		if(object.data.length<content.length+1){
			object.data=content.substr(0,object.data.length+2)+'█';
			setTimeout(function(){frame(object,parent,content);},50);
		}else
			object.data=content;
	}
	object.appear_type=setTimeout(function(){frame(object,parent,content);},appear_delay+Math.random()*100);
	appear_delay+=300/(1+appear_delay/500);
	object.data='';
}}
function appear_image(object){
	var content=object.data;
	function frame(object,content){
		object.style.visibility='visible';
		if(object.width<object.width_target){
			object.width+=Math.max((object.width_target-object.width)*0.3,5);
			setTimeout(function(){frame(object,content);},50);
		}else{
			object.width=object.width_target;
		}
	}
	setTimeout(function(){frame(object,content);},appear_delay+Math.random()*100);
	appear_delay+=300/(1+appear_delay/500);
	object.width_target=object.getAttribute('width');
	object.width=1;
}

function appear_all(){
	var list=Array();
	function list_add(nodelist){for(var I=0;I<nodelist.length;I++)list.push(nodelist[I]);}
	list_add(document.getElementsByTagName('img'));
	list_add(document.getElementsByTagName('div'));
	list_add(document.getElementsByTagName('button'));
	
	for(var I=0;I<list.length;I++)if(
		list[I].tagName=='DIV'&&list[I].className&&list[I].className.search(/(^|\s)appear(\s|$)/)!=-1||
		list[I].tagName=='BUTTON'||
		list[I].tagName=='IMG'&&list[I].getAttribute('width')
	){
		var object=list[I];
		function search(object,parent){if(!object.className||object.className.search(/\bdescription\b/)==-1){
			if(object.childNodes)for(var I in object.childNodes){
				child=object.childNodes[I];
				if(child.nodeName=='#text')
					appear_type(child,object);
				else
					search(child,object);
			}
		}}
		if(object.tagName=='IMG')
			appear_image(object);
		else
			search(object,object);
	}
}

function init(){
	var list=document.getElementsByTagName('a');
	for(var I=0;I<list.length;I++)if(!list[I].onclick){
		list[I].onclick=function(){
			var text=this.innerHTML.replace(/(<[^>]+\/>|<[^>]+>[^<]*<\/[^>]+>|<[^>]+>|\n)/g,'');
			if(text.length)_31i73_console.add(text);
			return true;
		}
	}

	appear_all();
}

(function(){
	/* Support for the DOMContentLoaded event is based on work by Dan Webb,
	Matthias Miller, Dean Edwards and John Resig. */

	var timer;

	function fireContentLoadedEvent(){if(!document.loaded){
		document.loaded=true;
		if(timer)clearInterval(timer);
		init();
	}}

	if(document.addEventListener){
		if(navigator.userAgent.indexOf('AppleWebKit/')>-1)
			timer=window.setInterval(function() {
				if (/loaded|complete/.test(document.readyState))
					fireContentLoadedEvent();
			},0);
		else
			document.addEventListener('DOMContentLoaded',fireContentLoadedEvent,false);

	}else{
		document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
		document.getElementById("__onDOMContentLoaded").onreadystatechange=function(){
			if(this.readyState=="complete") {
				this.onreadystatechange=null;
				fireContentLoadedEvent();
			}
		};
	}
	window.onload=fireContentLoadedEvent;
})();

if(!_31i73_console.read().length)
	_31i73_console.add_unique("Connected to "+document.location.href.replace(/^http:\/\/(www\.)?/,'').replace(/\/?$/,''));

document.write(
	'<div style="float:right;background-color:#000;padding:0;border:0 none;margin:0">'+
		'<a href="http://www.31i73.com/" style="display:block;border-width:0" onclick="_31i73_console.add(\'< access 31i73.com\');return true"><img src="/31i73.com.png"></a>'+
		'<div style="width: 150px; overflow: hidden; font-size: 10px; line-height: 10px; padding: 0; margin: 0 0 0 auto; background: #000 none">'+
			_31i73_console.read().join('<br />')+'<br />'+
			/*'$ '+*/
		'</div>'+
	'</div>'
);
