var bcExp;
var modVP;
var modExp;
var modContent;
var currentVideo='';

// called when template loads, this function stores a reference to the player and modules.
// Then event listeners will be added for when the template is ready and when a user 
// clicks on a video.
function onTemplateLoaded(experienceID) {
    //alert("EVENT: TEMPLATE_LOAD");
    bcExp = brightcove.getExperience(experienceID);
    
    modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
    modExp = bcExp.getModule(APIModules.EXPERIENCE);
    modContent = bcExp.getModule(APIModules.CONTENT);
	modAdvertising = bcExp.getModule(APIModules.ADVERTISING);
  
    modExp.addEventListener(BCExperienceEvent.TEMPLATE_READY, onTemplateReady);
    modExp.addEventListener(BCExperienceEvent.CONTENT_LOAD, onContentLoad);
	//modVP.addEventListener(BCVideoEvent.STREAM_START, onStreamStart);
	modVP.addEventListener(BCVideoEvent.VIDEO_CONNECT, onVideoConnect);
	//modAdvertising.addEventListener(BCAdvertisingEvent.AD_START, onAdStart);

    //modContent.addEventListener(BCContentEvent.VIDEO_LOAD, onVideoLoad); 
	//modContent.addEventListener(BCContentEvent.STREAM_START, onStreamStart);
  
}



function onVideoConnect(evt) {
    currentVideo = modVP.getCurrentVideo();
	//var locationStr = ''+window.location;
	if (fod_videoid != currentVideo.id) {
		window.location = "/?bctid=" + currentVideo.id;
		//if (locationStr.indexOf(currentVideo.id) < 0) {window.location = "/?bctid=" + currentVideo.id;}
		modVP.stop();
	}
}

function onAdStart(evt) {
	if (currentVideo!='') {
		if (fod_videoid != currentVideo.id) {
			alert('videoid='+fod_videoid);
			window.location = "/?bctid=" + currentVideo.id;
			//if (locationStr.indexOf(currentVideo.id) < 0) {window.location = "/?bctid=" + currentVideo.id;}
			modVP.stop();
		}
	}
}

function onTemplateReady(evt) {
    //alert("EVENT: TEMPLATE_READY"); 
    }
	
function onContentLoad(evt) {
    //alert("EVENT: CONTENT_LOAD");
  
    currentVideo = modVP.getCurrentVideo();
	//var locationStr = ''+window.location;
	//alert('hello');
	//alert(locationStr.indexOf(currentVideo.id) < 0);
	//if (locationStr.indexOf(currentVideo.id) < 0) {window.location = "/?bctid=" + currentVideo.id;}
	//
    //alert("INFO: Currently Loaded videoID: " + currentVideo.id);
  	//document.title += " - " + currentVideo.id;
    //modContent.getVideoAsynch(1488633950);
}
function onVideoLoad(evt) {
    //alert("EVENT: VIDEO_LOAD");
  
    // Play video that was just loaded
    //modVP.loadVideo(evt.video.id);
}

function buildDimmerDiv()
{
	var windowWidth, windowHeight;
	   if (self.innerHeight) {     // all except Explorer
		 windowWidth = self.innerWidth;
		 windowHeight = self.innerHeight;
	   } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		 windowWidth = document.documentElement.clientWidth;
		 windowHeight = document.documentElement.clientHeight;
	   } else if (document.body) { // other Explorers
		 windowWidth = document.body.clientWidth;
		 windowHeight = document.body.clientHeight;
	   }
     windowWidth = 100 ;
    windowHeight = 1280;   //   Height del site
	//$('body').append('<div id="dimmer" class="dimmer" style="z-index:1000000; width:'+ windowWidth + '%; height:' + windowHeight +'px"></div>');
    document.write('<div id="dimmer" class="dimmer" style="z-index:1000000; width:'+ windowWidth + '%; height:' + windowHeight +'px"></div>');
}
//
function showDimmer(divId, title, width, height, left, top) 
{
	document.getElementById('dimmer').style.visibility = "visible";
    }
//
function hideDimmer() 
{
	document.getElementById('dimmer').style.visibility = "hidden";
}

//
function init()
{
	buildDimmerDiv();
}
// call init
init();
