function video_playlist_form()
{
	if ($("#video_playlist_form").is(':hidden'))
	{
		$("#video_playlist_form").slideDown('fast');

		show_playlists();
	}
	else
	{
		$("#video_playlist_form").slideUp('fast');
	}
}

function createPlaylist()
{
	var playlist_name = $("form#pl-frm input#playlist_name").val();
	
	if (playlist_name == '')
	{
		return false;
	}
	else
	{
		var sUrl = baseurl + "/ajax/video_playlist_add.php";
		var postData = "action=create_playlist&playlist_name=" + playlist_name;
		
		$.ajax({
		    type: "GET",
		    url: sUrl,
		    data: postData,
		    dataType: 'html',
		    success: video_playlist_create_success,
		    error: video_playlist_error
		});
	}
}

function video_playlist_create_success(msg)
{
	$("form#pl-frm input#playlist_name").val('');
	$("#video-tools-result").html(msg).slideDown('fast');
	
	show_playlists();
}

function video_playlist_error()
{
	$("#video-tools-result").html('connection failed').show();
}

function show_playlists()
{
	$("#show_playlists").html('<img src="' + baseurl + '/templates/images/loading.gif" />');

	var sUrl = baseurl + "/ajax/video_playlist_add.php";
	var postData = "action=show_playlist&user_id=" + user_id;
	
	$.ajax({
	    type: "GET",
	    url: sUrl,
	    data: postData,
	    dataType: 'html',
	    success: video_playlist_show_success,
	    error: video_playlist_error
	});
}
function video_playlist_show_success(msg)
{
	$("#show_playlists").html(msg);
}


function addVideoPlaylist()
{
	var playlist_id = $("form#show-pl-frm select#playlist_id").val();
	var sUrl = baseurl + "/ajax/video_playlist_add.php";
	var postData = "action=add_playlist_video&video_id=" + vid + "&playlist_id=" + playlist_id;
	
	if (playlist_id != '')
	{	
		$.ajax({
			type: "GET",
			url: sUrl,
			data: postData,
			dataType: 'html',
			success: video_playlist_add_success,
			error: video_playlist_error
		});
	}
	else
	{
		return false;
	}
}

function video_playlist_add_success(msg)
{
	$("#video-tools-result").html(msg).slideDown('fast');
	video_playlist_form();
}

