var ilosc=0;
var ptr=0;
var tabArray=new Array();

$(document).ready(function() {
$('img.add').click(function() {
 var id   = $(this).attr('id');
 var audio_id=id.substr(1);
 
	var creatorFilled = document.getElementById('creator-filled'); 
	
// chowanie
	var creatorEmpty=document.getElementById('creator-empty');
	creatorEmpty.setAttribute('style', 'display: none;');
	var creatorFilled=document.getElementById('creator-filled');
	creatorFilled.setAttribute('style', 'display: visible');
	
// dodanie do formularza
var input = document.createElement('input');
	input.setAttribute('type', 'hidden');
	input.setAttribute('name', 'input'+ptr);
	input.setAttribute('id', 'input'+ptr);
	input.setAttribute('value', audio_id);
	var form = document.getElementById('form');
	form.appendChild(input);
	
// dodanie na pasek
var new_li=document.createElement("li");
	new_li.setAttribute('id', 'li'+ptr);
	
var img = document.createElement('img');
	img.setAttribute('id', 's'+ptr);
	img.setAttribute('class', 'remove button');
	img.setAttribute('onclick', 'javascript:remove('+ptr+')');
	img.setAttribute('src', 'remove-20.png');
	img.setAttribute('alt', 'Usuń');	
	
	// add the text to the paragraph
var new_span=document.createElement("span");
	text=document.getElementById('s'+id).textContent;
	sometext = document.createTextNode(text);
	new_span.appendChild(sometext);

	new_li.appendChild(new_span);
	
	new_li.appendChild(img);
	new_li.appendChild(new_span);
	
	var playlist = document.getElementById('playlist'); 

	playlist.appendChild(new_li);
	tabArray[ptr]=audio_id;
	ptr+=1;
	ilosc+=1;
 });

 });
 
function remove(id) {
		var c = document.getElementById('input'+id);
		var d = document.getElementById('li'+id);
		tabArray[id]="undefined";
		c.parentNode.removeChild(c);
		d.parentNode.removeChild(d);
		if (ilosc==1)
		{
			var creatorEmpty=document.getElementById('creator-empty');
			creatorEmpty.setAttribute('style', 'display: visible;');
			var creatorFilled=document.getElementById('creator-filled');
			creatorFilled.setAttribute('style', 'display: none');
			ilosc-=1;
		} else
		ilosc-=1;
		
 }
 
 function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }
 
 function play(id) {
  getFlashMovie("player_invisible").sendTextToFlash(id);
}

function playPlaylist() {
	
	if (ilosc>0)
	{	
		var temp = tabArray.join(',');
		getFlashMovie("player_top").sendTextToFlash(temp);
	}
}
