function findPos(obj) { //Finds precise position for an element
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}
//-----------------------------
function showGamercard(elem,xblID){
	var posing = findPos(elem);
	var wide=elem.width;
	var tall=elem.height;
	var gamercard = document.getElementById(xblID);
	var currentPos=0;
	
	if (!gamercard){
		gamercard = document.createElement('div');
		gamercard.setAttribute('id',xblID);
		gamercard.style.zIndex=3;
		elem.parentNode.appendChild(gamercard);
		
		var xblAvatar = document.createElement('img');
		xblAvatar.setAttribute('id',xblID+"avatar");
		xblAvatar.setAttribute('src',"http://avatar.xboxlive.com/avatar/"+xblID+"/avatar-body.png");
		xblAvatar.style.position='absolute';
		xblAvatar.style.zIndex=-1;
		xblAvatar.style.top=-155+'px';
		xblAvatar.style.left=125+'px';
		gamercard.appendChild(xblAvatar);
		
		var gcFrame = document.createElement('iframe');
		gcFrame.setAttribute('id',xblID+"Frame");
		gcFrame.setAttribute('src',"http://gamercard.xbox.com/"+xblID+".card");
		gcFrame.setAttribute('width',204);
		gcFrame.setAttribute('height',140);
		gcFrame.setAttribute('frameBorder',0);
		gcFrame.style.overflow='hidden';
		gamercard.appendChild(gcFrame);
		
	}
	else {
		currentPos = findPos(gamercard);
	}

	if (currentPos[1]==(posing[1]+tall)){
		gamercard.parentNode.removeChild(gamercard);
	}
	else{
		gamercard.style.left=posing[0]+'px';
		gamercard.style.top=posing[1]+tall+'px';
		gamercard.style.position='absolute';
	}
}
//-----------------------------
function showSteam(elem,steamID){
	var posing = findPos(elem);
	var wide=elem.width;
	var tall=elem.height;
	var steamCard = document.getElementById(steamID);
	var currentPos=0;
	
	if (!steamCard){
		steamCard = document.createElement('a');
		steamCard.setAttribute('id',steamID);
		steamCard.setAttribute('class','steamCard');
		steamCard.setAttribute('href','http://steamcommunity.com/id/'+steamID);
		steamCard.setAttribute('target','_blank');
		elem.parentNode.appendChild(steamCard);
		
		var steamCardImg=document.createElement('img');
		steamCardImg.setAttribute('src','http://steamcard.com/do/original/'+steamID+'.png');
		steamCardImg.setAttribute('border',0);
		steamCard.appendChild(steamCardImg);
	}
	else {
		currentPos = findPos(steamCard);
	}

	if (currentPos[1]==(posing[1]+tall)){
		steamCard.parentNode.removeChild(steamCard);
	}
	else{
	steamCard.style.left=posing[0]+'px';
	steamCard.style.top=posing[1]+tall+'px';
	steamCard.style.position='absolute';
	}
}
//------------------------------
function showWii(elem,wiiCode,wiiGames){
	var posing = findPos(elem);
	var wide=elem.width;
	var tall=elem.height;
	var wiiCard = document.getElementById(wiiCode);
	var currentPos=0;
	
	if (!wiiCard){
		wiiCard = document.createElement('ul');
		wiiCard.setAttribute('id',wiiCode);
		wiiCard.setAttribute('class','wiiPop');
		
		elem.parentNode.appendChild(wiiCard);
		
		wiiCard.innerHTML="<li class=wiiCode>"+wiiCode+"</li><hr>";
		wiiGames = wiiGames.replace(/;;/g,"</li><li><span class=game>");
		wiiGames = wiiGames.replace(/::/g, "</span>: ");
		wiiCard.innerHTML=wiiCard.innerHTML+"<li><span class=game>"+wiiGames+"</li>";
	}
	else {
		currentPos = findPos(wiiCard);
	}

	if (currentPos[1]==(posing[1]+tall)){
		wiiCard.parentNode.removeChild(wiiCard);
	}
	else{
	wiiCard.style.left=posing[0]+'px';
	wiiCard.style.top=posing[1]+tall+'px';
	wiiCard.style.position='absolute';
	}
}
//------------------------------
function toggleSpoiler(spoiler) { //hide/show spoiler
	var vis = spoiler.nextSibling; //Get the one we want to toggle
	if (vis.style.visibility=="hidden") vis.style.visibility="visible";
	else vis.style.visibility="hidden";
}


