// Função de verificação do plugin flash
function flashPlugin( plugin_version ){
	var default_version = 5 ;
	var version ;
	if( plugin_version.length == "" ){
		version = new Number( default_version ) ;
	}
	else{
		version = new Number( plugin_version ) ;
	}
	var agent = navigator.userAgent.toLowerCase() ;
	var fol_plugin = new String() ;
	var plugin_description = new String() ;
	if ( navigator.plugins && navigator.plugins.length ){
		for ( var i = 0 ; i < navigator.plugins.length ; i++ ){
			fol_plugin = navigator.plugins[i] ;
			plugin_description = fol_plugin.description.split( " " ) ;
			if ( plugin_description[0] == "Shockwave" && plugin_description[1] == "Flash" && plugin_description[2].split( "." )[0] >= version.valueOf() ){
	            return true ;
	        }
	        else{
		        for ( var j = 0 ; j < fol_plugin.length ; j++ ){
		        	if ( fol_plugin[j].type == "application/x-shockwave-flash"){
		        		return true ;
		        	}
		        }
		    }
		}
		return false ;
	}
	else if ( navigator.mimeTypes && navigator.mimeTypes.length ){
		var detectPlugin = navigator.mimeTypes[ "application/x-shockwave-flash" ] ;
		if( detectPlugin && detectPlugin.enabledPlugin ){
			return true ;
		}
		else{
			return false ;
		}
	}
	else if ( agent.indexOf( "msie" ) != -1 && parseInt( navigator.appVersion , 10 ) >= 4 ){
		document.write( "<scr" + "ipt language=\"VBScript\"> \n") ;
		document.write( "on error resume next \n" ) ;
		document.write( "dim fol_plugin \n" ) ;
		document.write( "dim IEDetect \n" ) ;
		document.write( "set fol_plugin = CreateObject(\"ShockwaveFlash.ShockwaveFlash." + version + "\") \n" ) ;
		document.write( "if IsObject( fol_plugin ) then \n" ) ;
		document.write( "IEDetect = true \n" ) ;
		document.write( "else IEDetect = false \n" ) ;
		document.write( "end if" ) ;
		document.write( "<\/scr" + "ipt> \n") ;
		if( IEDetect ){
			return true ;
		}
	}
	return false ;
}

// Função para inserção local de peças em flash

function ie_mac(){
	return ( navigator.platform.toLowerCase().indexOf("mac") > -1 ) && ( navigator.appName.indexOf( "Internet Explorer" ) > -1 ) ;
}

/* O flash se atrapalha ao converter texto acentuado por problemas de charset.
O texto enviado ao flash então é enviado como códigos decimais de charset. */
function decompose( s ){
	var str = "" , val ;
	for( var i = 0; i < s.length; ++i ){
		val = s.charCodeAt(i).toString() ;
		while ( val.length < 3 ){
			val = "0" + val ;
		}
		str += val ;
	}
	return str ;
}



function criarplayer( url , text , width , height , path ){

	var tag = "" ;
	var flashvars = "url=" + escape( url ) + "&description=" + decompose( text ) + "&editoria=Sampa";
	if ( navigator.appName.indexOf( "Internet Explorer" ) > -1 ){
		tag += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"player\" align=\"middle\">" ;
		tag += "<param name=\"movie\" value=\"" + path + "\">" ;
		tag += "<param name=\"allowScriptAccess\" value=\"always\">" ;
		tag += "<param name=\"quality\" value=\"high\">" ;
		tag += "<param name=\"flashvars\" value=\"" + flashvars + "\">" ;
		if ( ie_mac() ){
			tag += "<embed type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" id=\"player\" src=\"" + path + "\" flashvars=\"" + flashvars + "\"><\/embed>" ;
		}
	}
	else{
		tag += "<object type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" data=\"" + path + "\" flashvars=\"" + flashvars + "\" id=\"player\">" ;
	}
	tag += "<\/object>";
	document.write(tag);
}

