/**********************************************************************************
 * 
 * LastChangedDate:		$Date: 2007-01-29 12:59:04 +0100 (Mon, 29 Jan 2007) $
 * LastChangedRevision	$Rev: 50 $
 * LastChangedBy:		$Author: $
 * HeadURL:				$URL: http://linux/cd/balance/trunk/httpdocs/js/nl/xd/flash/flash.js $
 * ID:					$Id: flash.js 50 2007-01-29 11:59:04Z  $
 * 
/**********************************************************************************/

// flash namepace
window.nl.xd.flash = {} ;

// Simple package
window.nl.xd.flash.Simple = function() {
	return {
		Standard: function( src , width , height , flashvars , id ) {
			var flash 	= '' ;
			var ua 		= navigator.userAgent.toLowerCase() ;
			var isOpera = ( ua.indexOf( 'opera' ) != -1 ) ;
			
			if ( isOpera ) {
				flash += '<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="' + width + '" height="' + height + '" id="' + id + '" align="left">' ;
				flash += '<param name="movie" value="' + src + '?timestamp=' + id + '" />' ;
				flash += '<param name="quality" value="high" />' ;
				flash += '<param name="wmode" value="transparent" />' ;
				falsh += '<param name="flashvars" value="' + flashvars + '" />' ;
				flash += '</object>' ;
			} else {
				flash += '<embed src="' + src + '?timestamp=' + id + '" flashvars="' + flashvars + '" wmode="transparent" quality="high" width="' + width + '" height="' + height + '" name="' + id + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' ;
			} ;
			
			return flash ;
		}
	} ;
} () ;

// Flash Class
nl.xd.flash.Flash = function( target , file , version , name , width , height ) {
	this.target = nl.xd.util.DOM.get( target ) ;
	
	this.node    = null ;
	this.isOpera = null ;
	
	this.initialize( file , version , name , width , height ) ;
} ;
nl.xd.flash.Flash.prototype.initialize = function( file , version , name , width , height ) {
	var ua = navigator.userAgent.toLowerCase() ;
	
	this.isOpera = ( ua.indexOf( 'opera' ) != -1 ) ;
	
	this.create( file , version , name , width , height ) ;
} ;
nl.xd.flash.Flash.prototype.build = function() {
	this.target.appendChild( this.node ) ;
} ;
nl.xd.flash.Flash.prototype.create = function( file , version , name , width , height ) {
	if ( this.isOpera ) {
		this.node = document.createElement( 'object' ) ;
		this.node.setAttribute( 'classid' , 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ) ;
		this.node.setAttribute( 'codebase' , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version ) ;
		this.node.setAttribute( 'width' , width ) ;
		this.node.setAttribute( 'height' , height ) ;
		this.node.setAttribute( 'name' , name ) ;
		this.node.setAttribute( 'id' , name ) ;
		
		this.node.appendChild( this.param( 'movie' , file ) ) ;
		this.node.appendChild( this.param( 'quality' , 'high' ) ) ;
	} else {
		this.node = document.createElement( 'embed' ) ;
		this.node.setAttribute( 'src' , file ) ;
		this.node.setAttribute( 'quality' , 'high' ) ;
		this.node.setAttribute( 'width' , width ) ;
		this.node.setAttribute( 'height' , height ) ;
		this.node.setAttribute( 'name' , name ) ;
		this.node.setAttribute( 'type' , 'application/x-shockwave-flash' ) ;
		this.node.setAttribute( 'pluginspage' , 'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ) ;
	} ;
} ;
nl.xd.flash.Flash.prototype.attribute = function( name , value ) {
	if ( this.isOpera ) {
		this.node.appendChild( this.param( name , value ) ) ;
	} else {
		this.node.setAttribute( name , value ) ;
	} ;
} ;
nl.xd.flash.Flash.prototype.param = function( name , value ) {
	var node = document.createElement( 'param' ) ;
	node.setAttribute( 'name' , name ) ;
	node.setAttribute( 'value' , value ) ;
	
	return node ;
} ;

/* ---- detection functions ---- */
deconcept = {} ;
deconcept.SWFObjectUtil = {} ;

deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
