﻿function PlayVideo()
{
    var videoheight, filename, introimage, divid, streamerapp, canembed, controller;
    
    this.Init = function(height, file, intro, div, streamer, embed, hascontroller)
    {
        videoheight = height;
        
        filename = file;
        
        introimage = intro;
        
        divid = div;
        
        streamerapp = streamer;
        
        canembed = embed;
        
        controller = hascontroller;
        
		setTimeout(function(){LoadVideo();}, 1000);
    }
    
    function ShowImage()
    {
        var videodiv = document.getElementById(divid);
        
        var container = document.createElement('div');
        
        videoheight = videoheight - 19;
 
        container.style.height = videoheight + 'px';
        
        container.style.width = '480px'
        
        container.style.backgroundImage = "url('/FileReturn.aspx?src=" + introimage + "&width=480&height=" + videoheight + "&returntype=thumb')";
        
        container.style.backgroundRepeat = 'no-repeat';
        
        container.style.backgroundPosition = 'center center';
        
        container.style.cursor = 'pointer';
        
        container.style.position = 'relative';
        
        container.style.backgroundColor = "#000000";
        
        container.onclick = function(){window.open('http://get.adobe.com/flashplayer/');};
        
        videodiv.appendChild(container);
        
        var message = document.createElement('div');
        
        message.className = 'mmnoflash ie6fix';
        
        message.style.left = '42px'; 
        
        message.style.top = Math.floor((videoheight - 133)/2) + 'px';
        
        container.appendChild(message);
    }
    
    function GetEmbedCode()
    {
        if (canembed)
        {
            var embeddiv = document.getElementById('embeddiv');
            
            embeddiv.onclick = function(){player.sendEvent('SHOW_EMBED')};
            
            embeddiv.style.cursor = 'pointer';
            
            embeddiv.innerHTML = "<span style=\"color:#392D1C;font-size:13px;font-weight:bold;margin-right:4px;\">&lt;<span style=\"font-size:11px;\">/</span>&gt;</span>EMBED";
  
            var embedCode = '<embed src="http://www.gatesfoundation.org/_layouts/swf/Multimedia/player.swf" width="480" height="' + videoheight + '" bgcolor="000000" allowfullscreen="true" allowscriptaccess="always" flashvars="file=' + filename + ShowController() +'&image=http://' + document.domain + introimage + GetStreamApp() + '"></embed>';

            return '&embed.code=' + escape(embedCode) + '&embed.show_window_after_complete=true';
        }
        
        return '';
    }
    
    function GetStreamApp()
    { 
        if (streamerapp)
        {
            return '&stretching=exactfit&autostart=true&type=fcsubscribe&streamer=' + streamerapp;
        }
        
        return '';
    }
    
    function ShowController()
    {
        if (!controller)
        {
            return '&controlbar=none&autostart=true';
        }
        
        return '';
    }
    
    function LoadVideo()
    {
        var so = new SWFObject('/_layouts/swf/Multimedia/player.swf', 'mediaplayer', 480, videoheight, '9.0.115.0', '#000000');
           
        so.addParam('allowscriptaccess','always');
        so.addParam('allowfullscreen','true');
        so.addParam('wmode', 'transparent');
        so.addParam('flashvars', '&width=480&height=' + videoheight + ShowController() + '&file=' + filename + '&plugins=/_layouts/swf/Multimedia/embed-1.swf&image=' + introimage + GetStreamApp() + GetEmbedCode());

        if (!so.write(divid))
        {
            ShowImage();
        }
    }
}
