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 overlay = "";

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"});

var tutorList = new Array(
{videoTitle:"Tooltips%20and%20Details",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/TooltipsandDetails.flv",videoShift:"false"},
{videoTitle:"Navigation%20Usage",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/NavigationUsage.flv",videoShift:"false"},
{videoTitle:"Ad%20Hoc%20Feeds",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/AdHocFeeds.flv",videoShift:"false"},
{videoTitle:"Layer%20Control%20Functionality",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/LayerControlFunctionality.flv",videoShift:"false"},
{videoTitle:"Layer%20Control%20Hierarchy",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/LayerControlHierarchy.flv",videoShift:"false"},
{videoTitle:"Styling%20with%20the%20Layer%20Control",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/StylingwiththeLayerControl.flv",videoShift:"false"},
{videoTitle:"SQL%20Server%20Configuration",videoPath:"rtmp:\/\/9l9ymunmbp.rtmphost.com\/Tutorials\/SQLServerConfiguration.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("/Blog/IDV_video_player.swf", "mymovie", String(playerWidth), String(playerHeight), "8", "#EEEEEE");
	   
	   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("name", "IDV_video_player");
	   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;
   }

}

function displayGraphic(anImage) {
    if (typeof(anImage)=="string") {
	    var iString = "<table><tr align='center'><td style='color: orange; font-weight: bold; font-size: 12px;'><span style='background-color: #666666; padding: 5px;'>CLICK TO CLOSE</span></td></tr><tr><td><a href='javascript:showGraphic(false);'><img id='anImage' src='" + anImage + "'></td></tr></table>"
	    document.getElementById("imagePop").innerHTML = iString;
	    setTimeout(delayShowGraphic,200);
    }
}

function delayShowGraphic() {
    showGraphic(true);
}

function showGraphic(isVis) {
	var theImage = document.getElementById("anImage");
	var theLayer = document.getElementById("imagePop");
	var theMatte = document.getElementById("flvPlayerBack");
	
	isVisible = isVis;
	if(isVis) {
		doCenterGraphic();
		MM_effectAppearFade(theImage, 500, 0, 100, false);
		MM_effectAppearFade(theLayer, 500, 0, 100, false);
		MM_effectAppearFade(theMatte, 500, 0, 70, false);
	} else {
		MM_effectAppearFade(theImage, 500, 100, 0, false);
		MM_effectAppearFade(theLayer, 500, 100, 0, false);
		MM_effectAppearFade(theMatte, 500, 70, 0, false);
		setTimeout(delayedMoveGraphic,500);
	} 
}

function delayedMoveGraphic() {
	
	var theLayer = document.getElementById("imagePop");
	var theMatte = document.getElementById("flvPlayerBack");
	theLayer.style.top = "-1000px";
	theLayer.style.left = "-1000px";
	theMatte.style.width = "1%";
	theMatte.style.height = "1%";

	document.getElementById("imagePop").innerHTML = "";
}
function doCenterGraphic() {
    overlay = "graphic";								
	if (isVisible) {
		var theLayer = document.getElementById("imagePop");
		var theWidth = parseInt(document.getElementById("anImage").width)+80;
		var theHeight = parseInt(document.getElementById("anImage").height)+80;
		
		//sizeWindow();
		
	    

		centerBox(theLayer, theWidth, theHeight);

		var theMatte = document.getElementById("flvPlayerBack");
		theMatte.style.width = String(document.body.clientWidth) + "px";
		theMatte.style.height = String(document.body.clientHeight + 120) + "px";
	}
}

function sizeWindow() {
    var width=window.screen.top;
    var height=window.screen.left;
    //window.moveTo(0,0);
    //window.resize(width,height);
}

// 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("footer")) + 87) + "px";
	box.style.width = String(document.body.clientWidth) + "px";
	box.style.height = String(document.body.clientHeight + 120) + "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() {	
    overlay = "movie";								
	if (isVisible) {
		var theLayer = document.getElementById("flvPlayer");
		centerBox(theLayer, playerWidth, playerHeight);
		var theMatte = document.getElementById("flvPlayerBack");
		matteBox(theMatte);
	}
}
// Interface to show movies.
function selectDemoVideo(v) {
	videoTitle = videoList[v].videoTitle;
	videoPath = videoList[v].videoPath;
	videoShift = videoList[v].videoShift;
	showVideo(true);
}

function selectTutorialVideo(n) {
	videoTitle = tutorList[n].videoTitle;
	videoPath = tutorList[n].videoPath;
	videoShift = tutorList[n].videoShift;
	showVideo(true);
}

function doOverlayCheck() {
    if (overlay=="movie") {
        doCenterMovie();
    } else if (overlay=="graphic") {
        doCenterGraphic();
    }
}
