
var cardConfig = {
	cardLifeTime:32000, // время жизни карточки
	cardChangePhoto:7000, // промежуток времени  через который меняются фотографии внутри карточки
	cardTimeShowHide:500, // время за каторое карточка будет создана/удалена
	cardStepShowHide:25, // частота изменений отображения карточки при создании/удалении
	cardWidth:352,  // ширена карточки
	cardHeight:233, // высота карточки
	cardLeftBlock:120, // ширена области фотографии для карточки
	timeBetweenCard:10000, // промежуток времени до появления следующей карточки
	timeBetweenBlockCards:35000, // время через которое будет создана след. карт. , если общее кол-во карточек достигло максимума
	totalCard:3, // мах кол-во карточек на экране
	cardUpdateProgres:1000 // частота изменения состояния прогресбар у карточки
};

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6 $$=7(){8(a[0]){8(d a[0]==\'j\')2.4=g.k(a[0]);e 2.4=a[0]};2.V=7(){B(2.4.f.n){2.4.N(2.4.f[0])};5 2};2.O=7(){6 3=a[0]||2.4;8((3.c.q||\'\')==\'C\')5 2;3.P=(3.c.q||\'\');3.c.q=\'C\';5 2};2.D=7(){6 l=(a[0]||W);2.4.c.D=(l/E);2.4.c.X=(l/E);2.4.c.Y=(l/E);2.4.c.Z="10(D="+l+")";5 2};2.Q=7(){6 3=a[0]||2.4;3.c.q=(3.P||\'\');5 2};2.11=7(3){8(3&&2.4){r(6 i R 3){8(i!=\'F\')2.4.c[i]=3[i].G();e{2.4.c.12=3.F.G();2.4.c.13=3.F.G()}}};5 2};2.14=7(3){8(3)r(6 i R 3)2.4[i]=3[i];5 2};2.15=7(){2.4.S==\'C\';6 s=2.4.f.n;r(6 i=0;i<s;i++)8(2.4.f[i].h==1)2.O(2.4.f[i]);5 2};2.16=7(){2.4.S==\'17\';6 s=2.4.f.n;r(6 i=0;i<s;i++)8(2.4.f[i].h==1)2.Q(2.4.f[i]);5 2};2.18=7(){2.4.H.N(2.4);5 2};2.19=7(T){2.4=g.1a(T);5 2};2.t=7(3){8(d 3==\'j\')3=g.k(3);e 8(d 3==\'I\'&&3.h!=1)5 2;2.4.t(3);5 2};2.1b=7(){6 o=a[0];8(d(o)==\'j\'){g.k(o).t(2.4)}e o.t(2.4);5 2};2.1c=7(){6 3=a[0];8(d 3==\'j\')3=g.k(3);e 8(d 3==\'I\'&&3.h!=1)5 2;6 u=3.H;u.1d(2.4,3);5 2};2.1e=7(){6 3=a[0];8(d 3==\'j\')3=g.k(3);e 8(d 3==\'I\'&&3.h!=1)5 2;6 u=3.H;u.1f(2.4,3);5 2};2.1g=7(){6 p=!a.n?1h:1i(a[0]);5 2.4.1j(p)};2.1k=7(){6 x=0;6 y=0;6 3=2.4;8(a[0]){6 m=$(a[0]).4;8(!m||!m.h)5{x:b(3.J),y:b(3.K)};U{x+=b(3.J)+b((3.9&&3.9.v&&!w.z)?3.9.v:0);y+=b(3.K)+b((3.9&&3.9.A&&!w.z)?3.9.A:0);3=3.9}B(3!=m&&3!=m.9)}e{U{x+=b(3.J)+b((3.9&&3.9.v&&!w.z)?3.9.v:0);y+=b(3.K)+b((3.9&&3.9.A&&!w.z)?3.9.A:0);3=3.9}B(3)}5{x:x,y:y}};2.1l=7(){8(2.4)5{L:b((2.4.1m||2.4.1n||b(2.4.c.L))),M:b((2.4.1o||2.4.1p||b(2.4.c.M)))};e 5{L:0,M:0}};5 2};',62,88,'||this|obj|el|return|var|function|if|offsetParent|arguments|parseInt|style|typeof|else|childNodes|document|nodeType||string|getElementById|val|parent|length|||display|for|len|appendChild|par|scrollLeft|browser|||ie|scrollTop|while|none|opacity|100|float|toString|parentNode|object|offsetLeft|offsetTop|width|height|removeChild|hide|_old_display|show|in|_content_display|name|do|empty|50|MozOpacity|KhtmlOpacity|filter|alpha|css|cssFloat|styleFloat|attr|hideCnt|showCnt|block|drop|create|createElement|appendTo|appendBefore|insertBefore|replaceObj|replaceChild|cloneObj|true|Boolean|clone|position|size|clientWidth|offsetWidth|clientHeight|offsetHeight'.split('|'),0,{}));

function px(x){return parseInt(x)+'px';};

var rightblock = function(){
	this.maxPhotos = 3;
	this.url = '';
	this.cards = {};
	this.total = 0;
	this.id = 'online_chats';
	
	this.init = function(){
		var span = $$().create('span');
		if (IE) span.css({position:'absolute', left:'0px', top:'0px'});
		else span.css({position:'fixed', right:'0px', bottom:'0px'});
		span.attr({id:this.id}).appendTo(document.body);
		
		this.resize();
		this.getCard();
	};
	
	this.getCard = function(){
		//var data = {chat:false, id:this.total,title:'User online NOW ', description:'test '+this.total, photo:['/photos/58588_p.jpg', '/photos/58587_p.jpg', '/photos/58586_p.jpg']};
		var _self = this;
		var ids = [];
		for(var i in this.cards) ids.push(this.cards[i].id);
		AjaxRequest.get({'url':'/right_cards.php?ids='+ids.join(','),'onSuccess':function(req){
				txt = req.responseText;
				if (txt!='' && txt!='0'){
					eval('var data = '+txt);
					_self.setCard(data);
				}
				else _self.setCard(false);
			}
		});		
	};
	this.setCard = function(data){
		var _self = this;
		if (!data){
			 setTimeout(function(){_self.getCard();}, cardConfig.timeBetweenCard);
			 return;
		}		
		data.callback = function(id){_self.dropCard(id);};
		data.parent = this;
		this.cards['card'+data.id] = new itemChatsOnline(data);
		this.total++;
		if (this.total<cardConfig.totalCard) setTimeout(function(){_self.getCard();}, cardConfig.timeBetweenCard);
		else setTimeout(function(){_self.getCard();}, cardConfig.timeBetweenBlockCards);
	};
	this.dropCard = function(id){		
		this.total--;
		delete(this.cards['card'+id]);
		this.resize();
	};
	this.resize = function(){
		if (!IE) return;
		var el = $$(this.id).el;
		$$(el).css({
			left:px(document.body.clientWidth+(document.body.scrollLeft||0)-cardConfig.cardWidth),
			top:px(document.body.clientHeight+(document.body.scrollTop||0)-el.clientHeight)
		});
	};
	this.init();
};

var itemChatsOnline = function(config){
	
	this.id = '';
	this.description = '';
	this.title = '';
	this.photo = [];
	this.curphoto = 0;
	this.parent = null;
	this.timeoutChangephoto = cardConfig.cardChangePhoto;//10 sek
	this.liveTime = cardConfig.cardLifeTime;//30 sek
	this.width = cardConfig.cardWidth;
	this.height = 0;
	this.opacity = 0;
	this.maxHeight = cardConfig.cardHeight;
	this.step = cardConfig.cardStepShowHide;
	this.cursteps = 1;
	this.closed = false;
	
	this.create = function(){
		var _self = this;
		var div = $$().create('div')
		.css({overflow:'hidden', width:px(this.width), height:px(this.height)})
		.attr({id:this.parent.id+this.id, className:'card'}).appendTo(this.parent.id).opacity(this.opacity).el;
		
		this.createTitle(div);
		this.createCeneter(div);
		
		
		this.createBottom(div);
		this.postCreate();
	};
	this.createTitle = function(obj){
		var title = $$().create('div')
		.css({paddingLeft:px(5), height:px(20)})
		.attr({className:'card_title'})
		.appendTo(obj).el;
		//tile
		$$().create('span').attr({innerHTML:this.title}).appendTo(title);
	};
	this.createCeneter  = function(obj){
		var table = $$().create('table')
		.attr({border:0, cellPadding:0, cellSpacing:0}).appendTo(obj).el.insertRow(0);
		this.createLeft(table.insertCell(0));
		this.createRight(table.insertCell(1));
	};	
	this.createLeft = function(obj){
		var div = $$().create('div')
		.css({overflow:'hidden', width:px(cardConfig.cardLeftBlock), height:px(172)})
		.attr({align:'center'})
		.appendTo(obj).el;
		var a = $$().create('a').attr({href:'/profile.php?id='+this.id, className:'card_image_link'}).appendTo(div).el;
		$$().create('img').css({border:'0'}).attr({id:this.parent.id+this.id+'_img',src:this.photo[this.curphoto], className:'card_image'}).appendTo(a);		
	};
	this.createProgres = function(obj){
		$$().create('div')
		.attr({innerHTML:this.progresTitle, align:'center'})
		.appendTo(obj);
		var div = $$().create('div')
		.css({width:px(this.width - cardConfig.cardLeftBlock-30)})
		.attr({className:'right_card_progress', align:'left'})
		.appendTo(obj).el;
		$$().create('div').attr({className:'right_card_progress_pr', id:this.parent.id+this.id+'_prg'}).appendTo(div);
		
	};
	this.createRight = function(obj){
		var div = $$().create('div')
		.css({overflow:'hidden', width:px(cardConfig.cardWidth - cardConfig.cardLeftBlock), height:px(172)})
		.attr({align:'center'})
		.appendTo(obj).el;
		$$().create('div')
		.attr({align:'left', innerHTML:this.description, className:'card_description'})
		.css({height:px(85)})
		.appendTo(div);
		this.createProgres(div);		
		var _self = this;
		$$().create('input')
		.css({marginTop:px(5)})
		.attr({type:'button', value:this.yes, onclick:function(){window.location = 'profile.php?id='+_self.id; _self.closed=true;}, className:'card_button'})
		.appendTo(div);
		$$().create('input')
		.css({marginTop:px(5), marginLeft:px(10)})
		.attr({type:'button', value:this.no, onclick:function(){_self.closed=true;}, className:'card_button'})
		.appendTo(div);
	};
	this.createBottom = function(obj){
		$$().create('div')
		.css({paddingLeft:px(5), height:px(36)})
		.attr({className:'card_bottom', innerHTML:this.titleBottom})
		.appendTo(obj);
	};

	this.callback = function(){};
	this.changePhoto = function(){
		if (this.closed) return;
		this.curphoto ++
		if (this.curphoto>=this.photo.length) this.curphoto=0;
		$$(this.parent.id+this.id+'_img').attr({src:this.photo[this.curphoto]});
	};
	this.changeProgres = function(){
		if (this.closed) return;
		var k = this.liveTime/cardConfig.cardLifeTime;
		var w = (this.width - cardConfig.cardLeftBlock-30)*k;
		$$(this.parent.id+this.id+'_prg').css({width:px(w)});
	};
	
	this.close = function(){
		$$(this.parent.id+this.id).drop();
		this.callback(this.id);
	};
	
	this.timeout = function(){
		this.cursteps = 0;
		if (this.closed) {this.preClose(); return;}		
		if (Math.ceil(this.liveTime/this.timeoutChangephoto) == Math.floor(this.liveTime/this.timeoutChangephoto)) this.changePhoto();
		this.changeProgres();
		var _self = this;
		this.liveTime -= cardConfig.cardUpdateProgres;
		setTimeout(function(){_self.timeout();}, cardConfig.cardUpdateProgres);
		if (this.liveTime<=0) this.closed = true;
	};	
	this.postCreate = function(){
		var k = Math.sin((this.cursteps/this.step)*90*(Math.PI/180));
		this.height = this.maxHeight*k;
		this.opacity = 100*k;
		$$(this.parent.id+this.id).css({height:px(this.height)}).opacity(this.opacity);
		this.cursteps++;
		var _self = this;
		this.parent.resize();
		if (this.cursteps<this.step+1) setTimeout(function(){_self.postCreate();}, cardConfig.cardTimeShowHide/this.step);
		else this.timeout();
	};
	this.preClose = function(){
		var k = Math.sin((this.cursteps/this.step)*90*(Math.PI/180));
		this.opacity = Math.round(100-100*k);
		this.height = Math.round(this.maxHeight - this.maxHeight*k);
		if (this.height<0) this.height = 0;
		if (this.opacity<0) this.opacity = 0;
		$$(this.parent.id+this.id).css({height:px(this.height)}).opacity(this.opacity);		
		var _self = this;		
		if (this.cursteps<this.step){this.cursteps++; setTimeout(function(){_self.preClose();}, cardConfig.cardTimeShowHide/this.step); this.parent.resize();}
		else this.close();
	};
	
	for(var i in config) this[i] = config[i];
	this.create();
};
var popup = new rightblock();

if (IE){
	window.onscroll = function(){
		try{popup.resize();}catch(e){}
	};
}





