/*
	FlashReplace is developed by Robert Nyman, http://www.robertnyman.com. License and downloads: http://code.google.com/p/flashreplace/
*/
// ---
var QuickTimeReplace = {
    elmToReplace: null,
    quickTimeInstalled: null,
    defaultQuickTimeVersion: 6,
    replace: function(elmToReplace, src, id, width, height, strPreferedFileExtension, version, params) {
        this.elmToReplace = document.getElementById(elmToReplace);
        this.quickTimeInstalled = this.checkForQuickTime(version || this.defaultQuickTimeVersion);
        if (this.elmToReplace && this.quickTimeInstalled) {

            if (strPreferedFileExtension == null)
                strPreferedFileExtension = '.mov'

            if (screen.width < 1024) {
                window.location.href = src + '.m4v';
            }
            else {

                var obj = '<object id="' + id + '" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
                obj += ' width="' + width + '"';
                obj += ' height="' + height + '"';
                obj += ' id="QuickTimeMovie"'
                obj += '>';
                var param = '<param';
                param += ' name="src"';
                param += ' value="' + src + strPreferedFileExtension + '"';
                param += '>';
                param += '<param';
                param += ' name="autoplay"';
                param += ' value="true"';
                param += ' />';




                var extraParams = '';
                var extraAttributes = '';
                for (var i in params) {
                    extraParams += '<param name="' + i + '" value="' + params[i] + '" autoplay="true" />';
                    extraAttributes += ' ' + i + '="' + params[i] + '"';
                }
                var embed = '<embed id="' + id + '" src="' + src + strPreferedFileExtension + '" width="' + width + '" height="' + height + '" autoplay="true" ';



                var embedEnd = extraAttributes + ' name="QuickTimeMovie"></embed>';
                var objEnd = '</object>';

                this.elmToReplace.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;
            }
        }
    },

    checkForQuickTime: function(version) {


        var nse;
        var agt = navigator.userAgent.toLowerCase();

        try {
            ie = true
            ns = false
            new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch (err) {

            ie = false
            ns = true
        }

        var win = ((agt.indexOf("win") != -1) || (agt.indexOf("32bit") != -1));
        var mac = (agt.indexOf("mac") != -1);

        this.quickTimeIsInstalled = false;


        if (ie && win) {
            this.quickTimeIsInstalled = detectIE("QuickTimeCheckObject.QuickTimeCheck." + version, "QuickTime");
        }

        if (ns || !win) {
            nse = ""; for (var i = 0; i < navigator.mimeTypes.length; i++) nse += navigator.mimeTypes[i].type.toLowerCase();
            this.quickTimeIsInstalled = detectNS("video/quicktime", "QuickTime");
        }

        function detectIE(ClassID, name) {


            result = false;

            if (BrowserDetect.version < 7) {
                document.write('<script type="text/vbscript">\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '")) \n </script>');
            }
            else {
                alert('Message to Internet Explorer 8 users. If the video does not start, the solution probably is that you need to install QuickTime from http://www.apple.com/quicktime/download/. If QuickTime is installed and it still does not start, note that graphics plugins like QuickTime still will not work on the 64bit version of Internet Explorer, you will have to use the 32bit version. Contact 07779641375 (UK time) or contact@on-schedule.org for assistance.')
                return true
            }

            if (result)
                return true;
            else
                return false;

        }

        function detectNS(ClassID, name) {

            if (nse.indexOf(ClassID) != -1) {
                if (navigator.mimeTypes[ClassID].enabledPlugin != null)
                    return true;
                else
                    return false;
            }
            return false;
        }

        return this.quickTimeIsInstalled;
    }

};
// ---