


/*$(document).ready(function() {
  $('a.quicktime').click(function() {
    $(this).quicktime({
      attrs: { autoplay: true },
      width: 200,
      height: 20
    });
    return false;
  });
    
  $('a.mp3').click(function() {
    $(this).mp3({
      player:   '/media/flash/mp3player.swf',
      width: 200,
      height: 20,
      autoplay: true
    });
    return false;
  });
});
*/
/**
 *  Quicktime plugin for converting anchors into Quicktime objects.
 *  @author:  M. Alsup (malsup at gmail dot com)
 *  @version: 1.0
 *  http://www.malsup.com/jquery/media/
 *  Free beer and free speech. Enjoy!
 *
 *  This plugin converts anchor tags into Quicktime objects.
 *  Demos can be found at: http://malsup.com/jquery/media/
**/
jQuery.fn.quicktime = function(options) {
    return this.each(function() {
        var $this = jQuery(this);
        var cls = this.className;
        
        var opts = jQuery.extend({
            width:        ((cls.match(/w:(\d+)/)||[])[1]) || 200,
            height:       ((cls.match(/h:(\d+)/)||[])[1]) || 200,
            version:     '6,0,2,0',
            cls:          cls,
            src:          $this.attr('href') || $this.attr('src'),
            caption:      $this.text(),
            attrs:        {},
            elementType:  'div',
            xhtml:        true
        }, options || {});
        
        var endTag = opts.xhtml ? ' />' : '>';
        var allowObjectAtts = 'name,id,accesskey,title,class,tabindex,noexternaldata';
        var skip = 'width,height,src,classid,codebase';
        var skipEmbedAttrs  = skip + ',id,class,title,accesskey,noexternaldata,pluginspage';
        
        var objectAttrs = [], objectParms = [], embedAttrs = [];
        for (var key in opts.attrs) {
            if (allowObjectAtts.indexOf(key) > -1) 
                objectAttrs.push(key +'="' + opts.attrs[key] + '"');
            else if (skip.indexOf(key) == -1) 
                objectParms.push('<param name="'+ key +'" value="' + opts.attrs[key] + '"' + endTag);
            if (skipEmbedAttrs.indexOf(key) == -1) 
                embedAttrs.push(key +'="' + opts.attrs[key] + '"');
        }

        var a = ['<object width="' + opts.width + '" height="' + opts.height + '" '];
        a.push(objectAttrs.join(" "));
        a.push(' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"');
        a.push(' codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=' + opts.version + '">');
        a.push('<param name="src" value="' + opts.src + '"' + endTag);
        a.push(objectParms.join(""));
        a.push('<embed width="' + opts.width + '" height="' + opts.height + '" src="' + opts.src + '" ' );
        a.push(embedAttrs.join(" "));
        a.push(' pluginspage="http://www.apple.com/quicktime/download/"> </embed>');
        a.push('</object>');
        if (opts.caption) a.push('<br' + endTag + opts.caption);
        
        // convert anchor to span/div/whatever...
        var $el = jQuery('<' + opts.elementType + ' class="' + opts.cls + '"></' + opts.elementType + '>');
        $('a.quicktime').show();
        $('div.quicktime').empty().remove();
        $this.after($el).hide();
        $el.html(a.join(''));
    });
};

/**
 *  This is a modified version of: 
 *  jMP3 v0.2.1 - 10.10.2006 (w/Eolas fix & jQuery object replacement)
 *  by Sean O (http://www.sean-o.com/jquery/jmp3)
 *  Copyright (c) 2006 Sean O (http://www.sean-o.com)
 *  Licensed under the MIT License:
 *  http://www.opensource.org/licenses/mit-license.php
 *
 *  This plugin was modified by M. Alsup (malsup at gmail dot com) so that its usage was 
 *  consistent with the flash and Quicktime plugins found at: http://malsup.com/jquery/media/
 *  This plugin converts anchor tags into flash objects that play mp3 files using the
 *  Flash Single MP3 Player.
 *  Demos can be found at: http://malsup.com/jquery/media/
 *  @version: 1.0
 *
 *  NOTE: This plugin uses (and requires) the Flash Single MP3 Player found at: 
 *  http://jeroenwijering.com/?item=Flash_Single_MP3_Player
 *
 *
 *  Advanced Usage:
 *  --------------
 *      $('a.mp3').mp3({
 *          caption:  false,                       // supress caption text
 *          player:   '/media/files/flash_mp3_player/mp3player.swf' // path to mp3 player
 *      });
 *
 *
 *
 *  Options are passed to the 'mp3' function using a single Object.  The options
 *  Object is a hash of key/value pairs.  The following option keys are supported:
 *
 *  Options:
 *  -------
 *  background:  background color of mp3 player* (default: none)
 *  foreground:  foreground color of player buttons* (default: 555555)
 *  width:       width of mp3 player* (default: 450)
 *  height:      height of mp3 player* (default: 370)
 *  volume:      playback volume, 0-100* (default: 50)
 *  repeat:      looping value, yes or no* (default: no)
 *  autoplay:    true of false* (default: false)
 *  cls:         classname(s) to be applied to new element (default: anchor classname)
 *  src:         source location of mp3 file (default: value of href attr)
 *  caption:     text to be used as caption; use false for no caption (default: value of anchor text)
 *  player:      full path to the singlemp3player.swf file (default: current dir)
 *  elementType: type of element to replace anchor (span, div, etc) (default: 'div')
 *  xhtml:       true for xhtml markup, false false for html (default: true)
 *
 *  * background, foreground, height, width, volume, repeat and autoplay values can be embedded 
 *    in the classname using the following syntax:
 *    <a class="mp3 vol:50 autoplay:true bg:fff></a>
 */
jQuery.fn.mp3 = function(options){
    return this.each(function(){
        var $this = jQuery(this);
        var cls = this.className;

        var opts = jQuery.extend({
            background:   ((cls.match(/bg:#?([0-9a-fA-F]+)/)||[])[1]) || '',            // background color
            foreground:   ((cls.match(/fg:#?([0-9a-fA-F]+)/)||[])[1]) ||'555555',       // foreground color (buttons)
            width:        ((cls.match(/w:(\d+)/)||[])[1]) || '25',                      // width of player
            height:       ((cls.match(/h:(\d+)/)||[])[1]) || '20',                      // height of player
            volume:       ((cls.match(/vol:(\d+)/)||[])[1]) || '50',                    // mp3 volume (0-100)
            repeat:       ((cls.match(/repeat:(yes|no)/)||[])[1]) || 'no',              // loop?
            autoplay:     ((cls.match(/autoplay:(true|false)/)||[])[1]) || 'false',     // play immediately on page load?
            showdownload: 'true',                                                       // show download button in player
            cls:          cls,
            src:          $this.attr('href'),
            caption:      $this.text(),
            player:       'singlemp3player.swf',
            elementType:  'div',
            xhtml:        true
        }, options || {});

        var endTag = opts.xhtml ? ' />' : '>';

        var a = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '];
        a.push('width="' + opts.width + '" height="' + opts.height +'" ');
        a.push('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">');
        a.push('<param name="movie" value="' + opts.player + '?');
        a.push('showDownload=' + opts.showdownload + '&file=' + opts.src + '&autoStart=' + opts.autoplay);
        a.push('&backColor=' + opts.background + '&frontColor=' + opts.foreground);
        a.push('&repeatPlay=' + opts.repeat + '&songVolume=' + opts.volume + '"' + endTag);
        a.push('<param name="wmode" value="transparent"'+ endTag);
        a.push('<embed wmode="transparent" width="' + opts.width + '" height="' + opts.height +'" ');
        a.push('src="' + opts.player + '?');
        a.push('showDownload=' + opts.showdownload + '&file=' + opts.src + '&autoStart=' + opts.autoplay);
        a.push('&backColor=' + opts.background + '&frontColor=' + opts.foreground);
        a.push('&repeatPlay=' + opts.repeat + '&songVolume=' + opts.volume + '" ');
        a.push('type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed>');
        a.push('</object>');
        if (opts.caption) a.push('&nbsp;' + opts.caption);

        // convert anchor to span/div/whatever...
        var $el = jQuery('<' + opts.elementType + ' class="' + opts.cls + '"></' + opts.elementType + '>');
        $('div.mp3').empty().remove();
        $('a.mp3').show();
        $this.after($el).hide();
        $el.html(a.join(''));

        // Eolas workaround for IE (Thanks Kurt!)
        if(jQuery.browser.msie){ $el[0].outerHTML = $el[0].outerHTML; }
    });
};