/* Конструктор класса FlashObject*/
function Flash( ) { 

	this.BrowserInfo( );

}

/* Метод определения типа Браузера */
Flash.prototype.BrowserInfo = function( ) {	
	
	var userAgent = navigator.userAgent.toLowerCase( );
   	this.browserIE = ( userAgent.indexOf( 'msie' ) != -1 );

}

/* Метод для опеределения нужной версии флэша */
Flash.prototype.CheckVersionFlash = function( needVersion ) {
	
	if ( navigator.plugins[ 'Shockwave Flash' ] ) {
		/* определяем есть ли у браузера plugin флэшплеера */
		matchStr = new RegExp ( '^[A-Za-z ]*(.*) .*$' );
		this.flashVerion = parseInt( navigator.plugins[ 'Shockwave Flash' ].description.replace( matchStr, '$1' ) );
		return ( needVersion <= this.flashVerion );
	}
	else if ( this.browserIE ) {
		/* иначе будет создаваться ActiveX объект (IE) */
		for( var i = needVersion; i < needVersion + 10; i++ ) {
			try {
			        flashPlayer = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash.' + i );
			        this.flashVerion = i;
			        return true;
			} 
			catch( e ) { 
				continue;
			}
		}
		return false;		
	}
	else {
		this.flashVerion = 0;
		return false;
	}
	
}

/* Метод вставки в страницу HTML нужного кода */
Flash.prototype.Insert = function( ) {
	
	if ( this.CheckVersionFlash( this.needFlashVerion ) ) {
		document.write( this.GenerateHtmlFlash( ) );
	}
	else {
		document.write( this.GenerateHtmlImage( ) );
	}
		
}

/* Метод для генерирования флэш - кода */
Flash.prototype.GenerateHtmlFlash = function( ) {
 
	var flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	flashCode += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= ' + this.flashVerion + ',0,0,0"' + ' width="' + this.width + '" height="' + this.height + '" align="middle">\n';
	flashCode += '\t<param name="allowScriptAccess" value="always"/>\n';
	flashCode += '\t<param name="movie" value="' + this.srcFlash + '"/>\n';
	flashCode += '\t<param name="quality" value="high"/>\n';
	if ( this.base ) {
		flashCode += '\t<param name="base" value="' + this.base + '"/>\n'; 
	}
	if ( this.background ) {
		flashCode += '\t<param name="bgcolor" value="' + this.background + '"/>\n'; 
	} 
	if ( this.transparent ) {
		flashCode += '\t<param name="wmode" value="transparent"/>\n'; 
	} 
	if ( this.flashvars ) {
		flashCode += '\t<param name="flashvars" value="' + this.flashvars + '"/>\n';
	} 
   
	flashCode += '\t<embed quality="high" allowScriptAccess="always" type="application/x-shockwave-flash"' + ' pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	flashCode += 'src="' + this.srcFlash+'" ' + '" width="' + this.width + '" height="' + this.height + '" ';
	if ( this.base ){
		flashCode += ' base="' + this.base + '"';
	}
	if ( this.background ){
		flashCode += ' bgcolor="' + this.background + '"';
	}
	if ( this.transparent ){
		flashCode += ' wmode="transparent"' 
	}
	if ( this.flashvars ){
		flashCode += ' flashvars="' + this.flashvars + '"';
	}
	flashCode += '></embed>';
	
	flashCode += '</object>';
    return flashCode;
    
}

/* Метод для генерирования image - кода */
Flash.prototype.GenerateHtmlImage = function( ) {
	
	var imageCode = '<img src="' + this.srcImage + '"/>';
	return imageCode;
	
}
