//*********************************
// POPOUT VIDEO
//*********************************
// load swfobject code
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '_js/swfobject.js';
document.getElementsByTagName('head')[0].appendChild(script);  

// add popout video
// videoLocation can be "bottomLeft", "bottomRight" or the id of an element that the video will be placed above, by default the video is aligned with the element at the top left corner, though it can be offset using the videoOffsetX and videoOffsetY parameters
function flashPopout(swfPath, videoName, videoWidth, videoHeight, closeLocation, videoLocation, closeOffsetX, closeOffsetY, videoOffsetX, videoOffsetY, callbackFn) {
	// create empty video div
	var videoDiv = document.createElement('div');
	videoDiv.setAttribute('id','popoutVideo'); 
	document.body.appendChild(videoDiv); 
	// insert video into video div	
	if (closeOffsetX == undefined) {
		closeOffsetX = 0;	
	}
	if (closeOffsetY == undefined) {
		closeOffsetY = 0;	
	}
	var flashvars = {myVideoName:videoName, myVideoWidth:videoWidth, myVideoHeight:videoHeight, myCloseLocation:closeLocation, myCloseOffsetX:closeOffsetX, myCloseOffsetY:closeOffsetY, myCallbackFn:callbackFn};
	var params = {wmode: "transparent", scale: "exactfit"};
	var attributes;
	if (videoLocation == 'bottomLeft') {
		attributes = {style:"position:fixed; bottom:0px; left:0px; width:"+videoWidth+"px; height:"+videoHeight+"px; z-index:1"};
	} else {
		if (videoLocation == 'bottomRight') {
			attributes = {style:"position:fixed; bottom:0px; right:0px; width:"+videoWidth+"px; height:"+videoHeight+"px; z-index:1"};
		} else {
			if (videoLocation == 'topLeft') {
				attributes = {style:"position:fixed; top:0px; left:0px; width:"+videoWidth+"px; height:"+videoHeight+"px; z-index:1"};
			} else {
				if (videoLocation == 'topRight') {
					attributes = {style:"position:fixed; top:0px; right:0px; width:"+videoWidth+"px; height:"+videoHeight+"px; z-index:1"};
				} else {
					if (videoOffsetX == undefined) {
						videoOffsetX = 0;	
					}
					if (videoOffsetY == undefined) {
						videoOffsetY = 0;	
					}
					attributes = {style:"position:absolute; top:"+(getTopOffset(videoLocation)+videoOffsetY)+"px; left:"+(getLeftOffset(videoLocation)+videoOffsetX)+"px; width:"+videoWidth+"px; height:"+videoHeight+"px; z-index:1"};
				}
			}		
		}
	}
	var swfFolder = swfPath.split("popoutVideo.swf");
	swfobject.embedSWF(swfPath, "popoutVideo", videoWidth, videoHeight, "9.0.115", swfFolder[0]+"expressInstall.swf", flashvars, params, attributes);
}

// remove video div
function removeFlashPopout() {
	var videoDiv = document.getElementById('popoutVideo');
	document.body.removeChild(videoDiv);
}

// get left offset
function getLeftOffset(elementID) {
	var el = document.getElementById(elementID);
	var pL = 0;
	while(el){
		pL += el.offsetLeft;
		el = el.offsetParent;
	}
	return pL;
}

// get top offset
function getTopOffset(elementID) {
	var el = document.getElementById(elementID);
	var pT = 0;
	while(el){
		pT += el.offsetTop;
		el = el.offsetParent;
	}
	return pT;
}
