function playlist(id){
	
	// setup playlist
	this.obj = document.getElementById(id);
	this.list = document.createElement('ol');
	this.obj.appendChild(this.list);
	
	// make it sortable
	this.makeSortable();
	
}

playlist.prototype.addItem = function(id, title){
	
	if(document.getElementById('play_'+id)){
		this.flash(id);
		return false;
	}
	
	var newItem = document.createElement('li');
	newItem.className = 'pending';
	newItem.id = 'play_'+id;
	
	var container = document.createElement('div');
	container.className = 'container';
	
	var a_remove = document.createElement('a');
	a_remove.href = '#';
	a_remove.className = 'clearlink';
	a_remove.innerHTML = '<img align="absmiddle" height="10" width="10" src="imgs/delete.png">';
	$(a_remove).bind('click', id, this.removeItem);
	container.appendChild(a_remove);
	
	var div_id = document.createElement('div');
	div_id.innerHTML = id;
	div_id.className = 'id';
	container.appendChild(div_id);
	
	var span_title = document.createElement('span');
	span_title.innerHTML = title;
	span_title.className = 'title';
	container.appendChild(span_title);
	
	//TODO - remove this - its only for simple debugging
	//$(container).append(' [<a href="#" onclick="player1.cueVideo(\''+id+'\')">1</a>]');
	//$(container).append(' [<a href="#" onclick="player2.cueVideo(\''+id+'\')">2</a>]');
	
	newItem.appendChild(container);
	$(newItem).hide();
	this.list.appendChild(newItem);
	this.makeSortable();
	
	// animate the show of the new item, and make sure we scroll in to view it
	$(newItem).show("slide",{direction:"up"},"normal");
	$('.rightcolbody').scrollTo('li:last', 500, {} );
	
	if(dj_controller) dj_controller.loadPlayers();
	
};

playlist.prototype.removeItem = function(e){
	$('#play_'+e.data, this.obj).hide("blind",{direction:"vertical"},"normal", function(){
		$('#play_'+e.data, this.obj).remove();
	});
	
};

playlist.prototype.makeSortable = function(){
	//alert(this.list.id);
	$('ol', this.obj).sortable("destroy");
	$('ol', this.obj).sortable({items:'li.pending', axis:'y', handle:'span.title', containment:'parent', revert:'true', opacity:80});
};
playlist.prototype.itemPlaying = function(id){
	$('li#play_'+id, this.obj).removeClass();
	$('li#play_'+id, this.obj).addClass('playing');
}
playlist.prototype.itemBuffering = function(id){
	$('li#play_'+id, this.obj).removeClass();
	$('li#play_'+id, this.obj).addClass('buffering');
}
playlist.prototype.itemCued = function(id){
	$('li#play_'+id, this.obj).removeClass();
	$('li#play_'+id, this.obj).addClass('cued');
}
playlist.prototype.itemPending = function(id){
	$('li#play_'+id, this.obj).removeClass();
	$('li#play_'+id, this.obj).addClass('pending');
}
playlist.prototype.itemPlayed = function(id){
	var item = $('li#play_'+id, this.obj);
	$(item).removeClass();
	$(item).addClass('played');
	$(item).attr('id', 'played_'+id);
	$(item).clone().insertBefore("li.played:first", this.list);
	$(item).remove();
	
}
playlist.prototype.flash = function(id){
	//highlight an element in the playlist
	$('.rightcolbody').scrollTo("#play_"+id, 100, {} );
	$("#play_"+id).effect("highlight", {color:'red'}, 1000);
}
playlist.prototype.getNextItem = function(){
	//returns the video ID of the next item to cue in the players
	var nextItem;
	if(nextItem = $('li.pending:first', this.list)){
		return $(".id", nextItem).html();
	}
	else return false;
	
}
