﻿//Video In Page Constants

var MOVIE_WRAPPER_DIV = 'large-player-wrapper';
var VIDEO_LIBRARY_PATH = '/support-resources/bipolar-disorder-videos.aspx';

var MOVIE_EMBED_DIV_LARGE = 'flash-player-large';
var MOVIE_NAME_LARGE = 'SQC114_inPagePlayer';
var MOVIE_PATH_LARGE = '/swf/video-in-page/SQC114_inPagePlayer.swf';

var MOVIE_EMBED_DIV_SMALL = 'flash-player-small';
var MOVIE_NAME_SMALL = 'SQC114_inPage';
var MOVIE_PATH_SMALL = '/swf/video-in-page/SQC114_inPage.swf';

//Set an interval before we call the externalInterface method.
//This allows the XML to load.
var MOV_ID = '';
var t;
function waitBeforeSetMovieID() {
	clearTimeout(t);
	var myFlashMovie = document.getElementById(MOVIE_NAME_LARGE);
	myFlashMovie.setMovieID(MOV_ID);
}

//Called by the small swf
function passIDToLargeSwf(id) { 

	//Ensure movie is visible
	toggleFlashDiv(MOVIE_WRAPPER_DIV,1);
	
	//Add
	resetLargeSwf();
	
	
	//Call flash function
	var myFlashMovie = document.getElementById(MOVIE_NAME_LARGE);
	if (myFlashMovie) {
		//alert('calling func...');
		//myFlashMovie.setMovieID(id);
		MOV_ID = id;
		t = setTimeout("waitBeforeSetMovieID()", 1000);
	}
	else {
		alert('did not find flash object');
	}
}

//This function is called by Flash to show or hide the large flash div.
function toggleFlashDiv(id,n) {
	if (n == 0) {
		resetLargeSwf();
	}
	if (document.getElementById(id)) {
		var obj = document.getElementById(id);
		obj.style.display = (n == 1 ? 'block' : 'none');
	}
}

//Re-embed the swf object, so we can successfully call the externalInterface method again.
function resetLargeSwf() {
	document.getElementById(MOVIE_WRAPPER_DIV).innerHTML = '<div id="' + MOVIE_EMBED_DIV_LARGE + '" class="player"></div>';
	//Re-embed large video
	attributes = { id: MOVIE_NAME_LARGE, name: MOVIE_NAME_LARGE };
	swfobject.embedSWF(MOVIE_PATH_LARGE, MOVIE_EMBED_DIV_LARGE, "716", "356", "8.0.0", "", flashvars, params, attributes);
	SQC114_inPagePlayer = document.getElementById('SQC114_inPagePlayer'); //Reassociate for IE6.		

}

// EMBED SWFs
	var params =  { wmode: "transparent", allowScriptAccess: "always" }
	//var params =  { allowScriptAccess: "sameDomain" }
	var attributes = { };
	var flashvars = { 
		videoPath: MOVIE_CONFIG_PATH,
		largeFlashDivID: MOVIE_WRAPPER_DIV,
		vidLib: VIDEO_LIBRARY_PATH
	};
	
	

$(document).ready(function() {
	//Embed small video
	attributes = { id: MOVIE_NAME_SMALL, name: MOVIE_NAME_SMALL };
	swfobject.embedSWF(MOVIE_PATH_SMALL, MOVIE_EMBED_DIV_SMALL, "275", "275", "8.0.0", "", flashvars, params, attributes);
	SQC114_inPage = document.getElementById('SQC114_inPage'); //Reassociate for IE6.	
	
	
	//Embed large video
	attributes = { id: MOVIE_NAME_LARGE, name: MOVIE_NAME_LARGE };
	swfobject.embedSWF(MOVIE_PATH_LARGE, MOVIE_EMBED_DIV_LARGE, "716", "356", "8.0.0", "", flashvars, params, attributes);
	SQC114_inPagePlayer = document.getElementById('SQC114_inPagePlayer'); //Reassociate for IE6.		
});