// begin bubble terms functions - call init(numBubbles); onLoad
// If bubble extends beyond top of browser - set top='1' in function call

function setBubble(val,top)
{ 
if (document.getElementById("bubble"+val) && 
	(document.getElementById("bubble"+val).style.display != 'block'))
{
	var obj = document.getElementById("bubble"+val);
	var objc = document.getElementById("bubble_content"+val);

	obj.style.zIndex = '999';
	obj.style.display = "block";
	obj.style.position = "relative";
	obj.style.margin = '0';
	obj.style.padding = '0';

    var h = objc.offsetHeight; 
    var w = objc.offsetWidth;

	var ie6 = false;
	var hoffset = 3;
	var woffset = -190;
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		if (window.XMLHttpRequest)
		{
			hoffset = -3;
			woffset = -610;
		}
		else
		{
			ie6 = true;
			hoffset = -8;
			woffset = -620;
		}
	}
	else 
	{
		if (navigator.userAgent.toLowerCase().indexOf("safari") != -1)
		{
			hoffset = -3;
			woffset = -138;
		}
	}

	obj.style.top = findPosY("playlist" + val) + hoffset + "px";
	obj.style.left = findPosX("playlist" + val) + woffset + "px";

	var tlh = 8;
	var tlw = 8;

	objc.style.top = tlh + 'px';
	objc.style.left = tlw + 'px';
	objc.style.width = '110px';
	objc.style.backgroundColor = '#fff';	
	objc.style.fontFamily = 'arial';
	objc.style.fontSize = '11px';
	objc.style.position = "absolute";

	if (ie6 == false)
	{
	document.getElementById("bubble_tl"+val).style.backgroundImage = 'url(img/bubble/tl.png)';
	document.getElementById("bubble_tl"+val).style.top = '0';
	document.getElementById("bubble_tl"+val).style.left = '0';
	document.getElementById("bubble_tl"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_tl"+val).style.width = '8px';
	document.getElementById("bubble_tl"+val).style.height = '8px';
	document.getElementById("bubble_tl"+val).style.position = 'absolute';

	document.getElementById("bubble_t"+val).style.backgroundImage = 'url(img/bubble/t.png)';
	document.getElementById("bubble_t"+val).style.top = '0';
	document.getElementById("bubble_t"+val).style.height = '8px';
	document.getElementById("bubble_t"+val).style.width = w + 'px';
	document.getElementById("bubble_t"+val).style.left = tlw + 'px';
	document.getElementById("bubble_t"+val).style.position = 'absolute';

	document.getElementById("bubble_tr"+val).style.backgroundImage = 'url(img/bubble/tr.png)';
	document.getElementById("bubble_tr"+val).style.top = '0';
	document.getElementById("bubble_tr"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_tr"+val).style.width = '15px';
	document.getElementById("bubble_tr"+val).style.height = '8px';
	document.getElementById("bubble_tr"+val).style.left = (w + tlw) + 'px';
	document.getElementById("bubble_tr"+val).style.position = 'absolute';

	document.getElementById("bubble_l"+val).style.backgroundImage = 'url(img/bubble/l.png)';
	document.getElementById("bubble_l"+val).style.left = '0';
	document.getElementById("bubble_l"+val).style.width = '8px';
	document.getElementById("bubble_l"+val).style.height = h + 'px';
	document.getElementById("bubble_l"+val).style.top =  tlh + 'px';
	document.getElementById("bubble_l"+val).style.position = 'absolute';

	document.getElementById("bubble_rp"+val).style.backgroundImage = 'url(img/bubble/rp.png)';
	document.getElementById("bubble_rp"+val).style.width = '15px';
	document.getElementById("bubble_rp"+val).style.top = tlh + 'px';
	document.getElementById("bubble_rp"+val).style.left = (tlw + w) + 'px';
	document.getElementById("bubble_rp"+val).style.height = '21px';
	document.getElementById("bubble_rp"+val).style.position = 'absolute';

	document.getElementById("bubble_r"+val).style.backgroundImage = 'url(img/bubble/r.png)';
	document.getElementById("bubble_r"+val).style.width = '15px';
	document.getElementById("bubble_r"+val).style.top = tlh + 21 + 'px';
	document.getElementById("bubble_r"+val).style.left = (tlw + w) + 'px';
	document.getElementById("bubble_r"+val).style.height = h - 21 + 'px';
	document.getElementById("bubble_r"+val).style.position = 'absolute';

	document.getElementById("bubble_bl"+val).style.backgroundImage = 'url(img/bubble/bl.png)';
	document.getElementById("bubble_bl"+val).style.left = '0';
	document.getElementById("bubble_bl"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_bl"+val).style.width = '8px';
	document.getElementById("bubble_bl"+val).style.height = '13px';
	document.getElementById("bubble_bl"+val).style.top = (tlh + h) + 'px';
	document.getElementById("bubble_bl"+val).style.position = 'absolute';

	document.getElementById("bubble_b"+val).style.backgroundImage = 'url(img/bubble/b.png)';
	document.getElementById("bubble_b"+val).style.height = '13px';
	document.getElementById("bubble_b"+val).style.width = w + 'px';
	document.getElementById("bubble_b"+val).style.top = (tlh + h) + 'px';
	document.getElementById("bubble_b"+val).style.left = tlw + 'px';
	document.getElementById("bubble_b"+val).style.position = 'absolute';

	document.getElementById("bubble_br"+val).style.backgroundImage = 'url(img/bubble/br.png)';
	document.getElementById("bubble_br"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_br"+val).style.width = '15px';
	document.getElementById("bubble_br"+val).style.height = '13px'
	document.getElementById("bubble_br"+val).style.left = (tlw + w) + 'px';
	document.getElementById("bubble_br"+val).style.top = (tlh + h) + 'px';
	document.getElementById("bubble_br"+val).style.position = 'absolute';
	}

	val = "";
	}
} 

function initBubbles()
{
	//need to initiate first or it doesn't build proper the first time fired.
    var i = 0;
	while (document.getElementById("bubble"+i)){
		setBubble(i);
		resetBubble(i);
		i++;
	}
}

function resetBubble(bubbleNum)
{
	if(document.getElementById("bubble"+bubbleNum)){
		document.getElementById("bubble"+bubbleNum).style.display = "none";
	}
}

function findPosX(id)
{
	var obj = document.getElementById(id);
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(id)
{
	var obj = document.getElementById(id);
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
