var work=false;

function UpdateTmpPlaylist(action, type, object_id, id_link)
{
	if(work)
		return;
	work=true;

  $("#" +id_link).empty();
  $("#" +id_link).append("<img src='/img/line_2.gif'>");
  $.post('/playlist/AddToTmpPlaylist',
  {action: action, type: type, object_id: object_id},
  function(data)
  {
	  work=false;

    if (action == "add")
    {
      $("#"+id_link).empty();
      if (type == "3")
      {
        $("#"+id_link).append("Go&nbsp;To&nbsp;Slideshow");
        $("#"+id_link).attr("href", "/slideshow/");		
      }
      else
      {
        $("#"+id_link).append("Go&nbsp;To&nbsp;Playlist");
        $("#"+id_link).attr("href", "/playlist/playlist/" + type);
      }
    }
  }
  );
}

function showTmpPlaylist(idd, file_type, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/GetTmpPlaylist/' + file_type + '/' + page ,
  {action:'showTmpPlaylist', id: idd, file_type: file_type , page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function showTmpPlaylistTracks(idd, file_type, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/GetTmpPlaylistTracks/',
  {action:'editPlaylist', id: idd, file_type: file_type , page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function showPlaylistTracks(idd, playlist_id, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/GetPlaylistTracks/',
  {action:'editPlaylist', id: idd, playlist_id: playlist_id , page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function ChangeTrackPos(idd, playlist_id, track_pos, file_type, direction, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/ChangeTrackPos/',
  {action:'editPlaylist', id: idd, playlist_id: playlist_id, track_pos: track_pos, file_type: file_type, direction: direction , page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function DeleteFile(idd, playlist_id, track_id, file_type, page, pos)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/delete_file/' + playlist_id + '/' + track_id,
  {action:'editPlaylist', id: idd, playlist_id: playlist_id, track_id: track_id, file_type: file_type, page: page, pos: pos},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function showActivePlaylists(idd, file_type, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/GetActivePlaylists/',
  {action:'showActivePlaylists', id: idd, file_type: file_type, page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function DeletePlaylist(idd, playlist_id, file_type, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/DeletePlaylist/' + playlist_id + '/',
  {action:'DeletePlaylist', id: idd, playlist_id: playlist_id, file_type: file_type, page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function ClearTmpPlaylist(idd, file_type, page)
{
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");

  $.post('/playlist/ClearTmpPlaylist/',
  {action:'DeletePlaylist', id: idd, file_type: file_type, page: page},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function GetPlayer(idd, idd_header, playlist){
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");
  $("#" + idd_header).empty();

  $.post('/playlist/getInfoHeader/',
  {action:'GetInfoHeader', id: idd_header, playlist: playlist},
  function(data)
  {
    if(idd_header != '')
    {
      $("#" + idd_header).empty();
      $("#" + idd_header).append(data);
    }
  }
  );

  $.post('/playlist/GetPlayer/' + playlist,
  {action:'GetPlayer', id: idd, playlist: playlist},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

function GetPlayerForFile(idd, idd_header, file_id, file_type){
  $("#" + idd).empty();
  $("#" + idd).append("<DIV class='cfileview' style='padding-left: 220px;'>loading... please wait...</DIV><div style='float:left; text-align:right; width:550px; padding-top:23px;'></div><div style='width:550px;'><div style='float:left;'><img src='/img/folder_lb.gif' height='11' width='10' border='0' /></div><div style='float:left;font-size:1px;'></div><div style='float:right;'><img src='/img/folder_rb.gif' height='11' width='10' border='0' /></div></div>");
  $("#" + idd_header).empty();

  $.post('/playlist/getInfoHeader/',
  {action: 'GetInfoHeader', id: idd_header, playlist: '-1', file_type: file_type},
  function(data)
  {
    if(idd_header != '')
    {
      $("#" + idd_header).empty();
      $("#" + idd_header).append(data);
    }
  }
  );

  $.post('/playlist/GetPlayerForFile/',
  {action:'GetPlayerForFile', id: idd, file_id: file_id},
  function(data)
  {
    if(idd != '')
    {
      $("#" + idd).empty();
      $("#" + idd).append(data);
    }
  }
  );
}

