AL.user_info=function(){
	YAHOO.lang.augmentObject(this,arguments[0]||{},true);
	ye.onDOMReady(this.init,this,true);
};

AL.user_info.prototype={
	ancor_name:'user_info',
	timer:null,
	mainDiv:null,
	body:null,
	mainInfoDiv:null,
	bodyContent:null,
	avatar:null,
	loginHref:null,
	ontg:null,
	mainHeight:148,
	cache:new Array(),
	curReqIndex:0,
	elements:new Array(),
	privateMessage:null,
	init:function(){
		//Основной позиционирующий сайт
		this.mainDiv=cr('div');
		this.mainDiv.className='user_info_aj';
		document.body.appendChild(this.mainDiv);
		//Основно слой относительного позиционирования. Позиционирует внутрение слои и выводит левый нижний угол
		this.body=cr('div');
		this.body.className='bd';
		this.mainDiv.appendChild(this.body);
		
		//Слой тени
		var divShadow=cr('div');
		divShadow.className='shadow';
		this.body.appendChild(divShadow);
		
		//Слой первой границы
		this.bodyContent=cr('div');
		this.bodyContent.className='content';
		this.body.appendChild(this.bodyContent);
		
		var sendMail=cr('div');
		sendMail.className='send_mail';
		var ico=cr('span');
		ico.className='ico_mailbox';
		sendMail.appendChild(ico);
		this.privateMessage=cr('a');
		this.privateMessage.href='/mail/newmessage/';
		this.privateMessage.innerHTML='Отправить личное сообщение';
		sendMail.appendChild(this.privateMessage);
		
		this.bodyContent.appendChild(sendMail);
		
		
		var divAngle=cr('div');
		divAngle.className='angle';
		this.body.appendChild(divAngle);
		
		//Слой основной информации
		this.mainInfoDiv=cr('div');
		this.mainInfoDiv.className='main_info';
		this.bodyContent.appendChild(this.mainInfoDiv);

		//Создаем блок для аватара
		this.avatar=cr('img');
		this.avatar.className='avatar';
		this.mainInfoDiv.appendChild(this.avatar);
		
		//Создаем ссылку на логине
		this.loginHref=cr('a');
		this.loginHref.className='login';
		this.mainInfoDiv.appendChild(this.loginHref);
		
		//Создаем слой информации "На ТЖ"
		this.ontg=cr('div');
		this.ontg.className='ontg';
		this.mainInfoDiv.appendChild(this.ontg);
		
		
		this.elements=document.getElementsByName(this.ancor_name);
		for(var i=0;i<this.elements.length;i++){
			ye.on(this.elements[i],'mouseover',function(e){
				if (this.timer!=null)this.clearTimer();
				var obj=this;
				this.timer=window.setTimeout(function(){
						obj.showInfo(e);
				},500);
			},this,true);
			ye.on(this.elements[i],'mouseout',function(e){
				if (this.timer!=null){
					this.clearTimer();
				}
				var obj=this;
				this.timer=window.setTimeout(function(e){obj.hideInfo(e);},500);
			},this,true);
		}
		ye.on(this.mainDiv,'mouseover',function(){
			this.clearTimer();
		},this,true);
		ye.on(this.mainDiv,'mouseout',function(){
			this.clearTimer();
			var obj=this;
			this.timer=window.setTimeout(function(e){obj.hideInfo(e);},500);
		},this,true);
	},
	clearTimer:function(){
		window.clearTimeout(this.timer);
		this.timer=null;
	},
	showInfo:function(e){
		this.clearTimer();
		var t=e.target;
		var user=t.id;
		var c=yd.getRegion(t);
		var info=this.searchInCache(user);
		if (info==false){
			this.loadInfo(user,e);
		}else {
			this.avatar.src=info.avatar;
			this.loginHref.href='/users/'+info.login+'/';
			this.loginHref.innerHTML=info.login;
			this.privateMessage.href='/mail/newmessage/'+info.login+'/';
			this.ontg.innerHTML='На ТЖ: '+info.ontg;
			yd.setStyles(this.mainDiv,{display:'block',top:(c.top+2-this.mainHeight+'px'),left:(c.right-5+'px')});
		}
	},
	hideInfo:function(){
		this.clearTimer();
		yd.setStyles(this.mainDiv,{display:'none'});
	},
	searchInCache:function(login){
		for(var i=0;i<this.cache.length;i++){
			if (this.cache[i].login==login){
				return this.cache[i];
			}
		}
		return false;
	},
	addToCache:function(info){
		this.cache[this.cache.length]=info;
	},
	loadInfo:function(login,event){
		this.curReqIndex++;
		yc.asyncRequest('get','/?com=users&sb=getinfo&login='+login+'&ind='+this.curReqIndex,{
			success:function(resp){
				eval(resp.responseText);
				if (r!=undefined && r.login!=undefined){
					this.addToCache(r);
					if (r.ind==this.curReqIndex){
						this.showInfo(event);
					};
				};
			},
			scope:this
		});
	}
};

window.user_info=new AL.user_info();
