/*
 * $Revision: 1.19 $ $Date: 2007/11/17 18:05:12 $
 */
// flash detection routines

var rem; // this is for .vbs part
var flashy = 0; // 0 = not detected, other = flash version detected
MSDetect = "false";

function flash_versionextract(p) {
	/*
	  "Shockwave Flash 7.0 r63"
	  "Shockwave Flash 8.0 r24"
	  "Flash Movie player Version 0.4.12 compatible with Shockwave Flash 4.0"
	  "Shockwave Flash 4.0 animation viewer handled by swfdec-0.3.5"
	  "Shockwave Flash 9.0 r31"
	*/
	var d = p.description;
	var t = 'Shockwave Flash ';
	var s = d.substring(d.indexOf(t) + t.length);
	var v = parseInt(s);
	var r = parseInt(s.substring(s.indexOf('r') + 1));
	return (v ? v + (r ? r / 100 : 0) : 0);
}

if (navigator.plugins && navigator.plugins.length) {
	p = navigator.plugins['Shockwave Flash'];
	if (p) {
		flashy = flash_versionextract(p);
	}
} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	var m = navigator.mimeTypes['application/x-shockwave-flash'];
	if (m && m.enabledPlugin) {
		flashy = flash_versionextract(m.enabledPlugin);
	}
} else {
	MSDetect = "true";
}

/*
 * legacy flash displayer
 * for more advanced displayer use flashd()
 */
function flashs(url, width, height, id) {
	var d = {
		url : url,
		width: width,
		height: height
	};

	if (typeof(id) != 'undefined') {
		d.id = id;
		d.wmode = 'transparent';
		d.scriptaccess = true;
		d.play = 'false';
	}
	flashd(d);
	return '';
}

/*
 * create html code with flash
 */
function flashd(d) {
	var s = '';

	s += '<object';
	if (d.id) {
		s += ' id=' + d.id;
	}
	s += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	s += ' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"';
	s += ' width=' + d.width + ' height=' + d.height + '>';

	if (d.play) {
		s += '<param name="play" value="' + d.play + '">';
	}

	if (d.scriptaccess) {
		s += '<param name="allowScriptAccess" value="sameDomain" />';
	}

	if (d.allowfullscreen) {
		s += '<param name="allowfullscreen" value="true" />';
	}

	if (d.wmode) {
		s += '<param name="wmode" value="' + d.wmode + '" />';
	}

	var a = d.url.split('?');
	if (flashy >= 6) {
		d.url = a[0];
		s += '<param name=FlashVars value="' + a[1] + '">';
	}

	s += '<param name=movie value="' + d.url + '">';
	s += '<param name=menu value=false><param name=quality value=high><param name="wmode" value="transparent"  />';
	s += '<embed wmode="transparent" src="' + d.url + '" menu=false quality=high width=' + d.width + ' height=' + d.height;

	if (d.allowfullscreen) {
		s += ' allowfullscreen="true"';
	}

	if (flashy >= 6) {
		s += ' FlashVars="' + a[1] + '"';
	}

	if (d.id) {
		s += ' name=' + d.id;
	}
	if (d.scriptaccess) {
		s += ' swLiveConnect="true" allowScriptAccess="sameDomain"';
	}
	if (d.wmode) {
		s += 'wmode="transparent"';
	}
	/*
	in opera we can't start the flash from javascript (no method)
	neither in firefox (illegal call)
	so we shouldn't disable the autoplay.
	if (!window.opera) {
			s += ' play="false"';
	}*/

	s += ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
	s += '</object>';

	if (d.document) {
		d.document.write(s);
	} else {
		document.write(s);
	}
}

// returns true if wmode is supported
// version info from http://www.adobe.com/go/tn_14201
function flashwm() {
	if (!flashy) {
		return false;
	}
	var p = navigator.platform.toLowerCase();

	if (p.indexOf('win') != -1) {
		return (flashy >= 6.65);
	}

	if (p.indexOf('mac') != -1) {
		return (flashy >= 6.67);
	}

	// just assume version 10 will support it
	return (flashy >= 10);
}

