// Copyright VPI Pet Insurance, 2010
// 
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, electronic, mechanical or otherwise, is prohibited
// without the prior written consent of the copyright owner.
// 
// Filename: BrightCove_Functions.js

var bcExp;
var modVP = null;
var _position = 0;
var _videoID = null;

function onTemplateLoaded(experienceID) {
	bcExp = brightcove.getExperience(experienceID);
	modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
	modVP.addEventListener(BCMediaEvent.PLAY, onPlay);
	modVP.addEventListener(BCMediaEvent.STOP, onStop);
}

function onPlay(evt) {
    $('#featuredContent ul').cycle('stop');

}

function onStop(evt) {
    _position = evt.position;
    _videoID = evt.media.id;
}

function stopPlayer() {
    if (modVP != null)
    {
        if (modVP.isPlaying())
        {
            modVP.stop();
            _position = 0;
            $('#featuredContent ul').cycle({
                fx: 'scrollHorz',
                slideExpr:'li',
                timeout:6000,
                speed:550,
                prev:'#prev',
                next:'#next',
                delay:-2000,
                pause:1,
                startingSlide:1
            });
            $('#featuredContent ul').cycle('start');
	    }
	    else if (_position > 0)
	    {
	        modVP.cueVideo(_videoID);
	        _position = 0;
	        $('#featuredContent ul').cycle({
                fx: 'scrollHorz',
                slideExpr:'li',
                timeout:6000,
                speed:550,
                prev:'#prev',
                next:'#next',
                delay:-2000,
                pause:1,
                startingSlide:1
            });
            $('#featuredContent ul').cycle('start');
	    }
    }
}




