


//			 ============================================================================================
//			
//			    subroutines : Common Javascript code for core functions
//			
//			
//			
//			    Created at the KSU Educational Communications Center
//			
//			    David Noel Pedergnana, Multimedia Designer
//			
//			    www.ksu.edu/ecc       *       dnp@ksu.edu
//			
//			    © MMVII D.N.B. Pedergnana
//			    
//			 ============================================================================================

var popup;
var popup2;
var popup3;
var videoPopup;

function getObjectByID(name) {				// Get an object's ID tag for easy referencing

	if (document.getElementById) {				// Firefox and Safari
		return document.getElementById(name);
	} else if (document.all) {					// IE
		return document.all[name]; 
	} else if (document.layers) {
		return document.layers[name];
	} else {
		return document.getElementById(name);		// Default for unknown browsers
	}
}

function parseURL() {					// Reads a frame's URL queryString and splits it into its components; then
							// 	returns an associative array containing all parameter(s)
	var result = new Array();
	var paramList = new Array();
	var nameAndValue = new Array();

	var queryString = location.href.split("?");		// GET Parameters

	if (queryString.length > 1) {			// Parameters exist; parse the queryString:

				// Split list into name.value pairs

		var hashPairs = queryString[1].split("&");
		var paramValue;
		var paramKey;

		for (p=0; p < hashPairs.length; p++) {	// Cycle through name/value pairs & store values

			nameAndValue = hashPairs[p].split("=");
			paramKey = nameAndValue[0];
			paramValue = nameAndValue[1];

			result[paramKey] = paramValue;
		}
		return result;

	}
}

function embedQT() {				// Shows the activeX control without an annoying 'activate' prompt

	var paramList = parseURL();

	var videoFile = paramList['video'];
	var w = paramList['w'];
	var h = paramList['h'];

	getObjectByID('header').innerHTML = unescape(videoFile);

	if (videoFile) {
		videoFile = 'video/' + videoFile + '.mov';

	var embedCode = "    <object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='" + w + "' "
		+ "	height='" + h + "' codebase='http://www.apple.com/qtactivex/qtplugin.cab' align='middle'>"
              + "        <param name='QTSRCDONTUSEBROWSER' value='true'>"
              + "        <param name='SCALE' value='tofit'>"
              + "        <param name='SRC' value='" + videoFile + "'>"
              + "        <param name='AUTOPLAY' value='true'>"
              + "        <param name='CONTROLLER' value='true'>"
              + "        <param name='KIOSKMODE' value='true'>"
              + "        <param name='BGCOLOR' value='#000000'>"
              + "        <embed qtsrcdontusebrowser='true' src='" + videoFile + "'"
		+ " scale='tofit' width='" + w + "' height='" + h + "' autoplay='true' "
		+ " controller='true' kioskmode='true'"
		+ " bgcolor='#000000' pluginspage='http://www.apple.com/quicktime/download/' align='middle'>"
              + "        </embed>"
              + "      </object>";

	document.write(embedCode);
	}
}

function getHandouts () {				// Parses the query string into a list of handouts, then displays them
							//	Format the argument list as follows: label, filename, label, filename...
	var paramList = parseURL();
	var handoutList = paramList['handouts'].split(",");

	linkCode =  "<ul>";
	var thisFile;

	for (n = 0; n < handoutList.length; n++) {	// Cycle through each handout and display a link

		label = handoutList[n];
		file = 'handouts/' + handoutList[n++] + '.pdf';

		linkCode += "<li>";
		linkCode += "<a href=\"javascript: openDoc('" + file + "', 776, 540);\">";
		linkCode += unescape(label);
		linkCode += "</a></li>\n";
	}

	linkCode += "</ul>";

	getObjectByID('handouts').innerHTML = linkCode;
}


function openDoc(file, w, h, resizable) {		// Opens a document of specified dimensions in a separate pop-up window
												//		Resizable is a boolean value ("yes" or "no")
	if(popup) {
		popup.close();
	}

	if (!resizable) {
		var resizable = 'yes';
	}

	popup = window.open(file, 'popUpWindow', 'height=' +h+ ', width=' +w+ ', scrollbars=' + resizable +', resizable=' + resizable);
}


function openWin(file, w, h) {		// Opens a document of specified dimensions in a separate pop-up window
												//		Resizable is a boolean value ("yes" or "no")
	if(popup2) {
		popup2.close();
	}

	popup2 = window.open(file, 'popUpWindow2', 'height=' +h+ ', width=' +w+ ', scrollbars=yes, resizable=yes, toolbar=yes');
}



function openVideo(file, w, h) {		// Opens a QuickTime video of specified dimensions in a separate pop-up window

	if ( file.match(/assets-/) ) {				// Adjust START.html path names
		file = file.replace(/assets-/, "");
		queryString = 'assets/videoPlayer.html?video=' + file + '&w=' + w + '&h=' + h;
	} else {
		queryString = 'videoPlayer.html?video=' + file + '&w=' + w + '&h=' + h;
	}

	if(videoPopup) {
		videoPopup.close();
	}

		// Offset video window dimensions

	
	w = w + 36;
	h = h + 103;

	videoPopup = window.open(queryString, 'videoWindow', 'height=' +h+ ', width=' +w+ ', scrollbars=no, resizeable=no');
}

function openFlash(file, w, h) {
	
	queryString = 'video/flashPlayer.html?w=' + w + '&h=' + h + '&file=' + file;

	if(videoPopup) {
		videoPopup.close();
	}
	
	w = w + 36;
	h = h + 82;

	videoPopup = window.open(queryString, 'videoWindow', 'height=' +h+ ', width=' +w+ ', scrollbars=no, resizeable=no');

}
	
	


function openDoc1(file, w, h, resizable) {		// Opens a document of specified dimensions in a separate pop-up window
												//		Resizable is a boolean value ("yes" or "no")
	if(popup3) {
		popup3.close();
	}

	if (!resizable) {
		var resizable = 'yes';
	}

	popup3 = window.open(file, 'popUpWindow3', 'height=' +h+ ', width=' +w+ ', scrollbars=' + resizable +', resizable=' + resizable);
}

