try{
//FF Prototype for IE's contains() method//
HTMLElement.prototype.contains = function(node) {
	if (node == null)
		return false;
	if (node == this)
		return true;
	else
		return this.contains(node.parentNode);
}
}catch(E){ /*IE*/ }
//

function createMetaBox( num, type ){

	if( !document.getElementById("metaBox") ){
		//metaBox parent
		var box = document.createElement('div');
			box.setAttribute("id", "metaBox");
		//Check Boundaries
		var pos = getPosition(type+num);
			box.style.cssText = "border: 1px solid #808080; background-color: #333; position: absolute; z-index: 1; left: "+pos.left+"; top: "+pos.top+";";

		//padding
		var pad = document.createElement('div');
			pad.style.cssText = "padding: 8px;";
		//inner table
		var table = document.createElement('table');
			table.border = 0;
			table.cellPadding = 0;
			table.cellSpacing = 0;
			table.setAttribute("width", "200px");
		//tbody
		var tbody = document.createElement('tbody');
			var row = document.createElement('tr');
			//
			//Column 1
			var col1 = document.createElement('td');
				col1.rowSpan = 2;
				col1.style.cssText =  "width: 65px;";
				//Contents: image
				var img_p = document.createElement('div');
					img_p.style.cssText =  "border: 1px solid #000; width: 55px;";
				var img_a = document.createElement('a');
					img_a.href = "#";
				switch(type){ //Image Hyperlinks
					case "FA": img_a.onclick = function(){ parent.gotoArtist(FA[num].aid); return false; }; break;
					case "PA": img_a.onclick = function(){ parent.gotoArtist(PA[num].artistId); return false; }; break;
					case "RA": img_a.onclick = function(){ parent.gotoArtist(RA[num].artistId); return false; }; break;
					//
					case "FP": img_a.onclick = function(){ parent.gotoPlaylistPage(FP[num].playlistId); return false; }; break;
					case "PP": img_a.onclick = function(){ parent.gotoPlaylistPage(PP[num].playlistId); return false; }; break;
					case "RP": img_a.onclick = function(){ parent.gotoPlaylistPage(RP[num].playlistId); return false; }; break;
					//
					case "FM": img_a.onclick = function(){ parent.gotoOtherUsers(FM[num].userId); return false; }; break;
					case "KS": img_a.onclick = function(){ parent.gotoOtherUsers(KS[num].userId); return false; }; break;

				}
				var img = document.createElement('img');
				//
				switch(type){ //Cover Art, tooltips
					case "FA": img.src = FA[num].cover; /*img.alt = FA[num].aName; img.title = FA[num].aName;*/ break;
					case "PA": img.src = PA[num].iconPath; /*img.alt = PA[num].artistName; img.title = PA[num].artistName;*/ break;
					case "RA": img.src = RA[num].filename; /*img.alt = RA[num].artistName; img.title = RA[num].artistName;*/ break;
					//
					case "FP": img.src = FP[num].iconPath; /*img.title = FP[num].userName + " - " + FP[num].playlistName; img.alt = FP[num].userName + " - " + FP[num].playlistName;*/ break;
					case "PP": img.src = PP[num].iconPath; /*img.title = PP[num].userName + " - " + PP[num].name; img.alt = PP[num].userName + " - " + PP[num].name;*/ break;
					case "RP": img.src = RP[num].imagePath; /*img.title = RP[num].creatorUserName + " - " + RP[num].name; img.alt = RP[num].creatorUserName + " - " + RP[num].name;*/ break;
					//
					case "FM": img.src = FM[num].iconPath; /*img.title = FM[num].userName; img.alt = FM[num].userName;*/ break;
					case "KS": img.src = KS[num].imagePath; /*img.title = KS[num].userName; img.alt = KS[num].userName;*/ break;
				}
				//onError
				if( type == "FA" || type == "PA" || type == "RA")
					img.onerror = function (evt) { this.src = 'http://cdn.finetune.com/images/no_album_55.png'; }
				if( type == "FP" || type == "PP" || type == "RP")
					img.onerror = function (evt) { this.src = 'http://cdn.finetune.com/images/no_playlist_55.png'; }
				if( type == "FM" || type == "KS")
					img.onerror = function (evt) { this.src = 'http://cdn.finetune.com/images/no_user_55.png'; }
				//
					img.setAttribute("class", "albHpRollover");
					img.className = "albHpRollover";
					img.style.cssText =  "width: 55px; height: 55px;";
				
				//Append
				img_a.appendChild(img);
				img_p.appendChild(img_a);
				col1.appendChild(img_p);
			//
			//Column 2
			var col2 = document.createElement('td');
				col2.style.cssText =  "vertical-align: top;";
				//Contents: title
				var title = document.createElement('div');
					col2.appendChild(title);
					title.style.cssText =  "padding-bottom: 5px;";
				//
				switch(type){ //Text / Hyperlinks
					case "FA": title.innerHTML = "<a class=\"mintLink\" href=\"#\" onClick=\"parent.gotoArtist("+FA[num].aid+"); return false;\" >"+trunc(FA[num].aName, 30)+"</a>"; break;
					case "PA": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoArtist("+PA[num].artistId+"); return false;\" >"+trunc(PA[num].artistName, 30)+"</a>"; break;
					case "RA": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoArtist("+RA[num].artistId+"); return false;\" >"+trunc(RA[num].artistName, 30)+"</a><br><a class=\"greyText\" href=\"#\" onClick=\"parent.gotoAlbum("+RA[num].albumId+");\" >"+trunc(RA[num].albumname, 30)+"</a>"; break;
								
					//
					case "FP": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoOtherUsers('"+FP[num].userId+"'); return false;\" >"+trunc(FP[num].userName, 18)+"</a><br><a style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoPlaylistPage("+FP[num].playlistId+");\" >"+trunc(FP[num].playlistName, 18)+"</a><div style=\"padding: 5px 3px 5px 0px; font-size: 10pt;\"><a href=\"#\" onClick=\"parent.gotoArtist("+FP[num].artists[0].artistId+");\" >"+FP[num].artists[0].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+FP[num].artists[1].artistId+");\" >"+FP[num].artists[1].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+FP[num].artists[2].artistId+");\" >"+FP[num].artists[2].artistName+"</a>...</div>"; break;
					case "PP": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoOtherUsers('"+PP[num].userId+"'); return false;\" >"+trunc(PP[num].userName, 18)+"</a><br><a style=\"font-size: 95%;\" href=\"#\" onclick=\"parent.gotoPlaylistPage("+PP[num].playlistId+");\" >"+trunc(PP[num].name, 18)+"</a><div style=\"padding: 5px 3px 5px 0px; font-size: 10pt;\"><a href=\"#\" onClick=\"parent.gotoArtist("+PP[num].artists[0].artistId+");\" >"+PP[num].artists[0].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+PP[num].artists[1].artistId+");\" >"+PP[num].artists[1].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+PP[num].artists[2].artistId+");\" >"+PP[num].artists[2].artistName+"</a>...</div>"; break;
					case "RP": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoOtherUsers('"+RP[num].creatorId+"'); return false;\" >"+trunc(RP[num].creatorUserName, 18)+"</a><br><a style=\"font-size: 95%;\" href=\"#\" onclick=\"parent.gotoPlaylistPage("+RP[num].playlistId+");\" >"+trunc(RP[num].name, 18)+"</a><div style=\"padding: 5px 3px 5px 0px; font-size: 10pt;\"><a href=\"#\" onClick=\"parent.gotoArtist("+RP[num].artists[0].artistId+");\" >"+RP[num].artists[0].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+RP[num].artists[1].artistId+");\" >"+RP[num].artists[1].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+RP[num].artists[2].artistId+");\" >"+RP[num].artists[2].artistName+"</a>...</div>"; break;
					//
					case "FM": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoOtherUsers('"+FM[num].userId+"'); return false;\" >"+trunc(FM[num].userName, 18)+"</a><br><span class=\"greyText\" style=\"font-size: 10pt;\">fingerprint</span><div style=\"padding: 5px 3px 5px 0px; font-size: 10pt;\"><a href=\"#\" onClick=\"parent.gotoArtist("+FM[num].artists[0].artistId+");\" >"+FM[num].artists[0].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+FM[num].artists[1].artistId+");\" >"+FM[num].artists[1].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+FM[num].artists[2].artistId+");\" >"+FM[num].artists[2].artistName+"</a>...</div>"; break;
					case "KS": title.innerHTML = "<a class=\"mintLink\" style=\"font-size: 95%;\" href=\"#\" onClick=\"parent.gotoOtherUsers('"+KS[num].userId+"'); return false;\" >"+trunc(KS[num].userName, 18)+"</a><br><span class=\"greyText\" style=\"font-size: 10pt;\">fingerprint</span><div style=\"padding: 5px 3px 5px 0px; font-size: 10pt;\"><a href=\"#\" onClick=\"parent.gotoArtist("+KS[num].artists[0].artistId+");\" >"+KS[num].artists[0].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+KS[num].artists[1].artistId+");\" >"+KS[num].artists[1].artistName+"</a>, <a href=\"#\" onClick=\"parent.gotoArtist("+KS[num].artists[2].artistId+");\" >"+KS[num].artists[2].artistName+"</a>...</div>"; break;
				}
				//
			var row2 = document.createElement('tr');
			
			//
			//Column 3
			var col3 = document.createElement('td');
				col3.style.cssText =  "vertical-align: bottom;";
			if(type != "FM" && type != "KS" && type != "RA"){ //No play button for these types
				//Contents: Play Button
				var play_l = document.createElement('a');
					play_l.href = "#";
				//
				switch(type){ //onClicks for Play buttons
					case "FA": play_l.onclick = function(){ parent.flashplayer.loadPlaylist('a'+FA[num].aid, parent.user.guid, ''); return false; }; break;
					case "PA": play_l.onclick = function(){ parent.flashplayer.loadPlaylist('a'+PA[num].artistId, parent.user.guid, ''); return false; }; break;
					//
					case "FP": play_l.onclick = function(){ parent.flashplayer.loadPlaylist('p'+FP[num].playlistId, parent.user.guid, ''); return false; }; break;				
					case "PP": play_l.onclick = function(){ parent.flashplayer.loadPlaylist('p'+PP[num].playlistId, parent.user.guid, ''); return false; }; break;
					case "RP": play_l.onclick = function(){ parent.flashplayer.loadPlaylist('p'+RP[num].playlistId, parent.user.guid, ''); return false; }; break;
				}
				//	
				
				var play   = document.createElement('img');
					play.src = "http://cdn.finetune.com/images/buttons/play_mini_base.gif";
					play.onmouseover = function(){ this.src = "http://cdn.finetune.com/images/buttons/play_mini_over.gif"; }
					play.onmouseout = function(){ this.src = "http://cdn.finetune.com/images/buttons/play_mini_base.gif"; }
				
				switch(type){//Tooltips for playbuttons
					case "FA": play.alt = FA[num].aName + " radio"; play.title = FA[num].aName + " radio"; break;
					case "PA": play.alt = PA[num].artistName + " radio"; play.title = PA[num].artistName + " radio"; break;
					
					case "FP": play.alt = FP[num].playlistName; play.title = FP[num].playlistName; break;
					case "PP": play.alt = PP[num].userName + " - " + PP[num].name; play.title = PP[num].userName + " - " + PP[num].name; break;
					case "RP": play.alt = RP[num].creatorUserName + " - " + RP[num].name; play.title = RP[num].creatorUserName + " - " + RP[num].name; break;
				}
				//
				//Append
				play_l.appendChild(play);
				col3.appendChild(play_l);
			}else{
				col3.innerHTML = "";
			}
		//						
		//End of tbody
		//Append the table
		if( pos.hand == "left" ){
			row.appendChild(col1);
			row.appendChild(col2);
			row2.appendChild(col3);
			tbody.appendChild(row);
			tbody.appendChild(row2);
		}else{
			row.appendChild(col2);
			row.appendChild(col1);
			row2.appendChild(col3);
			tbody.appendChild(row);
			tbody.appendChild(row2);
		}
		table.appendChild(tbody);
		//
		//Append the rest
		pad.appendChild(table);
		box.appendChild(pad);
		
		return box;
	}
}

var t;	//Timer 
	
//Toggles the MetaBox ON/OFF//
function triggerMetaBox( num, state, type ){	
	if(state == "on"){
		t = setTimeout('showMetaBox('+num+', \''+type+'\');', 600);
	}else
		clearTimeout(t);
}

//Show it
function showMetaBox( num, type ){
var box = createMetaBox(num, type);
	if( typeof box != "undefined" ){
		document.getElementById(type+num).appendChild(box);
		
	}
}

//Hide it
function hideMetaBox( obj, event ){
	var box = document.getElementById("metaBox");			
	if (!obj.contains(event.relatedTarget || event.toElement)) {
		if(box)
			box.parentNode.removeChild(box);
	}
}

//Get X/Y position of the METAS//
function getPosition( spot ){

	var page = pageSize();
	var str  = "";
	var left, top, hand;
	//Left
	if(( findPosX( spot ) + 250 ) >= page.width  ){
		left = (findPosX( spot ) - 145);
		hand = "right";
	}else{
		left = (findPosX( spot ) - 10);
		hand = "left";
	}
	
	top = findPosY( spot ) - 10;
	var obj = { "left" : left+"px", "top" : top+"px", "hand" : hand };  
	return obj;
}