﻿$(function () {
    // show the order button to return visitors
    if (readCookie('DSPOrder') != null) {
        $('#orderButton').show();
    }
    
    createCookie("DSPOrder", "true", 120);
});


// cue up the order button
var bcExp;
var modCue;
var elapsed_seconds = 0;

function onTemplateLoaded(experienceID) {
    bcExp = brightcove.getExperience(experienceID);

    modCue = bcExp.getModule(APIModules.CUE_POINTS);
    modExp = bcExp.getModule(APIModules.EXPERIENCE);
    modExp.addEventListener(BCExperienceEvent.CONTENT_LOAD,
        function (evt) {
            modCue.addEventListener(BCCuePointEvent.CUE, onCue);
        });

    video = bcExp.getModule(APIModules.VIDEO_PLAYER);
    video.addEventListener(BCMediaEvent.BEGIN, onVideoBegin);
}

function onCue(evt) {
    if (evt.cuePoint.name == 'orderButton') {
        $('#orderButton').show();

        createCookie("DSPTrial", "true", 1);
    }
}

function onVideoBegin() {
    if (readCookie('VidTimer') != null) {
        elapsed_seconds = readCookie('VidTimer')
        video.seek(elapsed_seconds);
    }

    setInterval(function () {
        elapsed_seconds = parseInt(elapsed_seconds) + 1;
    }, 1000);
}

$(window).unload(function () {
    createCookie("VidTimer", elapsed_seconds, 1);
});
