﻿var CaseIHScout = {};
CaseIHScout.Flash = function() {

    var showFlashDetectionFailure = function(id) {
        var element = findFlashDetectionFailure(document.getElementById(id));
        if (element) {
            element.style.display = 'block';
        }
    };


    var hideFlashDetectionFailure = function(id) {
        var element = findFlashDetectionFailure(document.getElementById(id));
        if (element) {
            element.style.display = 'none';
        }
    };

    var findFlashDetectionFailure = function(element) {
        var needle;
        if (element) {
            if (element.nodeType == 1 && element.className.indexOf('FlashDetectionFailure') != -1) {
                needle = element;
            } else if (element.childNodes.length > 0) {
                var needle;
                for (var i = 0; i < element.childNodes.length; i++) {
                    needle = findFlashDetectionFailure(element.childNodes[i]);
                    if (needle) {
                        break;
                    }
                }
            }
        }
        return needle;
    };

    var isExpressInstallerSupported = function() {
        var vista = navigator.userAgent.match(/Windows NT (\d)\.\d/);
        if (vista && parseInt(vista[1]) >= 6) {
            return swfobject.hasFlashPlayerVersion('9.0.28');
        } else {
            return swfobject.hasFlashPlayerVersion('6.0.65');
        }
    };

    return {

        embedSWF: function(src, id, width, height, flashvars, params) 
        {
            // Ensure params have been defined and set defaults
            if (params == null) {
                params = {};
            }
            params['bgcolor'] = params['bgcolor'] || '#ffffff';
            params['wmode'] = params['wmode'] || 'opaque';
            params['base'] = params['base'] || 'Flash';

            // The ID passed to this script is the container element ID. All Flash embedding on this
            // site will be done in a child element of the container named "{ID}-FlashContent". We
            // should test for the existence of the elementand if it exists use it rather than the
            // container we are given. Please see /UserControls/FlashContainerUserControl.ascx for
            // more information
            id += '-FlashContent';

            // Test success for having the main Flash version or support for express intall
            if (isExpressInstallerSupported()) {
                swfobject.embedSWF(src, id, width, height, '8.0.0', params['base'] + '/ExpressInstaller.swf', flashvars, params);
            } else {
                swfobject.addDomLoadEvent(function() {
                    showFlashDetectionFailure(id);
                });
            }
        }
    };
} ();