// Javascript document
// Player
var currThumbnail=0;
var curVideo=0;
function getFlashMovie(movieName) {     
	return document[movieName];  
}
// Player
function MediaSelector(itemDiv, width, height, code, xml, media, mediamac ) {
    if(code == 'video')
        ShowLightBox(itemDiv, width, height, xml, media, mediamac);
    else
        ShowAudioBox(itemDiv, width, height, xml, media);
}
// Lightbox
function ShowAudioBox(itemDiv, width, height, videoxml, audio) {
    // Remove overlapping elements
	var fc = document.getElementById('flashcontent');
	if (fc!=null) fc.style.display = 'none';
	var selectBoxes, i;
    selectBoxes = document.getElementsByTagName('select');
    for (i in selectBoxes) {
        if (selectBoxes[i].style != null) {
            selectBoxes[i].style.position = "absolute";
            selectBoxes[i].style.left = "-1000px";
        }
    }

    var lightBoxDiv = document.getElementById('LightBox');
    lightBoxDiv.style.display = 'block';
    
    lightBoxDiv.style.top = document.documentElement.scrollTop + ((document.documentElement.clientHeight - (height + 24)) / 2) + "px";
    lightBoxDiv.style.left = document.documentElement.scrollLeft + ((document.documentElement.clientWidth - (width + 10)) / 2) + "px";
    
    lightBoxDiv.style.width = width + 10 + "px";
    lightBoxDiv.style.height = height + 24 + "px";
	
	lightBoxDiv.innerHTML = "<a class='LightBoxAnchor' href='" + audio + "'>Download Audio</a><a href='javascript:void(0)' onclick = 'HideLightBox();' style='float:right;color:#FFFFFF;margin-bottom:8px;'><img src='/App_Themes/InstituteBE/Images/Master/close.gif' alt='close'/></a><div id='LightBoxVideo'></div>";
	
	var flashvarsv = {
		xmlUrl: videoxml,
		cssUrl: "/CMSPages/GetCSS.aspx?stylesheetname=IBEFC"
	};
	var paramsv = {
		menu: "false",
		scale: "showAll",
		allowFullscreen: "false",
		allowScriptAccess: "always",
		bgcolor: "#FFFFFF",
		wmode: "transparent"
	};
	var attributesv = {
		id: "C2cDetailVideoPlayer"
	};
	swfobject.embedSWF("/InstituteBE/media/Library/Flash/VideoPlayer/AudioPlayer.swf", "LightBoxVideo", "640", "378", "8.0.0", "expressInstall.swf", flashvarsv, paramsv, attributesv);
	
	
    document.getElementById('BGFade').style.display = 'block';
}
function ShowLightBox(itemDiv, width, height, videoxml, videopc, videomac) {
	// Remove overlapping elements
	var fc = document.getElementById('flashcontent');
	if (fc!=null) fc.style.display = 'none';
	var selectBoxes, i;
    selectBoxes = document.getElementsByTagName('select');
    for (i in selectBoxes) {
        if (selectBoxes[i].style != null) {
            selectBoxes[i].style.position = "absolute";
            selectBoxes[i].style.left = "-1000px";
        }
    }

    var lightBoxDiv = document.getElementById('LightBox');
    lightBoxDiv.style.display = 'block';
    
    lightBoxDiv.style.top = document.documentElement.scrollTop + ((document.documentElement.clientHeight - (height + 24)) / 2) + "px";
    lightBoxDiv.style.left = document.documentElement.scrollLeft + ((document.documentElement.clientWidth - (width + 10)) / 2) + "px";
    
    lightBoxDiv.style.width = width + 10 + "px";
    lightBoxDiv.style.height = height + 24 + "px";
	
	lightBoxDiv.innerHTML = "<a class='LightBoxAnchor' href='" + videopc + "'>Download PC Version</a><a class='LightBoxAnchorCenter' href='" + videomac + "'>Download Mac Version</a><a href='javascript:void(0)' onclick = 'HideLightBox();' style='float:right;color:#FFFFFF;margin-bottom:8px;'><img src='/App_Themes/InstituteBE/Images/Master/close.gif' alt='close'/></a><div id='LightBoxVideo'></div>";
	
	var flashvarsv = {
		xmlUrl: videoxml,
		cssUrl: "/CMSPages/GetCSS.aspx?stylesheetname=IBEFC"
	};
	var paramsv = {
		menu: "false",
		scale: "showAll",
		allowFullscreen: "false",
		allowScriptAccess: "always",
		bgcolor: "#FFFFFF",
		wmode: "transparent"
	};
	var attributesv = {
		id: "C2cDetailVideoPlayer"
	};
	swfobject.embedSWF("/InstituteBE/media/Library/Flash/VideoPlayer/SimpleVideoPlayer.swf", "LightBoxVideo", "640", "378", "8.0.0", "expressInstall.swf", flashvarsv, paramsv, attributesv);
	
	
    document.getElementById('BGFade').style.display = 'block';
}
function HideLightBox() {
	// Restore removed elements
	var fc = document.getElementById('flashcontent');
	if (fc!=null) fc.style.display = 'block';
	var selectBoxes, i;
    selectBoxes = document.getElementsByTagName('select');
    for (i in selectBoxes) {
        if (selectBoxes[i].style != null) {
            selectBoxes[i].style.left = "0px";
            selectBoxes[i].style.position = "";
        }
    }
	
    document.getElementById('LightBox').style.display = 'none';
    document.getElementById('BGFade').style.display = 'none';
	
	var lightBoxDiv = document.getElementById('LightBox');
	if(lightBoxDiv)
		if(lightBoxDiv!=null)
			lightBoxDiv.innerHTML="";
}
// Lightbox

// Thumbnail viewer
function jsLoadVid(vidNum, captionText){
	getFlashMovie("C2cDetailVideoPlayer").jsToAsLoadVideo(vidNum % 4);
	
	var capt = document.getElementById('VideoCaption');
	if(capt){
		if(capt!=null){
			capt.innerHTML = captionText;
		}
	}
	
	try{
		for (i=0;i<=50;i++){
			var mrkrs = document.getElementById('video'+i);
			if(mrkrs){
				if(mrkrs!=null){
					mrkrs.style.display = 'none';
				}
			}
		}
	}catch(err){}
	
	var mrkr = document.getElementById('video'+vidNum);
	if(mrkr){
		if(mrkr!=null){
			mrkr.style.display = 'block';
			curVideo = vidNum;
		}
	}
}
function jsSelectInitialVideo(vidNum, captionText){
	currThumbnail = 0;
	if((vidNum == 0 || vidNum % 4 == 0) && vidNum <=3){
		var mrkr = document.getElementById('video'+vidNum);
		if(mrkr){
			if(mrkr!=null){
				mrkr.style.display = 'block';
			}
		}
		var capt = document.getElementById('VideoCaption');
		if(capt){
			if(capt!=null){
				capt.innerHTML = captionText;
			}
		}
	}
}

function jsAdvanceThumbnail(advLeft){
	if(advLeft){
		if(currThumbnail!=0){
			var prevThumbnail = currThumbnail -1;
			var prv = document.getElementById('thumbnail'+prevThumbnail);
			if(prv){
				if(prv!=null){
					var nextThumbnail = prevThumbnail + 4;
					var nxt = document.getElementById('thumbnail'+nextThumbnail);
					if(nxt){
						if(nxt!=null){
							nxt.style.display = 'none';
							if(curVideo==prevThumbnail){
								var mrkr = document.getElementById('video'+prevThumbnail);
								if(mrkr){
									if(mrkr!=null){
										mrkr.style.display = 'block';
									}
								}
							}
						}
					}
					prv.style.display = 'block';
					prv.parentNode.style.display = 'block';
					currThumbnail = currThumbnail -1;
				}
			}
		}
	}else{ // advance right
		var nextThumbnail = currThumbnail + 4;
		var nxt = document.getElementById('thumbnail'+nextThumbnail);
		if(nxt){
			if(nxt!=null){
				var prv = document.getElementById('thumbnail'+currThumbnail);
				if(prv){
					if(prv!=null){
						prv.style.display = 'none';
						prv.parentNode.style.display = 'none';
						var mrkr = document.getElementById('video'+currThumbnail);
						if(mrkr){
							if(mrkr!=null){
								mrkr.style.display = 'none';
							}
						}
					}
				}
				nxt.style.display = 'block';
				currThumbnail = currThumbnail +1;
			}
		}
	}
}
// Thumbnail viewer
