
function BxPrOnline ()
{
    this._delay = 3000;    
    this._ts = 0;
    this._id = 0;
    this._per_page = 0;
}

BxPrOnline.prototype.setTs = function (ts)
{
    this._ts = ts;
}

BxPrOnline.prototype.setId = function (id)
{
    this._id = id;
}

BxPrOnline.prototype.setPerPage = function (i)
{
    this._per_page = i;
}

BxPrOnline.prototype.check = function ()
{
    var $this = this;

	var h = function (r)
	{					
        if (r.length < 70)
        {
        	setTimeout('gBxPrOnline.check()', $this._delay);
			return;
        }
        
        var e_cont = $('online_cont');

        var bDublicate = false;
        
        // count number of search results
        var count = 0;
		var e_tmp = e_cont.firstChild;
		while (e_tmp)
		{
			if ('search_res' == e_tmp.className)
				++count;
				
		    e_tmp = e_tmp.nextSibling;			
		}
		        
        // determine last
        if (count >= $this._per_page)
        {
			var e_last = e_cont.lastChild;
			while (e_last && e_last.className != 'search_res')
			{
		    	e_last = e_last.previousSibling;
				if (!e_last) break;
			}
        }		
		
        // add new         
		e_cont.innerHTML = r + e_cont.innerHTML;
		
		// determine id and time of NEW profile
		var e_first = e_cont.firstChild;
		while (e_first && e_first.className != 'search_res')
		{
		    e_first = e_first.nextSibling;
			if (!e_first) break;
		}
		
        if (e_first)		
        {
        	var sId = e_first.id;
        	var m = sId.match(/sr_(\d+)_(\d+)/);
        	if (m != null)
        	{
        		var iId = m[1];
        		var iTs = m[2];
        		              		
        		$this.setId(iId);
        		$this.setTs(iTs);
        	}   
        	
	        // animate         	
    	    $(e_first.id).style.height = '0px';
        	if (e_last)	$(e_last.id).style.height = '85px';
        	
        	$this.showProfile (e_first.id, e_last ? e_last.id : '', 85);
        }
        else
        {
        	setTimeout('gBxPrOnline.check()', $this._delay);
        }
	}

    

    new BxXslTransform (aBxConfig['urlRoot'] + "profilesearch/xml_online_latest/?ts=" + this._ts + "&id=" + this._id, aBxConfig['urlSystemXsl'] + 'profile_row.xsl', h);

    
}

BxPrOnline.prototype.showProfile = function (id, id2, h)
{
	var st = 7;
	var d = 100;
	
	var e = $(id);
	var e2 = $(id2);
	var hh = parseInt(e.style.height);
	if (e2) var hh2 = parseInt(e2.style.height);	
	
	hh += st;
	if (e2) hh2 -= st;
	if (hh < h)
	{		
		e.style.height = hh + 'px'			
		if (e2) e2.style.height = hh2 + 'px'
		setTimeout ("gBxPrOnline.showProfile('"+id+"','"+id2+"',"+h+")", d);
	}
	else
	{
		hh = h;		
		e.style.height = hh + 'px'
		
		if (e2) $('online_cont').removeChild (e2);
		setTimeout('gBxPrOnline.check()', this._delay);
	}
	
}

gScriptLoader.scriptLoaded();
