var currentVid = "";
var currentID = "sw-popPlayer1";
var embedIndex = 1;

function $(n){return document.getElementById(n);}


function showVodCFW(vidToPlay){
	
	showGrayOverlay();
	ColdFusion.Window.show('video');
	
	if(vidToPlay != currentVid){	
		//if its the first one, just embed it
		if(embedIndex == 1){
			embedVodPlayer(vidToPlay);
			embedIndex += 1;
			
		}else{			
			swfobject.removeSWF(currentID);
			
			currentID = "popPlayer"+embedIndex;
					
			var newdiv = document.createElement('div');
   			newdiv.setAttribute('id', 'sw-vidPlayer');
			$('sw-vidPlayContainer').appendChild(newdiv);
			
			embedVodPlayer(vidToPlay);
			embedIndex += 1;
		}
		currentVid = vidToPlay;
	}
	
}


function embedVodPlayer(vidPath){
	var attributes = {};
	attributes.id = currentID;
	attributes.name = currentID;
	attributes.allowFullScreen = "true";
	var params = {};
	params.allowFullScreen = "true";
	params.wmode = "transparent";
	params.allowscriptaccess = "always";
	var flashvars = {};
	flashvars.vidFile = vidPath;
	swfobject.embedSWF("vod/popPlayerFullscreen.swf", "sw-vidPlayer", "100%", "100%", "9", false, flashvars, params, attributes);	
	

	
}
	
	

function hideVodCFW(){
	ColdFusion.Window.hide('video');
	hideGrayOverlay();
}

function hideGrayOverlay(){
	$('darkenScreenObject').style.display='none';
}

function showGrayOverlay() {
	var opacity = 40;
	var opaque = (opacity / 100);		
	var zindex = 4999;
	var grayBG = $('darkenScreenObject'); 			
	
	// Calculate the page width and height 
	if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
		var pageWidth = document.body.scrollWidth+'px';
		var pageHeight = document.body.scrollHeight+'px';
	} else if( document.body.offsetWidth ) {
	  var pageWidth = document.body.offsetWidth+'px';
	  var pageHeight = document.body.offsetHeight+'px';
	} else {
	   var pageWidth='100%';
	   var pageHeight='100%';
	}
	
	//set the shader to cover the entire page and make it visible.
	grayBG.style.opacity=opaque;                      
	grayBG.style.MozOpacity=opaque;                   
	grayBG.style.filter='alpha(opacity='+opacity+')';
	grayBG.style.zIndex=zindex;        
	grayBG.style.width= pageWidth;
	grayBG.style.height= pageHeight;
	grayBG.style.display='block';
}

getViewportHeight=function(){var height = 0;if( document.documentElement && document.documentElement.clientHeight ) {height = document.documentElement.clientHeight;} else if( document.body && document.body.clientHeight ) {height = document.body.clientHeight;}else if( window.innerHeight ) {height = window.innerHeight - 18;}return height;};
getViewportScrollY=function(){var scrollY = 0;if( document.documentElement && document.documentElement.scrollTop ) {scrollY = document.documentElement.scrollTop;}else if( document.body && document.body.scrollTop ) {scrollY = document.body.scrollTop;}else if( window.pageYOffset ) {scrollY = window.pageYOffset;}else if( window.scrollY ) {scrollY = window.scrollY;}return scrollY;};
