var profileBubbleTimeoutId;

function setProfileBubbleTimeout() {
	profileBubbleTimeoutId = window.setTimeout("hide('profileBubble')", 7000);
}

function clearProfileBubbleTimeout() {
	window.clearTimeout(profileBubbleTimeoutId);
}

function showProfileBubble(userName, relativeElement) {
	var eProfileBubble = document.getElementById('profileBubble');
	var eRelativeElement = document.getElementById(relativeElement);
	
	if(eProfileBubble) {
		var eProfileBubbleUserName = document.getElementById('profileBubbleUserName');
		var eTextRegister = document.getElementById('profileBubbleTextRegister');
		var eTextAlternative = document.getElementById('profileBubbleTextAlternative');
		
		if(eProfileBubbleUserName) {
			eProfileBubbleUserName.innerHTML = userName;
		}
		
		if(eTextRegister && eTextAlternative) {			
			if(document.location.href.indexOf('main') < 0 || document.location.href.indexOf('main=registration') >= 0 || document.location.href.indexOf('main=homepage') >= 0) {
				eTextRegister.style.display = 'block';
				eTextAlternative.style.display = 'none';
			} else {
				eTextRegister.style.display = 'none';
				eTextAlternative.style.display = 'block';
			}
		}
		
		eProfileBubble.style.display = 'block';
		eProfileBubble.style.left = absLeft(eRelativeElement) + 'px';
		eProfileBubble.style.top = absTop(eRelativeElement) + 'px';
		
		clearProfileBubbleTimeout();
		setProfileBubbleTimeout();
	}
}

function hide(id) {
	var element = document.getElementById(id);
	if(element) {
		element.style.display = "none";
	}
}

function absLeft(el) {
	return (el.offsetParent) ? el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
}

function absTop(el) {
	return (el.offsetParent) ? el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
}