/* used only by the playlists */
playlistCurrentSongId=false;
playlistCurrentPlaylistId=false;
/* add media to playlist -amtp */
amtpFileId=false;
amtpMediaType=false;
function deletePlaylist(url){
 $.ajax({
   type: "GET",
   url: url+'/'+playlistCurrentPlaylistId,
   success: function(msg){
    eval('playlist'+playlistCurrentPlaylistId+'Content=undefined');
     $('#myPlaylistsplaylistsPlayerColumn'+playlistCurrentPlaylistId).remove()
    $("#amtpSelectPlaylist option[value='"+playlistCurrentPlaylistId+"']").remove();
   }
 });

}
function addMediaToPlaylist(url, fileId, mediaType, playlistId, playlistContent){
    var contor=0;
    var found=false;
    if (fileId!=''){
        /**
         * check to see if the file to be added to the playlist isn't already added
         */

        if (typeof playlistContent!='undefined'){
            while(contor<playlistContent.length && found==false){
                if (fileId==playlistContent[contor][0] && mediaType==playlistContent[contor][1]){
                    found=true;
                }
                contor=contor+1;
            }
        }
        if (found==false){
            $.get(url,{'songId': fileId,
                        'mediaType': mediaType,
                        'playlistId': playlistId
            },function(data){
                $('#myPlaylistsplaylistsPlayerColumn'+playlistId).append(data);
            })
        }
    }

}

function deleteMediaFromPlaylist(url){
    jQuery.get(url, {
        'media_id':currentPlayingSong,
        'playlist_id':currentPlaylistId
    }, function(){
        $('#xix'+currentPlayingSong+'p'+currentPlaylistId+'t1').remove();
        var playlistContent=eval('playlist'+currentPlaylistId+'Content')
        var contor=0;
        var found=false;
        if (typeof playlistContent!='undefined'){
            while(contor<playlistContent.length && found==false){
                if (currentPlayingSong==playlistContent[contor][0] && 1==playlistContent[contor][1]){
                    playlistContent.splice(contor,1);
                }
                contor=contor+1;
            }
        }
        eval('playlist'+currentPlaylistId+'Content=playlistContent');
        playStop();
    });

}


function playPlaylist(url, pid) {
    currentPlaylist=eval('playlist'+pid+'Content');
    currentPlaylistId=pid;
    eval('playAudio'+currentPlaylist[0][0]+'()');
}
$(function(){
$('.choosePlalistAddMedia_trigger' ).overlay({
    expose: {
        color: '#595858',
        opacity: 0.95
    },
    closeOnClick: false,
    target: '#choosePlalistAddMedia_panel',
    top: 250,
    api: true,
    onLoad: function(event) {
        amtpFileId=this.getTrigger().attr('mediaId');
        amtpMediaType=this.getTrigger().attr('mediaType');
    }
})
})

$(document).ready(function() {
$('.playlistPlayerColumnTitle').click(function(){$(this).addClass('playlistSelected')});
$('.playlistMedia').click(
    function(){
        $(this).addClass('playlistMediaSelected');
        var parent=$(this).parent();
        if(parent.hasClass('playlistColumn')){
            parent.children('.playlistPlayerColumnTitle').addClass('playlistSelected');
        }
    }
);
$("#playlistSlide").resizable(
    {minWidth:600,maxWidth:600,alsoResize:'.alsoResize',minHeight:72,
        handles: {s: document.getElementById("playlistSouthHandle")}
    }
);

})


