<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
		<title>Advanced SWF Authoring</title>
		<meta name="generator" content="Adobe GoLive"/>
	</head>

	<body>
		<hr/>
		<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2003 Adobe Systems Incorporated<br/>
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe.</p>
		<hr/>
		<p><b>Extension Name:</b> SWF Detect Extension</p>
		<p><b>Folder name:</b> SWFDetect</p>
		<hr/>
		<p><b>Description:</b></p>
		<p>This extension adds additional support to flexibly embed and deliver SWF content, automatically routing users to plug-in download pages or alternative pages.</p>
		<hr/>
		<p><b>Module Definition:</b></p>
		<jsxmodule info="$$$/extendscript/SWFDetect/info=This extension adds additional support to flexibly embed and deliver SWF content, automatically routing users to plug-in download pages or alternative pages." name="Advanced SWF Authoring" debug="false"/> 
		<p><b>Scripts:</b></p>
		<!-- add some scripts -->
		<script type="text/javascript"><!--
//--------------------------------------------------------------------
// GLOBAL VARIABLES
//--------------------------------------------------------------------
			var SWFInspector = null;
			var SWFDetectPanel = null;

			var typeview;
			var basicview;
			var pageview;
			var htmlview;
			var imageview;
			
			// called when the inspector changes	
			function moduleSignal( evobj ) {
				switch( evobj.type )
				{
					case "inspector":
						if (inspectedIsSWF( document )) {
							addDetectPanel();
						} else {
							SWFInspector = null;
						}
						break;
				}
			} 		

//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------

			function controlSignal(control) {
				if (document) {
					switch (control.name) {
						case 'typedd':
							switch(control.selection.valueOf()) {
								case 0:
									basicview.hide();
									pageview.hide();
									htmlview.hide();
									imageview.hide();
									break;
								
								case 1:
									basicview.show();
									pageview.show();
									htmlview.hide();
									imageview.hide();
									break;

								case 2:
									basicview.show();
									pageview.hide();
									htmlview.show();
									imageview.hide();
									break;
								
								case 3:
									basicview.show();
									pageview.hide();
									htmlview.hide();
									imageview.show();
									break;
							}
							break;
						
						case 'advanced':
							// hide advanced button and show options
							basicview.advanced.hide();
							basicview.revisiontext.show();
							basicview.revisionedit.show();
							break;
						
						case 'createbutton':
							createDetectDocument();
							break;

						case 'createinline':
							if (typeview.typedd.value == module.localize("$$$/extendscript/SWFDetect/InlinewithImage=Inline with Image") || typeview.typedd.value == module.localize("$$$/extendscript/SWFDetect/InlinewithHTML=Inline with HTML")) {
								createInline();
							}
							break;

						case 'removebutton':
							removeInline();
							break;
						
						case 'imageurl':
							// Check if specified file exists
							var imageFile = new JSXFile( control.value );
							// Probably a relative reference, if there is a document,
							if (!imageFile.exists && document.file) {
								// either reference the site or the document
								var targetDir = (document.ref.siteDoc == null) ? document.file.parent : document.ref.siteDoc.website.root;
								imageFile = new JSXFile(targetDir.absurl + control.value);
							}
							if (imageFile.exists) { // Ignore settings if still can't find
								var results = app.imageConverter.getImageSize(imageFile);
								if (results != null) {
									imageview.widthedit.value = results.width;
									imageview.heightedit.value = results.height;
								}
							}
							break;

						case 'widthdd':
							if (control.value == module.localize("$$$/extendscript/SWFDetect/Image=Image")) imageview.widthedit.value = '';
							break;
							
						case 'heightdd':
							if (control.value == module.localize("$$$/extendscript/SWFDetect/Image=Image")) imageview.heightedit.value = '';
							break;
					}
				}
			}
			
			
			function addDetectPanel() 
			{
				// get a ref to the current inspector
				var myWindow = Window.find("inspector","current");
				// make sure the tab panel is showing, if it isn't then the swf inspector isn't being displayed,
				// but the insertionpoint could still be inside an swf object.
				if (myWindow != null && myWindow.children.length > 0 && myWindow.children[0].constructor.name == "Tabpanel") 
				{
					SWFDetectPanel = myWindow.children[0].add('panel', [10,10,20,20], localize('Detect'), {name:'detectpanel', alignment:['scale','scale'], icon:'test'}); // add the panel

			
 					myWindow.children[0].children[0].show();	

					typeview = SWFDetectPanel.add('panel', "TypeControls", { alignment:['scale','top'] } );//, "TITLE", {name:'detectpanel', alignment:'left', icon:'test'}); // add the panel
					typeview.posx = 10;
					typeview.posy = 5;
					typeview.size.width = SWFDetectPanel.size.width;
					
					// add basic view
					basicview = SWFDetectPanel.add('panel', "BasicControls", { alignment:['scale','scale'] } );
					basicview.posx = 10;
					basicview.posy = 30;
					basicview.size.width = SWFDetectPanel.size.width;
					// hide advanced
					basicview.revisiontext.hide();
					basicview.revisionedit.hide();
					basicview.hide();

					// add Page view
					pageview = SWFDetectPanel.add('panel', "PageControls", { alignment:['scale','scale'] } );
					pageview.posx = 10;
					pageview.posy = 60;
					pageview.size.width = SWFDetectPanel.size.width;
					pageview.hide();
					
					// add HTML view
					htmlview = SWFDetectPanel.add('panel', "HTMLControls", { alignment:['scale','scale'] } );
					htmlview.posx = 10;
					htmlview.posy = 60;
					htmlview.size.width = SWFDetectPanel.size.width;
					htmlview.hide();
					
					// add image view
					imageview = SWFDetectPanel.add('panel', "ImageControls", { alignment:['scale','scale'] } );
					imageview.posx = 10;
					imageview.posy = 60;
					imageview.size.width = SWFDetectPanel.size.width;
					imageview.hide();
				}
 					
				SWFInspector = myWindow;
			}


	





	// ----------------------------------------------------------
	// basic detect script
	// ----------------------------------------------------------
	function getDetect() {
		var txt = "var plugin = (navigator.mimeTypes && navigator.mimeTypes[\"application\/x-shockwave-flash\"]) ? navigator.mimeTypes[\"application\/x-shockwave-flash\"].enabledPlugin : 0;\nif (plugin) {\n	var words = navigator.plugins[\"Shockwave Flash\"].description.split(\" \");\n	for (var i=0; i<words.length; ++i) {\n		if (isNaN(parseInt(words[i]))) continue;\n		var pluginVersion = words[i];\n		var revision = parseInt(words[i + 1].substring(1));\n	}\n	var hasFlash = pluginVersion >= version;\n} else if (navigator.userAgent && navigator.userAgent.indexOf(\"MSIE\")>=0 \n   && (navigator.appVersion.indexOf(\"Win\") != -1)) {\n	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \\n');\n	document.write('on error resume next \\n');\n	document.write('hasFlash = ( IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & version)))\\n');\n	document.write('<\/SCR' + 'IPT\> \\n');\n}";

		return txt;
	}




	// ----------------------------------------------------------
	// Page detect
	// ----------------------------------------------------------
		function addToScript(text) {
			var js = document.element.getSubElement("script");
			// if a script tag is found
			if (js) {
				var scriptcontents = js.getInnerHTML();
				js.setInnerHTML(scriptcontents + text);
			} else {
				var head = document.element.getSubElement("head");
				var headHTML = head.getInnerHTML();
				head.setInnerHTML(headHTML + "<scr"+"ipt type='text/javascript'>\n" + text + "\n<"+"/"+"script>\n");
			}
			
		}
		
		function createDetectDocument() {
			var version = basicview.versiondd.value.substr(-1);
			var revision = (basicview.rev) ? basicview.revisionedit.value:0;
			var successpage = pageview.flashurl.value
			var failpage = pageview.alturl.value;
		
			// create the new document
			var newdoc = app.newDocument();
			
			// set params for detect
			var detect = "var version	= " + version + ";\n";
			
			// get basic detect 
			detect += getDetect();
			
			detect += "if (hasFlash) {\nwindow.location.href='" + successpage + "';\n} else {\nwindow.location.href='" + failpage + "';\n}\n";
			addToScript(detect);
		}
		
		
		
	// ----------------------------------------------------------
	// Inline detect
	// ----------------------------------------------------------		
		// update inline
		// this func is called whenever a property in either of the inline inspectors is changed
		function createInline() {
			var version = basicview.versiondd.value.substr(-1);
			var revision = (basicview.rev) ? basicview.revisionedit.value:0;
			if (typeview.typedd.value == module.localize("$$$/extendscript/SWFDetect/InlinewithHTML=Inline with HTML")) {
				createHTMLDetect(version, revision, htmlview.sourceurl.value);
			} else if (typeview.typedd.value == module.localize("$$$/extendscript/SWFDetect/InlinewithImage=Inline with Image")) {
				createImageDetect(version, revision);
			}
		}

		function removeInline() {
			var source = unescape(document.selection.element.getAttribute('orig'));
			var pat = /var theembed = "([^;]*)"/;
			var results = source.match(pat);
			var embed = stripslashes(results[1]);
			app.translator.rewriteSnippet (embed, 'Remove Inline Detect');
		}

		
		
		function createHTMLDetect(version, revision, source) {
			// open the file
			var thefile = new JSXFile(source);
			
			// read the contents
			thefile.open("r");
			var html = thefile.read();
			
			// remove \r b/c javascript doesn't like them
			html = html.replace(/[\r|\n]/g, '');
			
			addInlineDetect(version, revision, html);

		}
		
		function createImageDetect(version, revision) {
			if (imageview.imageurl.value != "") {
				var imgtag = "<img ";
				imgtag += "src=\"" + imageview.imageurl.value + "\" ";
				if (imageview.altedit.value != "") imgtag += "alt=\""+imageview.altedit.value+"\" ";

				// set width
				if (imageview.widthedit.value != "" && (imageview.widthdd.value != module.localize("$$$/extendscript/SWFDetect/Image=Image"))) {
					switch (imageview.widthdd.value) {
						case (module.localize("$$$/extendscript/SWFDetect/Pixel=Pixel")):
							imgtag += "width=\""+imageview.widthedit.value+"\" ";
							break;
						case (module.localize("$$$/extendscript/SWFDetect/Percent=Percent")):
							imgtag += "width=\""+imageview.widthedit.value+"%\" ";
							break;
					}
				}

				// set height
				if (imageview.heightedit.value != "" && (imageview.heightdd.value != module.localize("$$$/extendscript/SWFDetect/Image=Image"))) {
					switch (imageview.heightdd.value) {
						case (module.localize("$$$/extendscript/SWFDetect/Pixel=Pixel")):
							imgtag += "height=\""+imageview.heightedit.value+"\" ";
							break;
						case (module.localize("$$$/extendscript/SWFDetect/Percent=Percent")):
							imgtag += "height=\""+imageview.heightedit.value+"%\" ";
							break;
					}
				}

				
				// set name/ID
				if (imageview.nameedit.value != "" && (imageview.namedd.value != module.localize("$$$/extendscript/SWFDetect/None=None"))) {
					switch (imageview.namedd.value) {
						case (module.localize("$$$/extendscript/SWFDetect/Name=Name")):
							imgtag += "name=\""+imageview.nameedit.value+"\" ";
							break;
						case (module.localize("$$$/extendscript/SWFDetect/ID=ID")):
							imgtag += "id=\""+imageview.nameedit.value+"\" ";
							break;
						case (module.localize("$$$/extendscript/SWFDetect/NameID=Name & ID")):
							imgtag += "name=\""+imageview.nameedit.value+"\" ";
							imgtag += "id=\""+imageview.nameedit.value+"\" ";
							break;
					}
				}
				
				imgtag += " />";
				addInlineDetect(version, revision, imgtag);
			}
		}


		function addInlineDetect(version, revision, source) {
			// set params for detect
			var detect = getDetectTag("html", version, revision, source);
			detect += "<scrip" + "t type='text/javascript'>var version	= " + version + ";";
			
			// get basic detect 
			detect += getDetect();
			
			// get html code from document
			var embed = document.selection.text;
			// escape dbl quotes
			embed = addslashes(embed);
			embed = embed.replace(/[\r|\n]/g, '');
			
			// escape dbl quotes for source
			source = addslashes(source);

			detect += "if (hasFlash) {\n";
			detect += "var theembed = \"" + embed + "\";\n";
			detect += "document.write(theembed);} else {\n";
			detect += "var thehtml = \"" + source + "\";\n";
			detect += "document.write(thehtml);}";
			detect += "<"+"/script><"+"/agl:swfdetect>";
			
			var te = document.selection.element.textArea;
			
			if( te != null )
			{
				te.remove();
				te.insertHTML( detect );
				te.selectionLength = 1;
			}
		}
		
		// get the start swfdetect tag
		function getDetectTag(type, version, revision, source, width, widthtype, height, heighttype, alt, name, id) {
			var output	=  '<agl:swfdetect ';
			output 		+= 'type="html" ';
			output 		+= 'src="'+escape(source)+'" ';
			output 		+= 'version="'+version+'" ';
			output 		+= 'revision="'+revision+'" ';
			if (width) output		+= 'width="'+width+'" ';
			if (widthtype) output 	+= 'widthtype="'+widthtype+'" ';
			if (heighttype) output	+= 'heighttype="'+heighttype+'" ';
			if (alt) output 		+= 'alt="'+alt+'" ';
			if (name) output 		+= 'name="'+name+'" ';
			if (id) output 			+= 'id="'+id+'" ';
			output 		+= '>';
			return output;
		}


// ------------------------------------------------------
// TRANSLATOR FUNCTIONS
// ------------------------------------------------------
	function inspectTranslation (inspector, source) {
		// just showing the remove button
	}


	function translate (documentURL, siteURL, source) {
		// declare some vars
		var pattern, match, allattrib, attribs, embed, embedpattern;
		var attributes = new Object();
		
		pattern =/<agl:swfdetect[^>]*>(.|\r|\n)*<\/agl:swfdetect>/g;
		pattern.multiline= true;
		while (true) {
			match = pattern.exec(source);
			if (match == null) 
			{
				break;
			}
			
			var idx = match.index;
			
			// save the match and get the tag attributes
			match = match[0];
			var attributes = getAtttributes(match);
			
			// no grab the orginal embed tag
			embedpattern =/<object[^>]*>(.|\r|\n)*<\\\/object>/g;
			embed = embedpattern.exec(match);
			app.translator.translateSnippet (idx, match.length, stripslashes(embed[0]));
		}
	}



	//-------------------------------------
	// UTILITY FUNCTIONS
	//-------------------------------------
	
		function addslashes(str) {
			var output = str.replace(/"/g, '\\"');
			output = output.replace(/\//g, '\\/');
			return output;
		}
		
		function stripslashes(str) {
			var output = str.replace(/\\\\/g, '\\');
			output = output.replace(/\\"/g, '"');
			output = output.replace(/\\'/g, "'");
			output = output.replace(/\\\//g, "/");
			return output;
		}
		
		// return the attributes from and xml node
		function getAtttributes(tag) {
			var attributes, match, attribs;
			
			attributes = [];
			// parse out all attributes
			match = /<(\S*) ?([^>]*)>/.exec(tag);
			
			// quit if no attributes
			if (match == null) return false;
			
			// grab match we want
			match = match[2];

			// now break up attributes
			attrib_pattern = /([^\s"\'=]+?)=[\'|"]([^\'|"]+)/g;
			while(true) {
				attribs = attrib_pattern.exec(match);
				
				// quit loop if nothing is left
				if (attribs == null) break;
				attributes[attribs[1]] = attribs[2];
			}
			return attributes;
		}

			
		
		// test's if the currently selected item is a flash obj,
		// if so adds the SWF detect panel.
		// adapted from code provided by Patrick Wollek @ adobe.
		function inspectedIsSWF( doc ) {
			// test if there is a doc and the view is ok
			if( doc != null && doc.type == "markup" && doc.view == "layout" ) {
				var obj = document.selection.element;						// grab this element
				if( obj == null ) return false;								// die is if is nul

				// make sure the tag is an object tag
				if( obj.nodeName == "object" ) {
					// first check if the obj tag's classid is the correct one for flash
					// since the embed tag is no good for xhtml it might not always be there
					var classid = obj.getAttributeNode( "classid" );
					if( classid != null && classid.value == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000") {
						return true;
					}
					
					// just in case this doc only has an embed tag, grab it and double check
					var lst = obj.getElementsByTagName( "embed" );
					
					if( lst.length > 0 ) {
						var embeded = lst[0];
						var type = embeded.getAttributeNode( "type" );
						
						if( type != null && type.value == "application/x-shockwave-flash" ) {
							return true;
						}
					}
				}
			}
			return false;
		}
//-->
</script>
		<!-- define the views --><!-- Persistent detect type controls -->
		<jsxview height="20" name="TypeControls" width="250">
			<jsxcontrol posx="0" posy="4" type="static" value="Type" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="typedd" halign="scale" posx="65" posy="0" type="popup" value="$$$/extendscript/SWFDetect/NoneDetectPageInlinewith=None,Detect Page,Inline with HTML,Inline with Image" width="161"></jsxcontrol>
		</jsxview>
		<!-- Basic version and revision controls -->
		<jsxview height="335" name="BasicControls" width="250">
			<jsxcontrol posx="0" posy="4" type="static" value="$$$/extendscript/SWFDetect/Versi=Version" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="versiondd" posx="65" posy="0" type="popup" value="7,6,5,4" width="50"></jsxcontrol>
				 <!-- advanced row -->
			<jsxcontrol height="19" name="advanced" posx="125" posy="0" type="button" value="$$$/extendscript/SWFDetect/Advanced=Advanced" width="80"></jsxcontrol>
			 
			<jsxcontrol name="revisiontext" posx="135" posy="4" type="static" value="$$$/extendscript/SWFDetect/Revision=Revision" width="45" height="19"></jsxcontrol>
			 
			<jsxcontrol height="20" name="revisionedit" posx="180" posy="0" type="edit" value="0" width="15"></jsxcontrol>
		</jsxview>
		<!-- Detect Page Controls -->
		<jsxview height="335" name="PageControls" width="250">
			<!-- flash url -->
			<jsxcontrol posx="0" posy="4" type="static" value="$$$/extendscript/SWFDetect/FlashPage=Flash Page" width="45"></jsxcontrol>
			 
			<jsxcontrol name="flashurl" halign="scale" height="18" posx="65" posy="0" type="urlgetter" value="(EmptyReference!)" width="161"></jsxcontrol>
			 <!-- alternate url -->
			<jsxcontrol posx="0" posy="34" type="static" value="$$$/extendscript/SWFDetect/Alternate=Alternate" width="45"></jsxcontrol>
			 
			<jsxcontrol name="alturl" halign="scale" height="18" posx="65" posy="30" type="urlgetter" value="(EmptyReference!)" width="161"></jsxcontrol>
			 <!-- create button -->
			<jsxcontrol height="19" name="createbutton" posx="65" posy="60" type="button" value="$$$/extendscript/SWFDetect/CreatePage=Create Page" width="80"></jsxcontrol>
		</jsxview>
		<!-- Inline HTML Controls -->
		<jsxview height="335" name="HTMLControls" width="250">
			<!-- HTML url -->
			<jsxcontrol posx="0" posy="4" type="static" value="$$$/extendscript/SWFDetect/Source=Source" width="45"></jsxcontrol>
			 
			<jsxcontrol name="sourceurl" halign="scale" height="18" posx="65" posy="0" type="urlgetter" value="(EmptyReference!)" width="161"></jsxcontrol>
			 <!-- create button -->
			<jsxcontrol height="19" name="createinline" posx="65" posy="60" type="button" value="$$$/extendscript/SWFDetect/InsertDetect=Insert Detect" width="80"></jsxcontrol>
		</jsxview>
		<!-- Inline Image Controls -->
		<jsxview height="335" name="ImageControls" width="250">
			<!-- Image url -->
			<jsxcontrol posx="0" posy="4" type="static" value="$$$/extendscript/SWFDetect/Source=Source" width="45"></jsxcontrol>
			 
			<jsxcontrol name="imageurl" halign="scale" height="18" posx="65" posy="0" type="urlgetter" value="" width="161"></jsxcontrol>
			 <!-- width row -->
			<jsxcontrol posx="0" posy="34" type="static" value="$$$/extendscript/SWFDetect/Width=Width" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="widthedit" posx="65" posy="30" type="edit" value="" width="30"></jsxcontrol>
			 
			<jsxcontrol height="19" name="widthdd" posx="100" posy="30" type="popup" value="$$$/extendscript/SWFDetect/PixelPercentImage=Pixel,Percent,Image" width="80"></jsxcontrol>
			 <!-- height row -->
			<jsxcontrol posx="0" posy="61" type="static" value="$$$/extendscript/SWFDetect/Height=Height" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="heightedit" posx="65" posy="57" type="edit" value="" width="30"></jsxcontrol>
			 
			<jsxcontrol height="19" name="heightdd" posx="100" posy="57" type="popup" value="$$$/extendscript/SWFDetect/PixelPercentImage=Pixel,Percent,Image" width="80"></jsxcontrol>
			 
			<hr/>
			<!-- alt text row -->
			<jsxcontrol posx="0" posy="99" type="static" value="$$$/extendscript/SWFDetect/AltText=Alt Text" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="altedit" halign="scale" posx="65" posy="95" type="edit" value="" width="161"></jsxcontrol>
			 <!-- Name/ID -->
			<jsxcontrol posx="0" posy="129" type="static" value="$$$/extendscript/SWFDetect/NameID=Name/ID" width="45"></jsxcontrol>
			 
			<jsxcontrol height="19" name="nameedit" posx="65" posy="125" type="edit" value="" width="60"></jsxcontrol>
			 
			<jsxcontrol height="19" name="namedd" posx="130" posy="125" type="popup" value="$$$/extendscript/SWFDetect/NameIDNameNone=Name & ID,ID,Name,None" width="80"></jsxcontrol>
			 <!-- create button -->
			<jsxcontrol height="19" name="createinline" posx="65" posy="155" type="button" value="$$$/extendscript/SWFDetect/InsertDetect=Insert Detect" width="80"></jsxcontrol>
		</jsxview>
		<!-- define a translator -->
		<jsxtranslator classid="SWFDetect" direction="twoway">
			<param name="extension" value="html"/>
			<param name="extension" value="htm"/>
			<param name="extension" value="php"/>
			<param name="extension" value="asp"/>
			<param name="expression" value="<agl:swfdetect[^>]*>"/>
		</jsxtranslator>
		<!-- Define the inspector for the translations -->
		<jsxinspector classid="SWFDetect" height="164" name="inspector" title="$$$/extendscript/SWFDetect/TimeInspector=Time Inspector" width="215">
			<jsxcontrol height="19" name="removebutton" posx="70" posy="10" type="button" value="$$$/extendscript/SWFDetect/RemoveDetect=Remove Detect" width="90"></jsxcontrol>
		</jsxinspector>
	</body>

</html>
