﻿
var player;
var videoPlayer;
var handlerUrl = "/dhc/Videos/GetVideo.ashx";

/* called when template loads, we use this to store a reference to the player and modules
    and add event listeners for the video load (when the user clicks on a video)
 */
function onTemplateLoaded(experienceId) 
{
    player = brightcove.getExperience(experienceId);
    videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
    pauseState = false;
}

function pauseVideo() 
{
   videoPlayer.pause(true);
}

function showProductVideo(productId, left, top) {
    showVideo(handlerUrl +"?productId=" + productId, left, top);
}

function showNonProductVideo(videoName, left, top) {
    showVideo(handlerUrl + "?videoName=" + videoName, left, top);
}

function showVideo(handlerUrlWithParameters, left, top) {
    $.ajax({
        url: handlerUrlWithParameters,
        crossDomain: false,
        success: function (html) {
            showModalPopupForVideo(left, top);
            $("#VideoScriptDivision").html(html);
            brightcove.createExperience($("#myExperience").get(0), $("#VideoScriptDivision").get(0), true);
        }
        //,error: ajax_error
    }
    );
}

function showModalPopupForVideo(left, top) {
    OpenModalPopupAtLeftAndTopPositions('ModalPopupDivForVideo',
                                        'MaskedDiv',
                                         $('#PageHeaderTable').offset().left + left,
                                         $('#PageHeaderTable').offset().top + top, 
                                         true);
    
}


function ajax_error(request, type, errorThrown)
{
    var message = "There was an error with the AJAX request.\n";
    switch (type) {
        case 'timeout':
            message += "The request timed out.";
            break;
        case 'notmodified':
            message += "The request was not modified but was not retrieved from the cache.";
            break;
        case 'parseerror':
            message += "XML/Json format is bad.";
            break;
        default:
            message += "HTTP Error (" + request.status + " " + request.statusText + ").";
    }
    message += "\n";
    alert(message);
}

