var videocount;
var videos;
var videoswidth;
var videosheight;
var allsetup;

function createActiveXObject(id)
{
    var error;
    var control = null;
    
    try
    {
        if (window.ActiveXObject)
        {
            control = new ActiveXObject(id);
        }
        else if (window.GeckoActiveXObject)
        {
            control = new GeckoActiveXObject(id);
        }
    }
    catch (error)
    {
        ;
    }
    return control;
}

function detectWMPSupport()
{
    var wmp64 = "MediaPlayer.MediaPlayer.1";
    var wmp7 = "WMPlayer.OCX.7";
    if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject)
    {
        if(createActiveXObject(wmp7))
        { 
            return true;
        }
        else
        {
            if(createActiveXObject(wmp64))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    else
    { 
        return false;
    }
}

function showVideo(filename, videostill, width, height)
{

    if (allsetup != 1)
    {
        videocount = 0;
        videos = new Array();
        videoswidth = new Array();
        videosheight = new Array();
        allsetup = 1;
    }

    videos[videocount] = filename;
    videoswidth[videocount] = width;
    videosheight[videocount] = height;
    
    var outString = "";
    
    outString += '<table cellpadding=0 cellspacing=0 border=0>';
    outString += '<tr><td align=center>';
    outString += '<span id=video'+videocount+'>';
    outString += '<span onclick="showVideo2('+videocount+');">';
    outString += '<img alt="Click to play!" src="'+videostill+'" width='+width+' height='+height+'>';
    outString += '<br><img alt="Click to play!" width='+width+'height=70 src=/scott/images/clickme'+width+'.png>';
    outString += '</span></span>';
    outString += '</td></tr></table>';
    
    document.write(outString);
    
    videocount ++;
}

function showVideo2 (video)
{
    var filename = videos[video];
    var width = videoswidth[video];
    var height = videosheight[video];

    var outString = "";
    height += 70;
    if (detectWMPSupport())
    {
        outString += '<OBJECT height="'+height+'" width="'+width;
        outString += '" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" MAYSCRIPT>';
        outString += '<PARAM name="URL" value="'+filename+'"/>';
        outString += '<PARAM NAME="uiMode" VALUE="full"/>';
        outString += '<PARAM NAME="enableContextMenu" value="true" />';
        outString += '<param name="AutoStart" value="true">';
        outString += '<param name="windowlessVideo" value="false"/>';      
        outString += '</OBJECT>';
    }
    else
    {
      outString += '<object name="cnnVidPlayer" width="'+width+'" height="'+height;
      outString += '" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading Stream..." type="application/x-oleobject">';
      outString += '<param name="URL" value="'+filename+'">';
      outString += '<param name="AllowChangeDisplaySize" value="True">';
      outString += '<param name="AutoSize" value="False">';
      outString += '<param name="DisplaySize" value=0>';
      outString += '<param name="ShowControls" value="True">';
      outString += '<param name="ShowTracker" value="True">';
      outString += '<param name="AutoRewind" value="True">';
      outString += '<param name="AutoStart" value="True">';
      outString += '<embed name="vidplayer" src="'+filename+'" type="application/x-mplayer2" ';
      outString += 'width="'+width+'" height="'+height+'" ShowTracker="true" showstatusbar="true" AutoSize="false" loop="false" DisplaySize="0" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
      outString += '</embed>';
      outString += '</object>';
	}
	document.getElementById("video" + video).innerHTML = outString;
}

