/* $Id: swfalt.jquery.js,v 1.1.4.1 2008/03/24 19:56:48 ytan Exp $

Unobtrusive Accessible jQuery 1.2.1 alt-flash content.

Overview:
	jQuery.fn.swfalt()
	Shows Flash object if JavaScript and the correct version of Flash are
	installed/enabled and hides alternate content.

Parameters:
	One parameter. If this parameter is NOT an object it is treated as
	the property "version" below. If the parameter is an object, it expects
	the properties below:
		version: (Float) Version of Flash required. null == any version of
			Flash.
			default: null
		alt: (String) Selector for alternate content.
			default: '.alt'

Usage:
	HTML:
	<div id="contact" class="swf">
		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="445" height="270" id="flash_piece" class="content">
			<param name="allowScriptAccess" value="sameDomain" />
			<param name="movie" value="flash_piece.swf" />
			<param name="quality" value="high" />
			<param name="wmode" value="transparent">
			<embed src="flash_piece.swf" quality="high" wmode="transparent" width="445" height="270" name="flash_piece" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
		</object>
		<div class="alt">
			<h3>Alternate Display Information</h3>
			<p>For Search Engines</p>
			<p>And The Disabled</p>
		</div>
	</div>

	JAVASCRIPT:
	// Hide .alt within .swf if any flash is present
		$('.swf').swfalt();
	// Hide .alt within .swf if flash 7 or above
		$('.swf').swfalt(7);
	// Hide .alt_content within .swf if flash 7 or above
		$('.swf').swfalt({version: 7, alt: '.alt_content'});

Author:
	gburns

TODO:
	Documentation
*/

jQuery.fn.swfalt = function(settings) {
	if ( typeof(settings) != 'object' ) settings = { version: settings };

	settings = jQuery.extend({
		version: null,
		alt: '.alt'
	}, settings || {});

	settings.version = ( parseInt(settings.version) ) ? parseInt(settings.version) : null;

	var version = ( jQuery.swfalt.installed != null ) ? jQuery.swfalt.version : jQuery.swfalt.check().version;

	return this.each(function() {
		if ( version < settings.version ) return;

		var $object = jQuery('object, embed', this)
			.show();

		if ( $.browser.msie ) $object[0].outerHTML = $object[0].outerHTML;

		jQuery(settings.alt, this)
			.hide();
	});
};

jQuery.swfalt = {
	installed: null,
	version: null,
	lastMajorRelease: 10,
	check: function() {
		var flash_plugin;

		if ( navigator.plugins && navigator.plugins.length ) {
			flash_plugin = navigator.plugins["Shockwave Flash"];
			if (flash_plugin) {
				jQuery.swfalt.installed = true;

				if ( flash_plugin.description ) {
					jQuery.swfalt.version = flash_plugin.description.charAt(flash_plugin.description.indexOf('.')-1);
				}
			} else {
				jQuery.swfalt.installed = false;
			}

			if (navigator.plugins["Shockwave Flash 2.0"]){
				jQuery.swfalt.installed = true;
				jQuery.swfalt.version = 2;
			}
		} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
			flash_plugin = navigator.mimeTypes['application/x-shockwave-flash'];

			if ( flash_plugin && flash_plugin.enabledPlugin ) {
				jQuery.swfalt.installed = true;
			} else {
				jQuery.swfalt.installed = false;
			}
		} else {
			for ( var i=jQuery.swfalt.lastMajorRelease; i>=2; i-- ) {
				try {
					flash_plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
					jQuery.swfalt.installed = true;
					jQuery.swfalt.version = i;
					break;
				} catch(e) {
				}
			}

			if ( jQuery.swfalt.installed == null ) {
				try {
					flash_plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					jQuery.swfalt.flashInstalled = true;
					jQuery.swfalt.version = 2;
				} catch(e) {
				}
			}

			if ( jQuery.swfalt.installed == null ) {
				jQuery.swfalt.installed = false;
			}

			flash_plugin = null;
		}

		return {installed: jQuery.swfalt.installed, version: jQuery.swfalt.version};
	}
};