/* following block of code from internet to detect browser and OS */
/* Note may want to use platform and other variables in newer versions of javascript */
var detect, OS, browser;
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	return place;
}
function setBrowserAndOS() {
	detect = navigator.userAgent.toLowerCase();
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari";
	else if (checkIt('omniweb')) browser = "OmniWeb";
	else if (checkIt('opera')) browser = "Opera";
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab";
	else if (checkIt('msie')) browser = "IE";
	else if (checkIt('firefox')) browser = "Firefox";
	else if (checkIt('mozilla')) browser = "Mozilla";
	else browser = "Unknown";
	if (!OS) {
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('os x')) OS = "OSX";
		else if (checkIt('mac')) OS = "Mac";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('win')) OS = "Windows";
		else OS = "Unknown";
	}
}
/* end of browser and OS detect code */

function loadMediaPlayer(baseMediaWidth, mediaEmbedHeight, tmpMediaReference) {
	var mediaDiv = document.getElementById('media_div');
	var node;
	setBrowserAndOS();
	if (OS == 'Windows' || OS == 'OSX') {
		// should work if user has QuickTime installed
		node = document.createElement("EMBED");
		node.setAttribute('SRC', "/empty.mov");
		node.setAttribute('WIDTH', baseMediaWidth);
		node.setAttribute('HEIGHT', mediaEmbedHeight);
		node.setAttribute('QTSRC', tmpMediaReference + '.smil');
		node.setAttribute('PLUGINSPAGE','http://www.apple.com/quicktime/download/');
	} else {
		// pass back SMIL reference w/o QuickTime force via empty.mov; probably won't work
		node = document.createElement("EMBED");
		node.setAttribute('SRC', tmpMediaReference + '.smil');
		node.setAttribute('WIDTH', baseMediaWidth);
		node.setAttribute('HEIGHT', mediaEmbedHeight);
	}
	mediaDiv.appendChild(node);
}

function goToURL(url) { 
	if (window.top == null) 
		window.location = url;
	else
		window.top.location = url;
	return false;
}

function mediaRequestNewPage(name, action, ss, sf, off, title) {
	var mediaUrl = '/mediaRequestNewPage.php?name=' + name + '&title=' + title;
	if (action == 'view')
		mediaUrl += '&action=view&sf=' + sf + '&off=' + off;
	else
		mediaUrl += '&action=listen&ss=' + ss;
	return goToURL(mediaUrl);
}

function mediaRequest(name, action, ss, sf, off, id, title) {
	setBrowserAndOS();
	if (browser == 'Firefox' || browser == 'Mozilla') {
		var mediaUrl = '/transcripts/' + name + '.php?title=' + title;
		if (action == 'view')
			mediaUrl += '&action=view&sf=' + sf + '&off=' + off;
		else
			mediaUrl += '&action=listen&ss=' + ss;
		if (id.length > 0)
			mediaUrl += '&id=' + id;
		return goToURL(mediaUrl);
	} else {
		return mediaRequestNewPage(name, action, ss, sf, off, title);
	}
}