// VARs holds path for embedded video player and for player in new browser
// cpod_video_host.html reads query string when page loads and loads an array with the values passed in the query string.
var qsParm = new Array(); // creat the array to hold each name/value pair of passed by parent page.
qsParm['videoPath'] = null; // default values for the array fields in case the page is opened w/o passing arguments.
var swfOpened = false; // set to true 1st time sendURL() is called by the .swf

// THIS CODE BLOCK IS FOR SHOWING-HIDING VIDEO DIV ON A WEB PAGE
function toggleVideo(divID, toggleState, videoPath){
var pre, post;
	
   if (document.getElementById){
      //Netscape 6 and IE6 specific code
      pre = 'document.getElementById("';
	  post = '")'; 
   }
   else if (document.layers){
      //Netscape 4 specific code
      pre = 'document.';
      post = '';
   }
   else if (document.all){
      //IE4+ specific code
      pre = 'document.all.';
      post = '.style';
   }
    // alert(eval(pre + 'detect' + post));
   	var flashDiv = eval(pre + divID + post);
	if(toggleState){ 
		// Reassign videoPath
		qsParm['videoPath'] = videoPath;
		
		// Show div holding flash player
		flashDiv.className = 'show'; 
		
		//IMPORTANT:  When div shows, it dynamically writes embed code and needs time to let .swf load.
		//            So, when .swf 1st opens, at end of flyIn, the .swf calles AS getVideoPath() which calles JS sendURL() below.
		if(swfOpened){
			getMovieName("videoplayer").flyIn();
			//sendURL(); // Explicitly tell opended swf to play current video url.
		}
		
	} 
	else{  
		flashDiv.className = 'hide'; 
	}
}
// THIS CODE BLOCK IS FOR OPENING VIDEO PLAYER IN A NEW BROWSER.
// FUNCTIONS CALLED BY WEB PAGE CONTAINING LINKS TO VIDEOS
// ,,,,,SEND QUERY STRING TO auto_video_player.html & OPEN IT IN NEW BROWSER
function popVideo(absoluteURL){	
	var qs = "http://www.montgomerycollege.edu/departments/cpod/videoplayer/auto_video_player.html?videoPath=" + absoluteURL;
	//+ "&videoSec=" + video_seconds[selection] + "&scriptPath=" + video_transcript[selection];
	videoWin = window.open(qs, 'all',"toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=380,height=345");	
	videoWin.moveTo(200, 180);
}

//**************************************************************************************************
//      NEW BROWSER OPENS:  FUNCTIONS CALLED BY THAT PAHGE AND THE FLASH VIDEO PLAYER ON IT- call to read_qs() at bottom
//*****************************************************************************************************
function read_qs() {
	
var query = window.location.search.substring(1);
var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
			//alert("key = " + key + ",  val = " + qsParm[key]);
		}
	}
}

//********************************************************************
//    WHETHER IN NEW BROWSER OR NOT:.....
//    Calls Actionscript receiveURLs() which receives the arguments
//********************************************************************
function sendURL(){
		//alert("sendURL() sending: " + qsParm['videoPath']);
		swfOpened = true;
		getMovieName("videoplayer").receiveURL(qsParm['videoPath']); 
}
/* This function called by host html and resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {		
	    return window[movieName]
    }
    else {
  	  return document[movieName]
    }
}
// READ THE QUERY STRING
//****** WHEN THIS SCRIPT LOADS IT READS THE QUERY STRING APPENDED TO THE URL
// read_qs(); 
