﻿(function($) {
    $.fn.extend({
        playmedia: function(options) {

            //Settings list and the default values   
            var defaults = {
                Height: "380px",
                Width: "640px",
                LoadDiv: "#pres",
                MediaName: "",
                MediaType: "",
                IntroAudio: "",
                PlayerPath: "",
                LoadClick: false
            };

            var options = $.extend(defaults, options);
            var o = options;
            if (o.LoadClick) {
                $(o.LoadDiv).click(function() {
                    SetAudio();
                });
            }
            else {
                SetAudio();
            }

            function SetMedia() {
                $(o.LoadDiv)[0].innerHTML = '';
                switch (o.MediaType) {
                    case ".qt": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"  standby="Loading Media Player components…" type="application/x-oleobject" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="' + o.MediaName + '"><param name="autoplay" value="true"><param name="controller" value="true"><embed src="' + o.MediaName + '" width="' + o.Width + '" height="' + o.Height + '" autoplay="true" controller="talse" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>'; break;
                    case ".mov": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"  standby="Loading Media Player components…" type="application/x-oleobject" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="' + o.MediaName + '"><param name="autoplay" value="true"><param name="controller" value="true"><embed src="' + o.MediaName + '" width="' + o.Width + '" height="' + o.Height + '" autoplay="true" controller="talse" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>'; break;
                    case ".mp3": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '"></embed></object>'.replace('&amp;', '&').replace('&quote;', '"'); break;
                    case ".avi": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '"></embed></object>'; break;
                    case ".mp4": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '"></embed></object>'; break;
                    case ".m4v": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '"></embed></object>'; break;
                    case ".mpg": $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '"></embed></object>'; break;
                    case ".wmv":
                        {
                           // o.MediaName = o.MediaName.replace('showfile', 'wmv');
                            $(o.LoadDiv)[0].innerHTML += '<object id="MediaPlayer" width="' + o.Width + '" height="' + o.Height + '" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"  standby="Loading Windows Media Player components…" type="application/x-oleobject"  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"><param name="Showcontrols" value="True" /> <param name="autoStart" value="true" /><param name="filename" value="' + o.MediaName + '" /><embed type="application/x-mplayer2" src="' + o.MediaName + '" name="MediaPlayer" width="' + o.Width + '0" height="' + o.Height + '"></embed></object>';
                            break;
                        }
                    case ".flv": $(o.LoadDiv)[0].innerHTML += '<object width="' + o.Width + '" height="' + o.Height + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"><param name="salign" value="lt" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="wmode" value="transparent" /><param name="autostart" value="true" /><param name="movie" value="' + o.PlayerPath + 'flvplay.swf" /><param name="flashvars" value="skinName=flvskin&streamName=' + o.MediaName + '&autoPlay=true&autoRewind=true" /><embed width="' + o.Width + '" height="' + o.Height + '" flashvars="streamName=' + o.MediaName + '&autoPlay=true&autoRewind=true&skinName=flvskin" quality="high" scale="noscale" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  src="' + o.PlayerPath + 'flvplay.swf" wmode="transparent" /></object>'; break;
                  //  case ".flv":  $(o.LoadDiv)[0].innerHTML += '<object width="' + o.Width + '" height="' + o.Height + '"><param name="allowFullScreen" value="false" /><param name="allowScriptAccess" value="always"><param name="scale" value="noscale" /><param name="wmode" value="transparent" /><param name="autostart" value="true" /><param name="movie" value="OSplayer.swf?'+ o.MediaName +'&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=&showTitle=no"><embed src="OSplayer.swf?movie=' + o.MediaName +'&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=&showTitle=no"  width="' + o.Width + '" height="' + o.Height + '" allowFullScreen="true" type="application/x-shockwave-flash" allowScriptAccess="always">'; break;
                    case ".swf": $(o.LoadDiv)[0].innerHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + o.Width + '" height="' + o.Height + '"><param name="movie" value="' + o.PlayerPath + 'dsrsmart_3_pl.swf" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#000000" /><param name="quality" value="high" /><param name="menu" value="true" /><param name="play" value="true" /><param name="loop" value="false" /><param name="autostart" value="true" /><param name="scale" value="noscale" /><param name="flashvars" value="videoUrl=' + o.MediaName + '&currentfps=25.00&loopVideo=stopend&playOnLoad=true&autobuffer=true" /><embed src="' + o.PlayerPath + 'dsrsmart_3_pl.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="transparent" bgcolor="#000000" width="' + o.Width + '" height="' + o.Height + '" quality="high" menu="true" play="true" loop="true" scale="noscale" flashvars="videoUrl=' + o.MediaName + '&currentfps=25.00&loopVideo=stopend&playOnLoad=true&autobuffer=true"></embed></object>'; break;
                    default: $(o.LoadDiv)[0].innerHTML += '<br/><br/><a href="' + o.MediaName + '" target="_blank">Click Here to Download the Presentation File</a>'; break;
                }
            };

/*
<object width='400' height='325' id='flvPlayer'>
  <param name='allowFullScreen' value='true'>
   <param name="allowScriptAccess" value="always"> 
  <param name='movie' value='OSplayer.swf?movie=mario.flv&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=Super Mario Brothers Lego Edition&showTitle=yes'>
  <embed src='OSplayer.swf?movie=mario.flv&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=Super Mario Brothers Lego Edition&showTitle=yes' width='400' height='325' allowFullScreen='true' type='application/x-shockwave-flash' allowScriptAccess='always'>
 </object>
*/

            function SetAudio() {
                //   $(o.LoadDiv)[0].innerHTML = '';
                // if (o.IntroAudio != "") {
                // $(o.LoadDiv)[0].innerHTML += '<embed type="application/x-mplayer2" src="' + o.IntroAudio + '" autoStart="true" loop="false" name="MediaPlayer1" width="0px" height="0px"/>';
                // setTimeout(SetMedia, 2500);
                // }
                // else {
                SetMedia();
                // }
            };

            function ClearMedia() {
                $(o.LoadDiv)[0].innerHTML = '';
            };
        }
    });
})(jQuery)
