﻿// 플래시 파일 불러오는 스크립트

function EmbedObject() {
// Object
	var objectTAG		= new String;
	//SWF
	var classIDSWF		= 'CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000';
	var codeBaseSWF		= 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab';

	//WMP
	var classIDWMP		= 'CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95';
	var codeBaseWMP		= 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab';

// Param
	var parameterTAG	= new String;

// Embed
	var embedTAG		= new String;

	// SWF
	var typeSWF			= 'application/x-shockwave-flash';
	var pluginsPageSWF	= 'http://www.macromedia.com/go/getflashplayer';

	// WMP
	var typeWMP			= 'application/x-mplayer2';
	var pluginsPageWMP	= 'http://www.microsoft.com/Windows/MediaPlayer/';

    this.embedSWF		= embedSWF;
    this.embedWMP		= embedWMP;
	this.editObject		= editObject;
    this.editParam		= editParam;
    this.editEmbed		= editEmbed;
    this.displayHTML	= displayHTML;
	this.showembedTAG	= showembedTAG;

	// Flash 넣는 함수
	function embedSWF(srcSWF, widthSWF, heightSWF, objectID, alignSWF, verSWF) {

		//Script init
		objectTAG += "<OBJECT ";
		embedTAG += "<EMBED ";

		//Class ID
		objectTAG += "classid='"+ classIDSWF +"' ";

		//CodeBase, Version
		(verSWF) ? codeBaseSWF += "#version="+ verSWF : codeBaseSWF += "#version=8,0,0,0"
		this.editObject('codebase',codeBaseSWF);


		// Align
		if (alignSWF)	{
			this.editObject('align',alignSWF);
		}

		// ID
		if (objectID)	{
			this.editObject('id',objectID);
			this.editEmbed('name',objectID);
		}

		//Parameter
		this.editParam('quality','high');
		this.editParam('movie',srcSWF,'Param');

		//Embed tag
		this.editEmbed('src',srcSWF);
		this.editEmbed('pluginspage',pluginsPageSWF);
		this.editEmbed('type',typeSWF);


		if (widthSWF)	{
			this.editObject('width',widthSWF);
			this.editEmbed('width',widthSWF);
		}

		if (heightSWF)	{
			this.editObject('height',heightSWF);
			this.editEmbed('height',heightSWF);
		}
	}

	// Media Player 넣는 함수
	function embedWMP(srcWMP, widthWMP, heightWMP, objectID, alignWMP, verWMP) {

		//Script init
		objectTAG += "<OBJECT ";
		embedTAG += "<EMBED ";

		//Class ID
		objectTAG += "classid='"+ classIDWMP +"' ";

		//CodeBase, Version
		(verWMP) ? codeBaseWMP += "#version="+ verWMP : codeBaseWMP += "#version=5,1,52,701"
		this.editObject('codebase',codeBaseWMP);

		//Type
		this.editObject('type','application/x-oleobject');

		// ID
		if (objectID)	{
			this.editObject('id',objectID);
			this.editEmbed('name',objectID);
		}

		// Align
		if (alignWMP)	{
			this.editObject('align',alignWMP);
		}

		//Parameter
		this.editParam('FileName',srcWMP,'Param');

		//Embed tag
		this.editEmbed('src',srcWMP);
		this.editEmbed('pluginspage',pluginsPageWMP);
		this.editEmbed('type',typeWMP);


		if (widthWMP)	{
			this.editObject('width',widthWMP);
			this.editEmbed('width',widthWMP);
		}

		if (heightWMP)	{
			this.editObject('height',heightWMP);
			this.editEmbed('height',heightWMP);
		}
	}

	//Object Tag
	function editObject(name, value) {
		objectTAG += " " + name + "='" + value + "' ";
	}

	//Parameter Tag
	function editParam(name, value, target) {

		parameterTAG += "<PARAM NAME='"+name+"' VALUE='"+value+"'>\n";

		// editParam함수에서 Object 및 Embed에 한꺼번에 집어넣음.
		if (!target) {
			editEmbed(name, value);
		}
	}
	//Embed Tag
	function editEmbed(name, value) {
		embedTAG += " " + name + "='" + value + "' ";
	}

	//HTML에 뿌려주는 함수
	function displayHTML() {
		objectTAG	+= ">\n";
		embedTAG	+= "></EMBED>\n";
		document.write(objectTAG);
		document.write(parameterTAG);
		document.write(embedTAG);
		document.write("</OBJECT>");
//		alert(objectTAG + parameterTAG + embedTAG);
	}

	function showembedTAG() {
		alert(objectTAG + parameterTAG + embedTAG);
	}
}