function detectQT() {
    var minVersion = '7';
    // If required QuickTime is not available provide a link to download instead of a movie object
    return (AC.Detector.isValidQTAvailable(minVersion));
}

function  QTDownloadNotice() {
    var downloadNotice = document.createElement('a');
    downloadNotice.addClassName('quicktime-download');

    downloadNotice.setAttribute('href', 'http://www.apple.com/quicktime/download/');
    downloadNotice.innerHTML = 'Get the Latest QuickTime.';

    // downloadNotice.appendChild(this._createNullMovie(options.width, options.height));
    return downloadNotice;
}

function ConfirmDownload() {
    var feedback = confirm('QuickTime Player is needed to play this video. Download the latest Quicktime ?');
    if(feedback == true) openInChildWindow("http://www.apple.com/quicktime/download/", "galeChildWindow");
    return false;
}

function InsertRtspMovie(id, width, height, rtspUrl) {
    elem = getElementById(id);
    if(detectQT()) {
        elemid = elem.getAttribute("id");
        var gQTBehaviorID = "qt_event_source";

        var xhtmlString = '<!--[if IE]><object id="' + gQTBehaviorID + '" classid="clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598" height="0"></object><![endif]-->'
             + _BuildObjectStartTag(width, height)
         + '<param value="dummy.mov" name="src"/>'
         + '<param value="' + rtspUrl + '" name="qtsrc"/>'
         + '<param value="tofit" name="scale"/>'
         + '<embed height="' + height + '" width="' + width
             + '" qtsrc="' + rtspUrl + '" pluginspage="http://www.apple.com/quicktime/download/" src="dummy.mov" scale="tofit" />'
         + '</object>';

    /*
         + '<span id="' + elemid + 'imagetools"><ul><li><a href="javaScript: inlineZoom(\'' + elemid + '\', 1.5' + ')">inline zoom in</a></li>'
         + '<li><a href="javaScript: inlineZoom(\'' + elemid + '\', 0.75' + ')">inline zoom out</a></li></ul></span>';
    */
        elem.innerHTML = xhtmlString;
    } else {
        //elem.innerHTML = QTDownloadNotice();
        ConfirmDownload();
    }
}

function InsertRtspMovieAutoPlay(id, width, height, rtspUrl) {
    elem = getElementById(id);
    if(detectQT()) {
        elemid = elem.getAttribute("id");
        var gQTBehaviorID = "qt_event_source";

        var xhtmlString = '<!--[if IE]><object id="' + gQTBehaviorID + '" classid="clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598" height="0"></object><![endif]-->'
             + _BuildObjectStartTag(width, height)
         + '<param value="dummy.mov" name="src"/>'
         + '<param value="' + rtspUrl + '" name="qtsrc"/>'
         + '<param value="tofit" name="scale"/>'
         + '<param value="TRUE" name="AUTOPLAY"/>'
         + '<embed height="' + height + '" width="' + width
             + '" qtsrc="' + rtspUrl + '" pluginspage="http://www.apple.com/quicktime/download/" src="dummy.mov" scale="tofit" AUTOPLAY="TRUE"/>'
         + '</object>';

    /*
         + '<span id="' + elemid + 'imagetools"><ul><li><a href="javaScript: inlineZoom(\'' + elemid + '\', 1.5' + ')">inline zoom in</a></li>'
         + '<li><a href="javaScript: inlineZoom(\'' + elemid + '\', 0.75' + ')">inline zoom out</a></li></ul></span>';
    */

        elem.innerHTML = xhtmlString;
    } else {
       //elem.innerHTML = QTDownloadNotice();
        ConfirmDownload();
    }
}

function inlineZoom(elemId, factor) {

  elem = document.getElementById(elemId);

  // spin through the DOM looking for width and height parameters
  videoelem = elem.childNodes[1];
  newWidth = videoelem.getAttribute("width") * factor;
  newHeight = videoelem.getAttribute("height") * factor;
  videoelem.setAttribute("width", newWidth);
  videoelem.setAttribute("height", newHeight);

  for (i=0; i<videoelem.childNodes.length; ++i) {
    paramelem = videoelem.childNodes[i];
    if (null != paramelem.getAttribute("width")) {
      paramelem.setAttribute("width", newWidth);
    }
    if (null != paramelem.getAttribute("height")) {
      paramelem.setAttribute("height", newHeight);
    }
  }
}


// build and return a string for the object start tag.
function _BuildObjectStartTag(width, height) {

	var classid = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
	var pluginspage = "http://www.apple.com/quicktime/download/";
	var codebase = "http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0";

	return '<object height="' + height + '" width="' + width +
          '" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" scale="tofit" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B">';
}

