// video.js - function to play video

function playBrightcoveVideo(id, title, description) {
	
	// Set defaults
	if (typeof title == "undefined") title = "";
	if (typeof description == "undefined") description = "None";
	
	// Stop inline video
	stopInlineVideo();
	
	// Show overlay
	var overlay = document.createElement('div');
	overlay.id = 'overlay';
	overlay.innerHTML = '<div id="overlay-flash"></div>';
	document.body.insertBefore(overlay, document.body.firstChild);
	
	// Show Flash
	var flashvars = new Object();
	flashvars.videoId = id;
	flashvars.name = title;
	flashvars.shortDescription = description;
	var params = {
		allowScriptAccess: "always",
		allowFullScreen: "true",
		quality: "high",
		menu: "false", 
		wmode: "transparent"
	};
	var attributes = {}
	swfobject.embedSWF("/media/flash/video_player.swf", "overlay-flash", "100%", "100%", "9.0.115.0", "expressInstall.swf", flashvars, params, attributes);
	
	// Scroll page to top in IE6
	if (Browser.Engine.trident4) {
		window.scrollTo(0,0);
	}
}

function playCaptivateVideo(id, contentUrl, title, description, w, h) {

	// Set defaults
	if (typeof title == "undefined") title = "";
	if (typeof description == "undefined") description = "None";
	
	// Stop inline video
	stopInlineVideo();
	
	// Show overlay
	var overlay = document.createElement('div');
	overlay.id = 'overlay';
	overlay.innerHTML = '<div id="overlay-flash"></div>';
	document.body.insertBefore(overlay, document.body.firstChild);
	
	// Show Flash
	var flashvars = new Object();
	flashvars.id = id;
	flashvars.contentUrl = contentUrl;
	flashvars.name = title;
	flashvars.shortDescription = description;
	flashvars.width = w;
	flashvars.height = h;
	var params = {
		allowScriptAccess: "always",
		allowFullScreen: "true",
		quality: "high",
		menu: "false", 
		wmode: "transparent"
	};
	var attributes = {}
	swfobject.embedSWF("/media/flash/captivate_player.swf", "overlay-flash", "100%", "100%", "9.0.115.0", "expressInstall.swf", flashvars, params, attributes);
	
	// Scroll page to top in IE6
	if (Browser.Engine.trident4) {
		window.scrollTo(0,0);
	}
}

function closeVideo() {
	
	// Remove overlay
	var flash = document.getElementById('overlay-flash');	
	var overlay = document.getElementById('overlay');
	if (overlay && flash) overlay.removeChild(flash);	
	if (overlay) document.body.removeChild(overlay);	

}

function closeBrightcoveVideo() {
	closeVideo();
}

function stopInlineVideo() {
	var element = document.getElementById("featured-flash");
	if (element) element.stopVideo();
}

function positionVideoDescription(evt) {
	
	// Get mouse cooridinates
    if (!evt) var evt = window.event;
    posx = evt.clientX;
    posy = evt.clientY;
    
    // Position div
	var element = document.getElementById("video-description"); 	
	element.style.left = (posx - 80) + "px";
	element.style.top = (posy + 20) + "px";
}

function showVideoDescription() {
	if (Browser.Engine.trident4) return;
	document.getElementById("video-description").style.visibility = "visible";
}

function hideVideoDescription() {
	if (Browser.Engine.trident4) return;
	document.getElementById("video-description").style.visibility = "hidden";
}

function setVideoDescription(title, description) {
	if (Browser.Engine.trident4) return;

	// Reload Flash with new text
	var flashvars = new Object();
	flashvars.title = title;
	flashvars.description = description;
	var params = {
		allowScriptAccess: "always",
		quality: "high",
		menu: "false", 
		wmode: "transparent"
	};
	var attributes = {}
	swfobject.embedSWF("/media/flash/video_description.swf", "video-description", "160", "200", "9.0.115.0", "expressInstall.swf", flashvars, params, attributes);
}

function initVideoDescription() {
	if (Browser.Engine.trident4) return;
	if (document.body.addEventListener) document.body.addEventListener("mousemove", positionVideoDescription, false);
	else document.body.onmousemove = positionVideoDescription;
}

