﻿var GFOVideo = {
    Init: function(height, file, intro, div, streamer, embed, hascontroller, width) {

        function ShowImage() {
            height = height - 19;

            $('#' + div).append($('<div></div>').css('cursor', 'pointer').css('height', height).css('width', width)
				.css('backgoundColor', '#000000').css('backgroundImage', 'url("/FileReturn.aspx?src=' + intro + '&width=' + width + '&height=' + height + '&returntype=thumb")')
				.css('backgroundRepeat', 'no-repeat').css('backgroundPosition', 'center center').css('position', 'relative')
				.click(function() { window.open('http://get.adobe.com/flashplayer/'); })
				.append('<div class="mmnoflash ie6fix" style="left:42px;top:' + Math.floor((height - 133) / 2) + 'px;"></div>'));
        }

        function GetStreamApp() {
            return (streamer ? '&stretching=exactfit&autostart=true&type=fcsubscribe&streamer=' + streamer : '');
        }

        function ShowController() {
            return (hascontroller ? '' : '&controlbar=none&autostart=true');
        }

        function GetEmbedCode() {
            if (embed) {
                var embeddiv = $('#embeddiv');

                if (embeddiv.length) {
                    embeddiv.click(function() { player.sendEvent('SHOW_EMBED') }).css('cursor', 'pointer')
					.html('<span style="color:#392D1C;font-size:13px;font-weight:bold;margin-right:4px;">&lt;<span style="font-size:11px;">/</span>&gt;</span>EMBED');
                }

                return '&embed.code='
				+ escape('<embed src="http://www.gatesfoundation.org/_layouts/swf/Multimedia/player.swf" width="400" height="225" bgcolor="000000" allowfullscreen="true" allowscriptaccess="always" flashvars="file=' + file + ShowController() + '&image=http://' + document.domain + intro + GetStreamApp() + '"></embed>')
				+ '&embed.show_window_after_complete=true';
            }

            return '';
        }

        function LoadVideo() {
            var so = new SWFObject('/_layouts/swf/Multimedia/player.swf', 'mediaplayer', width, height, '9.0.115.0', '#000000');

            so.addParam('allowscriptaccess', 'always');
            so.addParam('allowfullscreen', 'true');
            so.addParam('wmode', 'transparent');
            so.addParam('flashvars', '&width=' + width + '&height=' + height + ShowController() + '&file=' + file + '&plugins=/_layouts/swf/Multimedia/embed-1.swf&image=' + intro + GetStreamApp() + GetEmbedCode());

            if (!so.write($('#' + div)[0])) {
                ShowImage();
            }
        }

        width = isNaN(width) ? 480 : width;

        $(window).load(function() { LoadVideo(); });
    }
}