function buildPluginCode(moduleType, moduleId, filename, player) {
	var content = "";
	var name = "m_" + moduleType + "_" + moduleId + ((moduleType == moduleTypeConst.AUDIO) ? "_audio" : "_video");
	//var filenameParts = filename.split(".");
	//var filetype = filenameParts[filenameParts.length - 1].toLowerCase();
	
	//if ((realPlayer || (!realPlayer && !winMediaPlayer)) && filetype != "wmv" && filetype != "wma" && filetype != "avi") {
	if (player == "real") {
		if (moduleType == moduleTypeConst.VIDEO) {
			content += '<object id="' + name + '" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="240" height="180">';
			content += '<param name ="src" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '">';
			content += '<param name="controls" value="ImageWindow">';
			content += '<param name="console" value="' + name + '">';
			content += '<param name="autostart" value="false">';
			content += '<param name="maintainaspect" value="true">';
			content += '<embed id="' + name + '_emb" type="audio/x-pn-realaudio-plugin" autostart="false" src="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '" controls="ImageWindow" width="240" height="180" maintainaspect="true" pluginspage="http://www.real.com/international/player/" console="' + name + '"></embed>';
			// center param instead of maintainaspect? Test with big video
			content += '</object>';
			
			content += '<object id="' + name + '" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="240" height="45">';
			content += '<param name="controls" value="ControlPanel">';	
			content += '<param name="console" value="' + name + '">';
			content += '<embed id="' + name + '_emb" type="audio/x-pn-realaudio-plugin" src="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '" controls="ControlPanel" width="240" height="36" pluginspage="http://www.real.com/international/player/" console="' + name + '"></embed>';
			content += '</object>';
		}
		else {
			content += '<object id="' + name + '" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="240" height="45">';
			content += '<param name="src" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '">';
			content += '<param name="controls" value="ControlPanel">';	
			content += '<param name="console" value="' + name + '">';
			content += '<param name="autostart" value="false">';
			content += '<embed id="' + name + '_emb" type="audio/x-pn-realaudio-plugin" autostart="false" src="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '" controls="ControlPanel" width="240" height="45" pluginspage="http://www.real.com/international/player/" console="' + name + '"></embed>';
			content += '</object>';
		}
	}
	else if (player == "wmp") {
		if (moduleType == moduleTypeConst.VIDEO) {
			content += '<object id="' + name + '" CLASSID="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="240" height="225">'; // 45 px height of chrome
			content += '<param name="URL" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '">';
			//content += '<param name="uiMode" value="mini">';
			content += '<param name="autoStart" value="0">';
			content += '<embed id="' + name + '_emb" autostart="0" ShowPositionControls="1" ShowStatusBar="0" ShowControls="1" type="application/x-mplayer2" src="http://' + location.host + '/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '" width="240" height="225"></embed>';
			content += '</object>';
		}
		else {
			content += '<object id="' + name + '" CLASSID="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="240" height="45">'; // 45 px height of chrome
			content += '<param name="URL" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '">';
			content += '<param name="autoStart" value="0">';
			content += '<embed id="' + name + '_emb" autostart="0" ShowPositionControls="1" ShowStatusBar="0" ShowControls="1" type="application/x-mplayer2" src="http://' + location.host + '/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '" width="240" height="45"></embed>';
			content += '</object>';
		}
		
		content += '<script FOR="m_' + moduleType + '_' + moduleId + '_video" EVENT="Error">';
		content += 'var max = m_' + moduleType + '_' + moduleId + '_video.error.errorCount - 1;';
		content += 'var errItem = m_' + moduleType + '_' + moduleId + '_video.error.item(max);';
		content += 'alert(errItem.errorCode + " - " + errItem.errorDescription);';
		content += '</scr' + 'ipt>'; // otherwise browser thinks script area end is here
	}
	else if (player == "quicktime") {
		if (moduleType == moduleTypeConst.VIDEO) {
			content += '<object id="' + name + '" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="240" height="196">'; // 16 px height for chrome
			content += '<param name="src" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '">';
			// qtsrc ?
			content += '<param name="autoplay" value="false">';
			content += '<param name="scale" value="Aspect">';
			content += '<param name="bgcolor" value="#f3f3f3">';
			content += '<embed scale="Aspect" src="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=3&moduleId=' + moduleId + '" autoplay="false" bgcolor="#f3f3f3" width="240" height="196" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" />';
			content += '</object>';
		}
		else {
			content += '<object id="' + name + '" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="240" height="45">';
			content += '<param name="src" value="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '">';
			content += '<param name="autoplay" value="false">';
			content += '<param name="bgcolor" value="#f3f3f3">';
			content += '<embed src="/fileaccess/' + filename + '?section=Generic&action=FileView&viewtype=inline&moduleType=4&moduleId=' + moduleId + '" autoplay="false" bgcolor="#f3f3f3" width="240" height="45" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" />';
			content += '</object>';
		}
		
		if (window.ActiveXObject) {
			setTimeout("_restoreController('" + name + "')", 1000);
		}
	}
	
	var pluginArea = document.getElementById("m_" + moduleType + "_" + moduleId + "_pluginArea");
	pluginArea.innerHTML = content;
	
}

/**
 * Sometimes QT controller is not displayed on IE
 */
function _restoreController(id) {
	var plugin = document.getElementById(id);
	plugin.SetControllerVisible(true);
}