﻿/// <reference path="VideoScripts.js" />
function createPlayer(theFile, videoId, theImg, autostart, icons) 
{
    var params =
    {
        allowfullscreen: "true",
        allowscriptaccess: "always",
        wmode: "opaque", 
        menu: "true"
    };
    
    var flashvars = 
    {
        frontcolor: "0x2E6BAE",
        screencolor: "0xeeeeee",
        autostart: autostart,
        width: "640", 
        height: "500",
        bufferlength: "10",
        usefullscreen: "true",
        repeat: "list",
        shuffle: "false",
        showdownload: "false",
        file: theFile,
        javascriptid: "videoContent",
        enablejs: "true",
        showIcons: icons,
        abouttxt:'PrepLogic Media Player',
        aboutlnk: 'http://www.preplogic.com',
        image: theImg
    };
    var attributes = 
    {
        id: "videoContent"
    };
    
    // Stop the player if it is already running
    // canHaveHTML is false if videoContent is a <div>, true when it is an object
    var videoContent = $("videoContent");
    if (!videoContent.canHaveHTML)
        sendEvent("videoContent", "stop");
    
    // recreate the videoContent element
    videoContent = null;
    var videoContentContainer = $("videoContentContainer");
    videoContentContainer.innerHTML = '<div id=\"videoContent\"><a href=\"http://www.adobe.com/go/getflashplayer\" target=\"_blank\"><img style=\"border: 0px;\" alt=\"Get Adobe Flash Player\" src=\"/videoimages/get_adobe_flash_player.jpg\" /></a></div>'
 
    // embed the player
    swfobject.embedSWF(
        "mediaplayer.swf", "videoContent",
        "640", "500", "9.0.115","expressInstall.swf",
        flashvars, params, attributes);
}
var directSend = 0;
function sendEvent(swf,typ,prm)
{
    if (typ == "playitem")
        directSend = prm;
    try
    {
        var host = $(swf);
        if (host != null)
            host.sendEvent(typ, prm);
    }
    catch(e){ }
};
function sendVCplayitem(prm) {
    var host = $('videoContent');
    host.sendEvent('playitem', prm);
}
function getUpdate(typ,pr1,pr2,swf) {
    if(typ == "item" && swf == "videoContent") {
        var obj = $('playListIndex');
        if (swf == directSend)
            directSend = 0;
        else {
            obj.value = pr1;
            //alert(pr2);
            setVideoListSelectionIndex(LAST_SELECTED_INDEX);
            var VideoIdSpan = jQuery('#VideoInList_Video_' + LAST_SELECTED_INDEX).children()[0];
            VideoService.InsertVideoViewLog(parseInt(VideoIdSpan.innerHTML));
            LAST_SELECTED_INDEX++;
        }
    }
    if(typ == 'state') {
        // drop out of fullscreen
        if(pr1 == 3) {
            this.window.focus();
            var allLinks = $('lblVideoList').childNodes;
            var totalVideoCount = 0;
            for (i=0; i < allLinks.length; i++) {
                if (allLinks[i].tagName == "A")
                    totalVideoCount++;
            }
            IsUserLoggedIn();
            if (LAST_SELECTED_INDEX >= totalVideoCount) {
                $('videoContentContainer').innerHTML = '<div id=\"videoContent\"><img src=\"/videoimages/video_fire_still.jpg\" onclick=\"courseChanged($(\'cidDiv\').innerHTML, true);\" style=\"cursor: pointer;\" /></div>';
            }
       }
    }
}
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1)
    return window[swf];
  else
    return document[swf];
}


