
/* Copyright (c) 2007-2012 Filmit IT Solutions. All rights reserved. */

/**
 * Collection of JavaScript functions
 * for Filmit CMS generated DHTML pages.
 */


function showClip( clipAddress, width, height, clipDiv) {

  var clipNode = document.getElementById( clipDiv);
  var ctrlHeight = height + 16;
  var clipObject = null;
  var srcParam = null;
  var autoParam = null;
  var ctrlParam = null;
  var isIE = false;
  var isWin7 = false;
  var isQtEnabled = false;
  var isWMPEnabled = false;

  clipNode.style['padding'] = '20pt 0';

  if ( "ActiveXObject" in window) {

    if ( navigator.userAgent.indexOf( 'Windows NT 6.1' ) != -1) {

      isWin7 = true;
    }

    try {

      clipObject = new ActiveXObject('QuickTime.QuickTime');
      clipObject = null;

      isQtEnabled = true;

    } catch (e) {}

    try {

      clipObject = new ActiveXObject('WMPlayer.OCX');
      clipObject = null;

      isWMPEnabled = true;

    } catch (e) {}


    if ( isWin7 & isWMPEnabled & (!isQtEnabled)) {

      clipObject = document.createElement( 'object');
      srcParam = document.createElement ( 'param');
      autoParam = document.createElement ( 'param');
      ctrlParam = document.createElement ( 'param');

      srcParam.name = 'url';
      srcParam.value = clipAddress;
      clipObject.appendChild( srcParam);

      autoParam.name = 'autoStart';
      autoParam.value = 'true';
      clipObject.appendChild( autoParam);

      ctrlParam.name = 'UIMode';
      ctrlParam.value = 'full';
      clipObject.appendChild( ctrlParam);

      clipObject.width = width.toString();
      ctrlHeight = height + 64;
      clipObject.height = ctrlHeight.toString();

      while ( clipNode.firstChild) {
        clipNode.removeChild( clipNode.firstChild);
      }
      clipNode.appendChild( clipObject);

      clipObject.classid = 'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6';

    } else if ( isQtEnabled) {

      clipObject = document.createElement( 'object');
      srcParam = document.createElement ( 'param');
      autoParam = document.createElement ( 'param');
      ctrlParam = document.createElement ( 'param');

      srcParam.name = 'src';
      srcParam.value = clipAddress;
      clipObject.appendChild( srcParam);

      autoParam.name = 'autoplay';
      autoParam.value = 'true';
      clipObject.appendChild( autoParam);

      ctrlParam.name = 'controller';
      ctrlParam.value = 'true';
      clipObject.appendChild( ctrlParam);

      clipObject.width = width.toString();
      clipObject.height = ctrlHeight.toString();

      while ( clipNode.firstChild) {
        clipNode.removeChild( clipNode.firstChild);
      }
      clipNode.appendChild( clipObject);

      clipObject.codeBase = 'http://www.apple.com/qtactivex/qtplugin.cab';
      clipObject.classid = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';

    } else if ( isWin7) {

      clipObject = document.createElement( 'p');
      while ( clipNode.firstChild) {
        clipNode.removeChild( clipNode.firstChild);
      }
      clipNode.appendChild( clipObject);

      clipObject.innerHTML = 'Add-on missing or disabled<br />&nbsp;<br />To play this clip as embedded media, enable either one of these add-ons: <a class="body" href="http://www.apple.com/quicktime/download/">QuickTime Object</a>, Windows Media Player. Alternatively, use the link provided below to download the clip for playback with an external player of your choice.';

    } else {

      clipObject = document.createElement( 'p');
      while ( clipNode.firstChild) {
        clipNode.removeChild( clipNode.firstChild);
      }
      clipNode.appendChild( clipObject);

      clipObject.innerHTML = 'Add-on missing or disabled<br />&nbsp;<br />To play this clip as embedded media, enable this add-on:<a class="body" href="http://www.apple.com/quicktime/download/">QuickTime Object</a>. Alternatively, use the link provided below to download the clip for playback with an external player of your choice.';

    }


  } else {

    clipNode.innerHTML = '<EMBED SRC="' + clipAddress + '" WIDTH="' + width.toString() + '" HEIGHT="' + ctrlHeight.toString() + '" TYPE="video/quicktime" PLUGINSPAGE="http://www.apple.com/quicktime/download/" AUTOPLAY="true" CONTROLLER="true" \/>';

  }

  return void(0);
}

