(function($) {
  $.fn.trackList = function(options) {

    // Set the default options
    var defaults = {
      // The directory containing the Audio Files
      audioPath: null
    };

    // Merge the default options with the user's ones  
    var options = $.extend(defaults, options);

    // Add the plug-in
    return this.each(function() {
      // Bind the Click on the Track List
      jQuery(this).find('li > span').bind('click', function() {
        // Remove all the running icon
        jQuery(this).parent().parent().find('span').each(function() {
          jQuery(this).removeClass('indicator');
        });
       
        // Add the running icon
        jQuery(this).addClass('indicator');

        // Get the Selected Track
        track = jQuery('#' + this.id + '_DETAILS');

        // Check if the Track is not already selected
        if (!track.hasClass('visible')) {
          // Hide all the Tracks
          jQuery('div.Track').removeClass('visible').hide();

          // Fade In of the selected Track
          track.addClass('visible').fadeIn('normal');

          var player = new SWFObject("/Flash/playerMini.swf", "mymovie", "75", "20", "7", "#FFFFFF");
          player.addVariable("autoPlay", "yes");
          player.addVariable("soundPath", options.audioPath + "/" + this.id + ".mp3");
          player.write("TrackPlayerContainer");
        }
      });

      // Display the default first Track
      jQuery(this).find('li > span:first').click();
    });
  };
})(jQuery);

