// SONGLIST

songs_id	= new Array();
songs_title	= new Array();

function songadd(song_id, song_title)
{
	if(!song_id)
	{
		var songname = escapeHTML(prompt('Please enter a song title', ''));
		
		if(songname)
		{
			song_title = songname;
		}
		else
		{
			song_title = false;
		}
	}
	
	if(song_title.length)
	{
		songs_id[songs_id.length]		= song_id;
		songs_title[songs_title.length]	= song_title;
	
		setlistdisplay();
	}
}


function songmove(id, direction)
{
	var temp_song_id	= songs_id[id-direction];
	var temp_song_title	= songs_title[id-direction];
	
	songs_id.splice(id-direction, 1, songs_id[id]);
	songs_title.splice(id-direction, 1, songs_title[id]);
	
	songs_id[id]	= temp_song_id;
	songs_title[id]	= temp_song_title;
	
	setlistdisplay();
}


function songremove(id)
{
	songs_id.splice(id, 1);
	songs_title.splice(id, 1);
	
	setlistdisplay();
}


function setlistdisplay()
{
	var setlist = document.getElementById('setlist');
	
	if(songs_id.length)
	{
		var temp = '<table cellpadding="0" cellspacing="0" border="0">';
		
		for(i=0; i<songs_id.length; i++)
		{
			var temp_up = i ? '<a title="Move up" href="javascript:void(0);" onclick="songmove(' + i + ', 1)"><img alt="Up" src="/images/arrow-up.gif" /></a>' : '&nbsp;';
			var temp_dn = (i != songs_id.length-1) ? '<a title="Move down" href="javascript:void(0);" onclick="songmove(' + i + ', -1)"><img alt="Down" src="/images/arrow-down.gif" /></a>' : '&nbsp;';
			
			temp += '<tr><td class="r"><input type="hidden" name="songs[]" value="' + songs_id[i] + '" />' + (i+1) + '</td><td class="w100"><input type="hidden" name="songs_title[]" value="' + songs_title[i] + '" />' + songs_title[i] + '</td><td>' + temp_up + '</td><td>' + temp_dn + '</td><td><a title="Remove" href="javascript:void(0);" onclick="songremove(' + i + ')"><img alt="Delete" src="/images/delete.gif" /></a></td></tr>';	
		}
		
		temp += '</table>';
	}
	else
	{
		temp = '<p>Click on the song title to add it to the playlist.</p>';
	}
	 
	setlist.innerHTML = temp;
}