//This script detects the following:
//Flash
//Windows Media Player
//Java
//Shockwave
//RealPlayer
//QuickTime
//Acrobat Reader
//SVG Viewer

var pluginlist;
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")


// show / hide video controls when user hovers over video
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}



// serve correct media player depending on options in fundraising.php page
function InsertMedia(plugin, media, showcontrols)
{
	if (plugin == 'QuickTime') {
		// controlled via javascript - see http://developer.apple.com/mac/library/documentation/QuickTime/Conceptual/QTScripting_JavaScript/aQTScripting_Javascro_AIntro/Introduction%20to%20JavaScript%20QT.html
		// firefox doesn't work with the wmode = transparent feature so cant have overlay :(
		
		
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrols\'); return true;\" onmouseout=\"HideContent(\'hovercontrols\'); return true;\" id="mouseover">');		
		document.write ('<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" HEIGHT=110 WIDTH=170 CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" id=\"movie1\"><PARAM NAME=\"src\" VALUE=\"video/' + media + '.mov\"><PARAM NAME = \"wmode\" VALUE=\"transparent\"><PARAM NAME=\"SHOWLOGO\" VALUE=\"false\"><param name=\"controller\" value=\"false\"><PARAM NAME=\"autoplay\" VALUE=\"false\"><EMBED HEIGHT=110 WIDTH=170 PLUGINSPAGE=\"http://www.apple.com/quicktime/download/\" SRC=\"/video/' + media + '.mov\" AUTOPLAY=\"false\" controller=\"false\" wmode=\"transparent\" SHOWLOGO=\"false\" EnableJavaScript=\"true\" name=\"movie1\"></EMBED></OBJECT></div>');
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrols\'); return true;\" onmouseout=\"HideContent(\'hovercontrols\'); return true;\" id=\"hovercontrols\"><a href=\"javascript:document.movie1.Play();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-play.png\" class=\"first\" /></a>');
		document.write ('<a href=\"javascript:document.movie1.Stop();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-pause.png\" /></a></div>');
		if (showcontrols == 'true') ShowContent('hovercontrols');
	}

	// firefox can't handle transparent video with layer over top so show controls under :(
	if (plugin == 'QuickTimeFF') {
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\" id="mouseover">');		
		document.write ('<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" HEIGHT=110 WIDTH=170 CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" id=\"movie1\"><PARAM NAME=\"src\" VALUE=\"video/' + media + '.mov\"><PARAM NAME=\"SHOWLOGO\" VALUE=\"false\"><param name=\"controller\" value=\"false\"><PARAM NAME=\"autoplay\" VALUE=\"false\"><EMBED HEIGHT=110 WIDTH=170 PLUGINSPAGE=\"http://www.apple.com/quicktime/download/\" SRC=\"/video/' + media + '.mov\" AUTOPLAY=\"false\" controller=\"false\" SHOWLOGO=\"false\" EnableJavaScript=\"true\" name=\"movie1\"></EMBED></OBJECT></div>');
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\" id=\"hovercontrolsunder\"><a href=\"javascript:document.movie1.Play();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-play.png\" class=\"first\" /></a>');
		document.write ('<a href=\"javascript:document.movie1.Stop();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-pause.png\" /></a></div>');
		if (showcontrols == 'true') ShowContent('hovercontrolsunder');		
	}
	
	if (plugin == 'WindowsMediaPlayer') {
		document.write ('<span onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\" id="mouseover">');		
		document.write ('<OBJECT WIDTH=\"170\" HEIGHT=\"110\" CLASSID=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" STANDBY=\"Loading Windows Media Player components...\" TYPE=\"application/x-oleobject\" id=\"movie1\"><PARAM NAME=\"FileName\" VALUE=\"video/' + media + '.mpg\"><PARAM name=\"autostart\" VALUE=\"false\"><PARAM name=\"ShowControls\" VALUE=\"false\"><param name=\"ShowStatusBar\" value=\"false\"><PARAM name=\"ShowDisplay\" VALUE=\"false\"><EMBED TYPE=\"application/x-mplayer2\" SRC=\"video/' + media + '.mpg\" WIDTH=\"170\" HEIGHT=\"110\" ShowControls=\"0\" ShowStatusBar=\"0\" ShowDisplay=\"0\" autostart=\"0\" EnableJavaScript=\"true\" name=\"movie1\"></EMBED></OBJECT></span>');
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\" id=\"hovercontrolsunder\"><a href=\"javascript:document.movie1.Play();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-play.png\" class=\"first\" /></a>');
		document.write ('<a href=\"javascript:document.movie1.Stop();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-pause.png\" /></a></div>');	
		if (showcontrols == 'true') ShowContent('hovercontrolsunder');
	}
	if (plugin == 'RealPlayer') {
		document.write ('<span onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\">');	
		document.write ('<OBJECT CLASSID=\"CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" HEIGHT=\"110\" WIDTH=\"170\" id=\"movie1\"><PARAM NAME=\"controls\" VALUE=\"ImageWindow\"><PARAM NAME=\"console\" VALUE=\"one\"><PARAM NAME = \"wmode\" VALUE=\"transparent\"><PARAM NAME = \"nologo\" VALUE=\"true\"><PARAM NAME=\"AUTOSTART\" VALUE=\"false\"><PARAM NAME=\"src\" VALUE=\"video/' + media + '.rpm\"><EMBED SRC=\"video/' + media + '.rpm\" type=\"audio/x-pn-realaudio-plugin\" CONTROLS=\"ImageWindow\" CONSOLE=\"Clip1\" NOLOGO=\"true\" wmode=\"transparent\" HEIGHT=110 WIDTH=170 AUTOSTART=\"false\" EnableJavaScript=\"true\" name=\"movie1\"></EMBED></OBJECT></span>');
		document.write ('<div onmouseover=\"ShowContent(\'hovercontrolsunder\'); return true;\" onmouseout=\"HideContent(\'hovercontrolsunder\'); return true;\" id=\"hovercontrolsunder\"><a href=\"#\" onclick=\"document.movie1.DoPlay();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-play.png\" class=\"first\" /></a>');
		document.write ('<a href=\"#\" onclick=\"document.movie1.DoPause();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-pause.png\" /></a></div>');
		if (showcontrols == 'true') ShowContent('hovercontrolsunder');
	}
	if (plugin == 'RealPlayerSafari') {
		document.write ('<OBJECT CLASSID=\"CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" HEIGHT=\"110\" WIDTH=\"170\" id=\"movie1\"><PARAM NAME=\"controls\" VALUE=\"ImageWindow\"><PARAM NAME=\"console\" VALUE=\"one\"><PARAM NAME = \"wmode\" VALUE=\"transparent\"><PARAM NAME = \"nologo\" VALUE=\"true\"><PARAM NAME=\"AUTOSTART\" VALUE=\"false\"><PARAM NAME=\"src\" VALUE=\"video/' + media + '.rpm\"><EMBED SRC=\"video/' + media + '.rpm\" type=\"audio/x-pn-realaudio-plugin\" CONTROLS=\"ImageWindow\" CONSOLE=\"Clip1\" NOLOGO=\"true\" wmode=\"transparent\" HEIGHT=110 WIDTH=170 AUTOSTART=\"false\" EnableJavaScript=\"true\" name=\"movie1\"></EMBED></OBJECT>');
		document.write ('<div id=\"hovercontrolsunder\" class=\"alwaysshowcontrols\"><a href=\"#\" onclick=\"document.movie1.DoPlay();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-play.png\" class=\"first\" /></a>');
		document.write ('<a href=\"#\" onclick=\"document.movie1.DoPause();\"><img width=\"9\" height=\"8\" src=\"/images/buttons/player-pause.png\" /></a></div>');
	}
	if (plugin == 'Text') {
		document.write (media);
	}	
}


//http://techpatterns.com/downloads/javascript_browser_detection.php
function getBrowser() {
	
	var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op, browser;

	d = document;
	n = navigator;
	na = n.appVersion;
	nua = n.userAgent;
	win = ( na.indexOf( 'Win' ) != -1 );
	mac = ( na.indexOf( 'Mac' ) != -1 );
	lin = ( nua.indexOf( 'Linux' ) != -1 );
	browser = "none";
	
	if ( !d.layers ){
		dom = ( d.getElementById );
		if ( nua.indexOf( 'Opera' ) != -1 ) browser = "Opera";
		if ( nua.indexOf( 'Konqueror' ) != -1 ) browser = "Konqueror";
		if ( nua.indexOf( 'Safari' ) != -1) browser = "Safari";
		if ( nua.indexOf( 'Firefox' ) != -1 ) browser = "Firefox";
		if ( nua.indexOf( 'IE' ) != -1 ) browser = "IE";
		if ( mac ) browser = "Mac";
		ie = ( d.all && !op );
		ie4 = ( ie && !dom );
	
		/*
		ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
		Opera will register true in this test if set to identify as IE 5
		*/
	
		ie5x = ( d.all && dom );
		ie5mac = ( mac && ie5x );
		ie5xwin = ( win && ie5x );
	}
	return browser;
}
