var isVisible = false;
var hasInner = typeof(window.innerWidth) == 'number';   
var hasElement = (document.documentElement && document.documentElement.clientWidth); 
var playerWidth = 680;
var playerHeight = 580;
var videoTitle = ""
var videoPath = "";
var videoShift = "";

var videoList = new Array();
videoList.push({videoTitle:"CEO%20Summit",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/CeoSummit.flv",videoShift:"false"});
videoList.push({videoTitle:"Hurricane%20Management%20System",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/hms.flv",videoShift:"true"});
videoList.push({videoTitle:"United%20Nations%20video",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/demos\/ITU.flv",videoShift:"false"});
videoList.push({videoTitle:"ZapThink%20Podcast",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Videos\/ZapThink.flv",videoShift:"false"});
videoList.push({videoTitle:"Actionable Intelligence Part 1",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/IDVOverview.flv",videoShift:"false"});
videoList.push({videoTitle:"Actionable Intelligence Part 2",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/30minDemo_IDV_Preset.flv",videoShift:"false"});
videoList.push({videoTitle:"Webinar: Location-Based Data Mashups for SharePoint using Visual Fusion Suite&reg;",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/zapthinkwebinar.flv",videoShift:"false"});
videoList.push({videoTitle:"Visual Fusion Suite&reg; Overview",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/videos\/Scott_NoQA.flv",videoShift:"false"});
videoList.push({videoTitle:"A%20Deep%20Dive%20into%20Enterprise%20Location%20Intelligence",videoPath:"rtmp://9l9ymunmbp.rtmphost.com/videos/directionswebinar.flv",videoShift:"false"});


// Write the SWF to the div, or an empty string.
function displayMovie(isOn,vt,vp,vs) {	
	if (isOn) {		
	   var so = new SWFObject("IDV_video_player.swf", "mymovie", String(playerWidth), String(playerHeight), "8", "#EEEEEE");
	   so.addParam("quality", "high");
	   so.addParam("pluginspage", "https://www.macromedia.com/go/getflashplayer");
	   so.addParam("align", "middle");
	   so.addParam("play", "true");
	   so.addParam("loop", "false");
	   so.addParam("scale", "noscale");
	   so.addParam("devicefont", "false");
	   so.addParam("id", "flash-animations");
	   so.addParam("name", "IDVPlayer");
	   so.addParam("menu", "false");
	   so.addParam("allowScriptAccess", "sameDomain");
	   so.addParam("movie", "IDV_video_player");
	   so.addParam("wmode", "transparent");
	   so.addParam("salign", "");
	   so.addParam("FlashVars", "videoTitle=" + vt + "&videoPath=" + vp + "&videoShift=" + vs);
	   so.write("flvPlayer");
   } else {
		document.getElementById("flvPlayer").innerHTML = null;
   }
}

// Turn movie on/off
function showVideo(isVis) {
	
	var theLayer = document.getElementById("flvPlayer");
	var theMatte = document.getElementById("flvPlayerBack");
	
	isVisible = isVis;
	if(isVis) {
		displayMovie(true,videoTitle,videoPath,videoShift);
		doCenterMovie();
		
		MM_effectAppearFade(theLayer, 500, 0, 100, false);
		MM_effectAppearFade(theMatte, 500, 0, 70, false);
	} else {
		MM_effectAppearFade(theLayer, 500, 100, 0, false);
		MM_effectAppearFade(theMatte, 500, 70, 0, false);
		setTimeout(delayedMove,500);
	} 
	
}
// Move movie off screen before dismissing it, so no controls are covered
function delayedMove() {
	
	var theLayer = document.getElementById("flvPlayer");
	var theMatte = document.getElementById("flvPlayerBack");
	theLayer.style.top = "-1000px";
	theLayer.style.left = "-1000px";
	theMatte.style.width = "1%";
	theMatte.style.height = "1%";
	displayMovie(false,null,null,null);
}
// Fade effects
function MM_effectAppearFade(targetElement,dur,from,to,tog) { 	
	Spry.Effect.DoFade(targetElement,{duration:dur,from:from,to:to,toggle:tog});
}
// Center the div/movie on the page
function centerBox(box, width, height)   {   					
	cleft = hasInner   
		? pageXOffset +    
		  (window.innerWidth - width)/2   
		: hasElement   
		  ? document.documentElement.scrollLeft +    
			(document.documentElement.clientWidth - width)/2   
		  : document.body.scrollLeft +    
			(document.body.clientWidth - width)/2;   
  
	ctop = hasInner   
		? pageYOffset + (window.innerHeight - height)/2   
		: hasElement   
		  ? document.documentElement.scrollTop +    
			(document.documentElement.clientHeight - height)/2   
		  : document.body.scrollTop +    
			(document.body.clientHeight - height)/2;   
  
	box.style.left = cleft > 0 ? cleft + 'px' : '0px';   
	box.style.top = ctop > 0 ? ctop + 'px' : '0px';  
	box.style.zIndex = "2000"; 
} 
// Deal with background matte   
function matteBox(box)   {    									
	box.style.height = String(findPosY(document.getElementById("bottomShell")) + 87) + "px";
	box.style.width = String(document.body.clientWidth) + "px";
	box.style.zIndex = "1999"; 
} 
// Find absolute positions of div objects in document.
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
// Check to only center movie if it is visible
function doCenterMovie() {									
	if (isVisible) {
		var theLayer = document.getElementById("flvPlayer");
		centerBox(theLayer, playerWidth, playerHeight);
		var theMatte = document.getElementById("flvPlayerBack");
		matteBox(theMatte);
	}
}
// Interface to show movie.
function selectVideo(v) {
	videoTitle = videoList[v].videoTitle;
	videoPath = videoList[v].videoPath;
	videoShift = videoList[v].videoShift;
	showVideo(true);
}
