//---------------
//
// www.kigalczynski.pl -- Oficjalna strona Konstantego Ildefonsa Galczynskiego
//
// Copyright (C) 2007, Mikolaj Galczynski
//
//---------------

// Copyright Š 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// initialize a variable to test for JavaScript 1.1.
// which is necessary for the window.location.replace method
var javascriptVersion1_1 = false;


javascriptVersion1_1 = true;


// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
   // if the browser can do it, use replace to preserve back button
   if(javascriptVersion1_1) {
      window.location.replace(daURL);
   } else {
      window.location = daURL;
   }
   return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
   // check for redirection
   if( redirectURL && ((pluginFound && redirectIfFound) || 
      (!pluginFound && !redirectIfFound)) ) {
      // go away
      goURL(redirectURL);
      return pluginFound;
   } else {
      // stay here and return result of plugin detection
      return pluginFound;
   } 
}

function canDetectPlugins() {
   if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
      return true;
   } else {
      return false;
   }
}

function detectFlash(redirectURL, redirectIfFound) {
   pluginFound = detectPlugin('Shockwave','Flash'); 
   // if not found, try to detect with VisualBasic
   if(!pluginFound && detectableWithVB) {
      pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
   }
   // check for redirection
   return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
   pluginFound = detectPlugin('Shockwave','Director'); 
   // if not found, try to detect with VisualBasic
   if(!pluginFound && detectableWithVB) {
      pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
   }
   // check for redirection
   return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
   pluginFound = detectPlugin('QuickTime');
   // if not found, try to detect with VisualBasic
   if(!pluginFound && detectableWithVB) {
      pluginFound = detectQuickTimeActiveXControl();
   }
   return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
   pluginFound = detectPlugin('RealPlayer');
   // if not found, try to detect with VisualBasic
   if(!pluginFound && detectableWithVB) {
      pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
      detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
      detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
   } 
   return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
   pluginFound = detectPlugin('Windows Media');
   // if not found, try to detect with VisualBasic
   if(!pluginFound && detectableWithVB) {
      pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
   }
   return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
   // allow for multiple checks in a single pass
   var daPlugins = detectPlugin.arguments;
   // consider pluginFound to be false until proven true
   var pluginFound = false;
   // if plugins array is there and not fake
   if (navigator.plugins && navigator.plugins.length > 0) {
      var pluginsArrayLength = navigator.plugins.length;
      // for each plugin...
      for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
      // loop through all desired names and check each against the current plugin name
         var numFound = 0;
         for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
         // if desired plugin name is found in either plugin name or description
            if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
            (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
            // this name was found
            numFound++;
         }   
      }
      // now that we have checked all the required names against this one plugin,
      // if the number we found matches the total number provided then we were successful
      if(numFound == daPlugins.length) {
         pluginFound = true;
         // if we've found the plugin, we can stop looking through at the rest of the plugins
         break;
         }
      }
   }
   return pluginFound;
} // detectPlugin

function play( file )
{
   // Here we write out the VBScript block for MSIE Windows
   if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
       document.writeln('<script language="VBscript">');

       document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
       document.writeln('detectableWithVB = False');
       document.writeln('If ScriptEngineMajorVersion >= 2 then');
       document.writeln('  detectableWithVB = True');
       document.writeln('End If');

       document.writeln('\'this next function will detect most plugins');
       document.writeln('Function detectActiveXControl(activeXControlName)');
       document.writeln('  on error resume next');
       document.writeln('  detectActiveXControl = False');
       document.writeln('  If detectableWithVB Then');
       document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
       document.writeln('  End If');
       document.writeln('End Function');

       document.writeln('\'and the following function handles QuickTime');
       document.writeln('Function detectQuickTimeActiveXControl()');
       document.writeln('  on error resume next');
       document.writeln('  detectQuickTimeActiveXControl = False');
       document.writeln('  If detectableWithVB Then');
       document.writeln('    detectQuickTimeActiveXControl = False');
       document.writeln('    hasQuickTimeChecker = false');
       document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
       document.writeln('    If IsObject(hasQuickTimeChecker) Then');
       document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
       document.writeln('        detectQuickTimeActiveXControl = True');
       document.writeln('      End If');
       document.writeln('    End If');
       document.writeln('  End If');
       document.writeln('End Function');

       document.writeln('</scr' + 'ipt>');
   }

   if( canDetectPlugins() )
   {
      if( detectWindowsMedia() )
         playMP( file );
      else if( detectQuickTime() )
         playQT( file );
      else
      {
         document.write( '<h2>Przeglądarka nie umożliwia odtworzenia nagrania.<br>Należy zainstalować nastepującą wtyczkę:<br>Windows Media Player albo Quick Time.<br>Tutaj można pobrać <a href "https://addons.mozilla.org/pl/firefox/browse/type:7">wtyczki dla Firefoxa</a>.</h2>' );
      }
   }
   else
   {
      document.write( '<h2>Przeglądarka nie umożliwia odtworzenia nagrania.<br>Należy zainstalować nastepującą wtyczkę:<br>Windows Media Player albo Quick Time.<br>Tutaj można pobrać <a href "https://addons.mozilla.org/pl/firefox/browse/type:7">wtyczki dla Firefoxa</a>.</h2>' );
   }
}

function playMP( file )
{
   document.write('<OBJECT ID="MediaPlayer" width=302 height=46 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">');
   document.write('<PARAM NAME="AutoStart" VALUE="True">');
   document.write('<PARAM NAME="FileName" VALUE="' + file + '"');
   document.write('<PARAM NAME="ShowControls" VALUE="false">');
   document.write('<PARAM NAME="ShowStatusBar" VALUE="false">');
   document.write('<EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ');
   document.write('src="' + file + '" ');
   document.write('name="MediaPlayer" ');
   document.write('width="302" ');
   document.write('height="46" ');
   document.write('autostart="true" ');
   document.write('showcontrols="true">');
   document.write('</EMBED>');
   document.write('</OBJECT>');
}

function playQT( file )
{
   document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" height="16" width="172" codebase="http://www.apple.com/qtactivex/qtplugin.cab">' );
   document.write('<param name="SRC" value="' + file + '">' );
   document.write('<param name="AUTOPLAY" value="true">' );
   document.write('<param name="AUTOSTART" value="true">' );
   document.write('<param name="LOOP" value="false">' );
   document.write('<param name="CONTROLLER" value="true">' );
   document.write('<embed src="' + file + '" height="16" width="172"');
   document.write('autoplay="true"'); 
   document.write('controller="true"');
   document.write('pluginspage="http://www.apple.com/quicktime/download/">');
   document.write('</embed>');
   document.write('</object>' );
}

//
// Plays content for a given period of time
// Time should be as 'mm:ss:tt'
//
function playTime( file, time )
{
   document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" height="16" width="172" codebase="http://www.apple.com/qtactivex/qtplugin.cab">' );
   document.write('<param name="SRC" value="' + file + '">' );
   document.write('<param name="AUTOPLAY" value="true">' );
   document.write('<param name="AUTOSTART" value="true">' );
   document.write('<param name="LOOP" value="false">' );
   document.write('<param name="CONTROLLER" value="true">' );
   document.write('<param name="ENDTIME" value="00:' + time + '">' );
   document.write('<embed src="' + file + '" height="16" width="172"');
   document.write('autoplay="true"'); 
   document.write('controller="true"');
   document.write('endtime="00:' + time + '"');
   document.write('pluginspage="http://www.apple.com/quicktime/download/">');
   document.write('</embed>');
   document.write('</object>' );
}

function playDef( file )
{
   document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" height="16" width="172" codebase="http://www.apple.com/qtactivex/qtplugin.cab">' );
   document.write('<param name="SRC" value="../mp3/' + file + '">' );
   document.write('<param name="AUTOPLAY" value="false">' );
   document.write('<param name="AUTOSTART" value="false">' );
   document.write('<param name="LOOP" value="false">' );
   document.write('<param name="CONTROLLER" value="true">' );
   document.write('</object>' );
}

/*
function createControl( DivID, file )
{
  var d = document.getElementById(DivID);
  d.innerHTML = 
    <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" height="16" width="172" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
    <param name="SRC" value="../mp3/' + file + '">
    <param name="autoStart" value="false">
    </object>;
    
  
}
*/

function playVideo( id, onlyControls )
{
   // Here we write out the VBScript block for MSIE Windows
   if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
       document.writeln('<script language="VBscript">');

       document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
       document.writeln('detectableWithVB = False');
       document.writeln('If ScriptEngineMajorVersion >= 2 then');
       document.writeln('  detectableWithVB = True');
       document.writeln('End If');

       document.writeln('\'this next function will detect most plugins');
       document.writeln('Function detectActiveXControl(activeXControlName)');
       document.writeln('  on error resume next');
       document.writeln('  detectActiveXControl = False');
       document.writeln('  If detectableWithVB Then');
       document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
       document.writeln('  End If');
       document.writeln('End Function');

       document.writeln('\'and the following function handles QuickTime');
       document.writeln('Function detectQuickTimeActiveXControl()');
       document.writeln('  on error resume next');
       document.writeln('  detectQuickTimeActiveXControl = False');
       document.writeln('  If detectableWithVB Then');
       document.writeln('    detectQuickTimeActiveXControl = False');
       document.writeln('    hasQuickTimeChecker = false');
       document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
       document.writeln('    If IsObject(hasQuickTimeChecker) Then');
       document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
       document.writeln('        detectQuickTimeActiveXControl = True');
       document.writeln('      End If');
       document.writeln('    End If');
       document.writeln('  End If');
       document.writeln('End Function');

       document.writeln('</scr' + 'ipt>');
   }

   if( canDetectPlugins() )
   {
      if( detectFlash() )
      {
         if( onlyControls )
            playSFsmall( id );
         else
            playSF( id );
      }
      else
      {
         document.write( '<b>Shockwave Flash Player nie jest zaistalowany!</b><br>Tutaj można pobrać <a href "https://addons.mozilla.org/pl/firefox/browse/type:7">wtyczki dla Firefoxa</a>.' );
         return false;
      }
   }
   else
   {
      document.write( '<b>Shockwave Flash Player nie jest zaistalowany!</b><br>Tutaj można pobrać <a href "https://addons.mozilla.org/pl/firefox/browse/type:7">wtyczki dla Firefoxa</a>.' );
      return false;
   }
   return true;
}

function playSF( id )
{
   document.write('<object width="425" height="344">');
   document.write(' <param name="movie" value="http://www.youtube.com/v/' + id +'&hl=en&fs=1&rel=0"></param>' );
   document.write(' <param name="allowFullScreen" value="true"></param>');
   document.write(' <embed src="http://www.youtube.com/v/' + id +'&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344">');
   document.write(' </embed>');
   document.write('</object>' );
}

function playSFsmall( id )
{
   document.write('<object width="425" height="344">');
   document.write(' <param name="movie" value="http://www.youtube.com/v/' + id +'&hl=en&fs=1&rel=0"></param>' );
   document.write(' <param name="allowFullScreen" value="true"></param>');
   document.write(' <embed src="http://www.youtube.com/v/' + id +'&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="44">');
   document.write(' </embed>');
   document.write('</object>' );
}

