// JavaScript Document
/*
2 * FlashObject embed
3 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
4 *
5 * v1.1.0 - 03-31-2005
6 *
7 * writes the embed code for a flash movie, includes plugin detection
8 *
9 * Usage:
10 *
11 * myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
12 * myFlash.write("objId");
13 *
14 * for best practices, see:
15 * http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
16 *
17 */
18
19var FlashObject = function(swf, id, w, h, ver, c) {
20 this.swf = swf;
21 this.id = id;
22 this.width = w;
23 this.height = h;
24 this.version = ver;
25 this.align = "middle";
26
27 this.params = new Object();
28 this.variables = new Object();
29
30 this.redirect = "";
31 this.sq = document.location.search.split("?")[1] || "";
32 this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
33
34 if (c) this.color = this.addParam('bgcolor', c);
35 this.addParam('quality', 'high'); // default to high
36 this.doDetect = getQueryParamValue('detectflash');
37}
38
39var FOP = FlashObject.prototype;
40
41FOP.addParam = function(name, value) { this.params[name] = value; }
42
43FOP.getParams = function() { return this.params; }
44
45FOP.getParam = function(name) { return this.params[name]; }
46
47FOP.addVariable = function(name, value) { this.variables[name] = value; }
48
49FOP.getVariable = function(name) { return this.variables[name]; }
50
51FOP.getVariables = function() { return this.variables; }
52
53FOP.getParamTags = function() {
54 var paramTags = "";
55 for (var param in this.getParams()) {
56 paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
57 }
58 return (paramTags == "") ? false:paramTags;
59}
60
61FOP.getHTML = function() {
62 var flashHTML = "";
63 if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
64 flashHTML += '<embed type="application/x-shockwave-flash" swliveconnect="true" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
65 for (var param in this.getParams()) {
66 flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
67 }
68 if (this.getVariablePairs()) {
69 flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
70 }
71 flashHTML += '></embed>';
72 } else { // PC IE
73 flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
74 flashHTML += '<param name="movie" value="' + this.swf + '" />';
75 if (this.getParamTags()) {
76 flashHTML += this.getParamTags();
77 }
78 if (this.getVariablePairs() != null) {
79 flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
80 }
81 flashHTML += '</object>';
82 }
83 return flashHTML;
84}
85
86FOP.getVariablePairs = function() {
87 var variablePairs = new Array();
88 for (var name in this.getVariables()) {
89 variablePairs.push(name + "=" + escape(this.getVariable(name)));
90 }
91 return (variablePairs.length > 0) ? variablePairs.join("&"):false;
92}
93
94FOP.write = function(elementId) {
95 if(detectFlash(this.version) || this.doDetect=='false') {
96 if (elementId) {
97 document.getElementById(elementId).innerHTML = this.getHTML();
98 } else {
99 document.write(this.getHTML());
100 }
101 } else {
102 if (this.redirect != "") {
103 document.location.replace(this.redirect);
104 } else if (this.altTxt) {
105 if (elementId) {
106 document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
107 } else {
108 document.write(this.altTxt +""+ this.bypassTxt);
109 }
110 }
111 }
112}
113
114/* ---- detection functions ---- */
115function getFlashVersion() {
116 var flashversion = 0;
117 if (navigator.plugins && navigator.mimeTypes.length) {
118 var x = navigator.plugins["Shockwave Flash"];
119 if(x && x.description) {
120 var y = x.description;
121 flashversion = y.charAt(y.indexOf('.')-1);
122 }
123 } else {
124 result = false;
125 for(var i = 15; i >= 3 && result != true; i--){
126 execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
127 flashversion = i;
128 }
129 }
130 return flashversion;
131}
132
133function detectFlash(ver) { return (getFlashVersion() >= ver) ? true:false; }
134
135// get value of query string param
136function getQueryParamValue(param) {
137 var q = document.location.search || document.location.href.split("#")[1];
138 if (q) {
139 var detectIndex = q.indexOf(param +"=");
140 var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
141 if (q.length > 1 && detectIndex > -1) {
142 return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
143 } else {
144 return "";
145 }
146 }
147}
148
149/* add Array.push if needed */
150if(Array.prototype.push == null){
151 Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
152}
153