// Set default positions on screen

PositionX = 100;
PositionY = 100;
defaultWidth  = 301;
defaultHeight = 91;
playerTitle = 'Close 2 Death Player';

// Set are you sure windows for important links
function setWarningWindows() {
	var links;
	links = getElementsByClass('warning','td');
	for (i=0; i < links.length; i++) {
		links[i].onclick=function() {
			return confirmation();
		}
	}
}

// Set player popups for player links
function setPlayerPopups() {
	var links, linkTarget, itemName;
	links = getElementsByClass('player','a');
	for (i=0; i < links.length; i++) {
		if (links[i].firstChild.nodeName == "SPAN" || links[i].firstChild.nodeName == "IMG") {
			itemName = links[i].firstChild.className;
			itemNumber = links[i].title;
			links[i].onclick=getSongData(itemName, itemNumber);
		}
	}
	
}

// Return a properly formatted js function
function getSongData(songName, songNumber) {
	return function() { popPlayer(songName, songNumber); return false; }
}

// Return a popup of the song player
function popPlayer(songName,songNumber){
	var playerWin = window.open('','player','scrollbars=1,resizable=0,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !playerWin ) { return true; } //popup blockers should not cause errors
	playerWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>'+playerTitle+'<\/title>'+
		'<\/head><body style="background: #000;">'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;">'))+
		'<object width="300" height="90" type="application/x-shockwave-flash" data="/flash/player.swf?setID='+songNumber+'&amp;songname='+songName+'">'+
		'<param name="movie" value="/flash/player.swf?setID='+songNumber+'&amp;songname='+songName+'" />'+
		'<param name="quality" value="high" />'+
		'<param name="bgcolor" value="#000000" />'+
		'<param name="wmode" value="transparent" />'+
		'</object>'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	playerWin.document.close();
	if( playerWin.focus ) { playerWin.focus(); }
	return false;
}

// Return a properly formatted js function for the confirmation
function confirmation() {
	if (!confirm("Are you sure?")) return false;
}

// Start up functions
if(document.getElementById && document.createTextNode) {
	window.onload = function() {
		setPlayerPopups();
		setWarningWindows();
	}
}