var myMusic = new function(){
   var songs = [];
   var playingIndex = -1;
   var playingSong = null;
   
   function playIndex(i){
      var song = songs[i];
      
      playingIndex = i;
      playingSong = song;
      mySound.playAudio(song.URL);
      document.fire('song:playing', { 'song':song });
   }
   
   this.setSongs = function(songArray){
      songs = songArray
   }
   this.play = function(id){
      for(var i = 0, len = songs.length; i < len; i++){
         var song = songs[i];
         
         if (song.ID == id){
            playIndex(i);
            break;
         }
      }
   }
   this.playPause = function(){
      if (playingIndex < 0){
         playIndex(0);
      }else{
         mySound.playPause();
      }
   }
   this.prev = function(){
      if (playingIndex > 0){
         playIndex(playingIndex - 1);
      }else{
         playIndex(songs.length - 1);
      }
   }
   this.next = function(){
      if (playingIndex < songs.length - 1){
         playIndex(playingIndex + 1);
      }else{
         playIndex(0);
      }
   }
   this.getPlayingSong = function(){
      return playingSong;
   }
}
