var origOffset = 0; //for overlay postion

// load user up from server
function loadUser(userId) {
	var div = document.getElementById("overlay");

	// it doesn't exist? create it
	if(!div) {
		div = document.createElement("div");
		div.id = "overlay";
		div.className = 'profile view';
		div.onclick=hideOverlay;
		
		//retrieve the content div and append to that
		var myContent = document.getElementById("content");
		//document.body.appendChild(div);
		myContent.appendChild(div);
	}

	ajaxOb.sendRequest("/media/site/helpers/loadusers.php?user=" + userId, null, function() {
		div.innerHTML = this.xmlReqOb.responseText;
		//retrieve the scroll point and update the top of the div to match
		var myScroll = getScrollPoint();
			if(origOffset==0){
				origOffset = div.offsetTop;
			}
		div.style.top = (origOffset+myScroll)+'px';
		
		//get left point based on width of browser window
		var myCentre = parseInt($(window).width()/2);
		var myWidth = parseInt(div.clientWidth);
		div.style.left = myCentre-(myWidth/2)+'px';
		$(div).hide();	
		div.style.display = 'none';
		div.style.visibility = "visible";
		fadePage();
		$(div).fadeIn('slow');
		
		//we need to hide the community jump select (for ie6)
		var commJump = document.getElementById('communityJump');
		if(commJump){commJump.style.visibility = 'hidden';}
		
		//need to hide the forum jump on homepage for IE6
		var forumJump = document.getElementById('forumChangeforum');
		if(forumJump){forumJump.style.visibility = 'hidden';}
	});

	return false;
}

function hideOverlay(){
	var div = document.getElementById("overlay");
	if(div){
		$('#fadeDiv').fadeTo('fast',0.0);
		$('#fadeDiv').hide();
		div.style.visibility="hidden";	
		//we need to show the community jump select (for ie6)
		var commJump = document.getElementById('communityJump');
		if(commJump){commJump.style.visibility = 'visible';}
		//show the forum jump onn community homepage for IE6
		var forumJump = document.getElementById('forumChangeforum');
		if(forumJump){forumJump.style.visibility = 'visible';}
		//might as well clear out the contents of the div
		div.innerHTML = '';
	}
} 

//retrieve the current scroll position of the window
function getScrollPoint(){
	var pos = 0;
	if(document.documentElement && document.documentElement.scrollTop){
		pos = document.documentElement.scrollTop;
	} else if (document.body){
		pos = document.body.scrollTop;
	} else {
		pos = window.pageYOffset;
	}
	return pos;
}

function fadePage(){
	var fadeDiv = createFadeDiv();
	$(fadeDiv).show();
	$(fadeDiv).fadeTo('fast',0.4);
}

function createFadeDiv(){
	var fadeDiv = document.getElementById('fadeDiv');
	if(!fadeDiv){
		fadeDiv = document.createElement('div');
	}
	fadeDiv.id="fadeDiv";
	$(fadeDiv).css('opacity',0.0);
	document.body.appendChild(fadeDiv);
	return fadeDiv;
}