﻿/* * QTObject embed * http://blog.deconcept.com/2005/01/26/web-standards-compliant-javascript-quicktime-detect-and-embed/ * * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/) * * v1.0.2 - 02-16-2005 * * Embeds a quicktime movie to the page, includes plugin detection * * Usage: * *	myQTObject = new QTObject("path/to/mov.mov", "movid", "width", "height"); *	myQTObject.altTxt = "Upgrade your Quicktime Player!";    // optional  *  myQTObject.addParam("controller", "false");              // optional *	myQTObject.write(); * */QTObject = function(mov, id, w, h) {	this.mov = mov;	this.id = id;	this.width = w;	this.height = h;	this.redirect = "";	this.sq = document.location.search.split("?")[1] || "";	this.altTxt = "This content requires the QuickTime Plugin. <a href='http://www.apple.com/quicktime/download/'>Download QuickTime Player</a>.";	this.bypassTxt = "<p>Already have QuickTime Player? <a href='?detectqt=false&"+ this.sq +"'>Click here.</a></p>";	this.params = new Object();	this.doDetect = getQueryParamValue('detectqt');}QTObject.prototype.addParam = function(name, value) {	this.params[name] = value;}QTObject.prototype.getParams = function() {    return this.params;}QTObject.prototype.getParam = function(name) {    return this.params[name];}QTObject.prototype.getParamTags = function() {    var paramTags = "";    for (var param in this.getParams()) {        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';    }    if (paramTags == "") {        paramTags = null;    }    return paramTags;}QTObject.prototype.getHTML = function() {    var qtHTML = "";	if (navigator.plugins && navigator.plugins.length) { // not ie        qtHTML += '<embed type="video/quicktime" src="' + this.mov + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '"';        for (var param in this.getParams()) {            qtHTML += ' ' + param + '="' + this.getParam(param) + '"';        }        qtHTML += '></embed>';    }    else { // pc ie        qtHTML += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';        this.addParam("src", this.mov);        if (this.getParamTags() != null) {            qtHTML += this.getParamTags();        }        qtHTML += '</object>';    }    return qtHTML;}QTObject.prototype.getVariablePairs = function() {    var variablePairs = new Array();    for (var name in this.getVariables()) {        variablePairs.push(name + "=" + escape(this.getVariable(name)));    }    if (variablePairs.length > 0) {        return variablePairs.join("&");    }    else {        return null;    }}QTObject.prototype.write = function(elementId) {	if(isQTInstalled() || this.doDetect=='false') {		if (elementId) {			document.getElementById(elementId).innerHTML = this.getHTML();		} else {			document.write(this.getHTML());		}	} else {		if (this.redirect != "") {			document.location.replace(this.redirect);		} else {			if (elementId) {				document.getElementById(elementId).innerHTML = "<a href='http://www.apple.com/quicktime/download/'><img src='http://www.rhedpixel.com/images/misc/noQT.jpg' width='320' height='240' alt='You do not have QuickTime installed'></a>";			} else {				document.write("<a href='http://www.apple.com/quicktime/download/'><img src='http://www.rhedpixel.com/images/misc/noQT.jpg' width='320' height='240' alt='You do not have QuickTime installed'></a>");			}		}	}		}function isQTInstalled() {	var qtInstalled = false;	qtObj = false;	if (navigator.plugins && navigator.plugins.length) {		for (var i=0; i < navigator.plugins.length; i++ ) {         var plugin = navigator.plugins[i];         if (plugin.name.indexOf("QuickTime") > -1) {			qtInstalled = true;         }      }	} else {		execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))','VBScript');		qtInstalled = qtObj;	}	return qtInstalled;}/* get value of querystring param */function getQueryParamValue(param) {	var q = document.location.search;	var detectIndex = q.indexOf(param);	var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;	if(q.length > 1 && detectIndex != -1) {		return q.substring(q.indexOf("=", detectIndex)+1, endIndex);	} else {		return "";	}}function showQuickTime(ext) {	var type = "mp4";		if (ext == undefined)		type = "mov";	// get 1st and 2nd level directory from window.location	var theURL = window.location.href;   // http://www.rhedpixel.com/thework/category/piece.html	var temp = theURL.substring(0, theURL.lastIndexOf("/"));  // http://www.rhedpixel.com/thework/category	var d1 = temp.substring(temp.lastIndexOf("/")+1);  // category	d2 = theURL.substring(theURL.lastIndexOf("/")+1, theURL.lastIndexOf("."));  // piece	//alert("d1: " + d1 + "  d2: " + d2);		// ../..video/commercials/01_arc_tsunami/01_arc_tsunami.mov	var myQTObject = new QTObject("../../video/" + d1 + "/" + d2 + "/" + d2 + "." + type, d2, "320", "256");	myQTObject.addParam("target", "myself");	myQTObject.addParam("controller", "true");	myQTObject.addParam("bgcolor","#2b2b2b");	myQTObject.write("movie");}function showQTVR(w1,h1) {	var w = Math.floor(w1);  // need to convert to number or browser will act up	var h = Math.floor(h1);	// get 1st and 2nd level directory from window.location	var theURL = window.location.href;   // http://www.rhedpixel.com/thework/category/piece.html	var temp = theURL.substring(0, theURL.lastIndexOf("/"));  // http://www.rhedpixel.com/thework/category	var d1 = temp.substring(temp.lastIndexOf("/")+1);  // category	d2 = theURL.substring(theURL.lastIndexOf("/")+1, theURL.lastIndexOf("."));  // piece		var myQTObject = new QTObject("../../video/" + d1 + "/" + d2 + "/" + d2 + ".mov", d2, w, h+16);	myQTObject.addParam("target", "myself");	myQTObject.addParam("controller", "true");	myQTObject.write("movie");		// show body copy	//showLayer(file);}/*******************************************************WINDOWS MEDIA DETECTAll code by Ryan Parman, unless otherwise noted.(c) 1997-2003, Ryan Parmanhttp://www.skyzyx.comDistributed according to SkyGPL 2.1, http://www.skyzyx.com/license/*******************************************************/var windowsmedia=new Object();// Set some base valueswindowsmedia.installed=false;windowsmedia.flip4mac = false; // flip4mac installedwindowsmedia.version='0.0'; // Internet Explorer-only// Check for GeckoActiveXObject and co-inciding Plug-Invar gkoaxwma=false;if (navigator.plugins && navigator.plugins.length) { for (x=0; x<navigator.plugins.length; x++) { if (navigator.plugins[x].name.indexOf('ActiveX') != -1 && window.GeckoActiveXObject) { gkoaxwma=true; break; } } }// Create an ActiveX/GeckoActiveX constructorfunction AXO(id){	var error; var control = null;	try {		if (window.ActiveXObject && navigator.userAgent.indexOf('Win') != -1) control = new ActiveXObject(id);		else if (gkoaxwma) control = new GeckoActiveXObject(id);	}	catch (error) {}	return control;}if (window.ActiveXObject || gkoaxwma){	try	{		oWMP=new AXO('WMPlayer.OCX.7');		if (oWMP)		{			windowsmedia.installed=true;			// A wierd bug in the Gecko ActiveX plug-in will return			// undefined at the first call, but the correct value on the second.			// This "fix" doesn't seem to hurt IE at all.			parseFloat(oWMP.versionInfo);			windowsmedia.version=parseFloat(oWMP.versionInfo);			if (windowsmedia.version.toString().length == 1) windowsmedia.version+='.0';		}	}	catch(e) {}}else if (navigator.plugins && navigator.plugins.length){	for (x=0; x<navigator.plugins.length; x++)	{		if (navigator.plugins[x].name.indexOf('Windows Media') != -1) {			windowsmedia.installed = true;		}		if (navigator.plugins[x].name.indexOf('Flip4Mac') != -1) { // detect flip4mac on Macintosh platform			windowsmedia.flip4mac = true;		}	break;	}	// if on a Mac and WMP & F4M not found try checking mimeType. This is Microsoft's proposed solution.	if (navigator.userAgent.indexOf('Mac') != -1 && !windowsmedia.installed && !windowsmedia.flip4mac) {		var fHasWMP = navigator.mimeTypes 			&& navigator.mimeTypes["application/x-mplayer2"]			&& navigator.mimeTypes["application/x-mplayer2"].enabledPlugin;		if (fHasWMP) { // mac user has WMP installed			windowsmedia.installed = true;		}	}}// Internet Explorer or GeckoActiveXObject-compatible browsers only.windowsmedia.ver7=(windowsmedia.installed && parseInt(windowsmedia.version) >= 7) ? true:false;windowsmedia.ver8=(windowsmedia.installed && parseInt(windowsmedia.version) >= 8) ? true:false;windowsmedia.ver9=(windowsmedia.installed && parseInt(windowsmedia.version) >= 9) ? true:false;function showWindowsMedia() {	var elementId = "movie";	// get 1st and 2nd level directory from window.location	var theURL = window.location.href;   // http://www.rhedpixel.com/thework/category/piece.html	var temp = theURL.substring(0, theURL.lastIndexOf("/"));  // http://www.rhedpixel.com/thework/category	var d1 = temp.substring(temp.lastIndexOf("/")+1);  // category	d2 = theURL.substring(theURL.lastIndexOf("/")+1, theURL.lastIndexOf("."));  // piece	//alert("d1: " + d1 + "  d2: " + d2);		var thefile = "<embed src='../../video/" + d1 + "/" + d2 + "/" + d2 + ".wmv' width='320' height='256' autostart='true'></embed>";	if(windowsmedia.installed || windowsmedia.flip4mac) {		if (elementId) {			document.getElementById(elementId).innerHTML = thefile;		} else {			document.write(thefile);		}	} else {		if (elementId) {			document.getElementById(elementId).innerHTML = "<a href='http://www.windowsmediaplayer.com'><img src='http://www.rhedpixel.com/images/misc/noWMV.jpg' width='320' height='240' alt='You do not have Windows Media Player installed'></a>";		} else {			document.write("<a href='http://www.windowsmediaplayer.com'><img src='http://www.rhedpixel.com/images/misc/noWMV.jpg' width='320' height='240' alt='You do not have Windows Media Player installed'></a>");		}	}		}