var isClick = false;
var isLoading = false;
var cID;

var cElement, waitInterval;
var jTimeout;

function home_social_loggedon(){
	li = document.getElementById('friends').getElementsByTagName('li');
	for(i = 0; i < li.length; i++){
		p = li[i].getElementsByTagName('img');
		if(p.length > 0)
		{
			p = p[0];
			
			//p.onmouseover = function() { openUser(this); }
			p.onmouseover = function() { if(waitInterval) clearTimeout(waitInterval); cElement = this; waitInterval = setTimeout('openUser(cElement);', 300); }
			p.onmouseout = function() { if(waitInterval) clearTimeout(waitInterval); }
//			p.onmouseout = function() { hideUser(); }
			//p.onclick = function() { openUser(this); }
		}
	}
	document.getElementById('hlo_box').onmouseout = function() { jTimeout = setTimeout('hideUser()', 500); }
	document.getElementById('hlo_box').onmouseover = function() { clearTimeout(jTimeout); }
}

function basename(p, suffix) {
    var b = p.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function openUser(m){
	//if(isClick) return;
	var t = basename(m.src, '.jpg').replace(/t/, '').replace(/\..*$/ ,'');
	
	if(isLoading) return false;
	isLoading = true;
	
	loadUserAjax(t, m.id.replace(/hloi/,'')); 
}

function loadUserAjax(id, me){
	cID = id;
	params = {'id' : id, 'home' : 1};

	document.getElementById('hlo_box').style.display = 'none';
	doAjaxRequest('/social/ajaxUserInfo', params, {onSuccess : function(oReq){
		document.getElementById('hlo_box').innerHTML = oReq.responseText;
		document.getElementById('hlo_box').style.display = '';
		document.getElementById('hlo_box').style.left =  hloBoxLeftPosition(me) + 'px';
		isLoading = false;
	}, onFailure : function(oReq){
		setTimeout(500, 'loadUserAjax(cID)');
		isLoading = false;
	}
	});
	return false;
}

function hideUser(){
	//isClick = false;
	document.getElementById('hlo_box').style.display = 'none';
}
 
function hloBoxLeftPosition(me){
	if(me == 1 || me == 2)
	return 7;
	if(me == 3 || me == 4 || me == 5)
	return 16;
	if(me == 6 || me == 7 || me == 8 || me == 9)
	return 40;
	if(me == 10 || me == 11)
	return 70;
	if(me == 12 || me == 13)
	return 100; 
	if(me == 14 || me == 15 || me == 16 || me == 17)
	return 130; 
	if(me == 18 || me == 19 || me == 20)
	return 165; 
	if(me > 20)
	return 180; 
}