var fc_isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var fc_isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var fc_isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

//###################################################################
// ÀÛ ¼º ÀÚ : ¹Ú¼º¿í
// ¼³     ¸í : µ¿¿µ»ó ºä
//###################################################################

function mgameMovie(movieUrl,movieWidth,movieHeight,movieDiv,movieUI,moviePlay) {
	var classId			=	"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6";
	var playUI			=	movieUI ? "none" : "full";		//	½ºÅ©¸° ¸ðµå
	var playMode		=	moviePlay ? "false" : "true";	//	ÀÚµ¿ ÇÃ·¹ÀÌ
	var movieHtml		=	"";	

	movieHtml			+=	'<object width="'+ movieWidth +'" height="'+ movieHeight +'" id="mgamePlayer" classid="'+ classId +'">';
	movieHtml			+=	'	<param name="autostart" value="'+ playMode +'">';
	movieHtml			+=	'	<param name="url" value="'+ movieUrl +'">';
	movieHtml			+=	'	<param name="volume" value="70">';
	movieHtml			+=	'	<param name="showcontrols" value="true">';
	movieHtml			+=	'	<param name="defaultframe" value="content">';
	movieHtml			+=	'	<param name="uiMode" value="'+ playUI +'">';
	movieHtml			+=	'	<param name="enablecontextmenu" value="false">';
	movieHtml			+=	'	<param name="fullscreen" value="false">';
	movieHtml			+=	'	<param name="enabled" value="true">';
	movieHtml			+=	'	<param name="stretchtofit" value="true">';
	movieHtml			+=	'</object>';

	if(movieDiv) {
		document.getElementById(movieDiv).innerHTML	=	movieHtml;
	} else {
		document.write(movieHtml);
	}
}

function viewFlv(sURL, sWidth, sHeight){
//	if(sWidth) sWidth=322;
//	if(sHeight) sHeight=282;

	document.write('<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="'+sWidth+'" height="'+sHeight+'" id="flvplayer" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="'+sURL+'" />');
	document.write('<param name="quality" value="high" />');
	//document.write('<param name="wmode" value="opaque" />');
	document.write('<param name="allowFullScreen" value="true" />');
	document.write('<param name="bgcolor" value="#000000" />');
	document.write('<embed src="'+sURL+'" quality="high" bgcolor="#0000000" width="'+sWidth+'" height="'+sHeight+'"  name="20070726_flvplayer" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"  pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');

}

function  viewMediaPlayer(sDiv, sURL, sId, sCid, sWidth , sHeight,sOrder){

	var codeBase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112";
	var pluginsPage = "application/x-oleobject";
	var embedType = "application/x-mplayer2";
	var pluginsPage = "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/";

	var myObjectElement = document.createElement("<OBJECT WIDTH=\""+ sWidth + "\" HEIGHT=\""+ sHeight  + "\" ID=\"" + sId + "\" name=\"" + sId + "\" CLASSID=\"" + sCid + "\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"" + pluginsPage + "\" CODEBASE=\""+ codeBase + "\" VIEWASTEXT></OBJECT>");

	myObjectElement.appendChild(document.createElement("<PARAM NAME=\"filename\" VALUE=\"" + sURL + "\">"));

	if(sOrder) {
		var arrayTemp = sOrder.split("|");
		var arrayOne;

		for (var i=0; i< arrayTemp.length ; i++)
		{
			if(arrayTemp[i]) {
				arrayOne = arrayTemp[i].split("=");

				myObjectElement.appendChild(document.createElement("<PARAM NAME=\""+ arrayOne[0] + "\" VALUE=\""+ arrayOne[1] + "\">"));
			}
		}
	}

	document.getElementById(sDiv).appendChild(myObjectElement);
}


function  viewMediaPlayer2(sDiv, sURL, sId, sCid, sWidth , sHeight,sOrder){

	var codeBase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112";
	var pluginsPage = "application/x-oleobject";
	var embedType = "application/x-mplayer2";
	var pluginsPage = "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/";

	var MediaHTML ;
	MediaHTML = "<OBJECT WIDTH=\""+ sWidth + "\" HEIGHT=\""+ sHeight  + "\" ID=\"" + sId + "\" name=\"" + sId + "\" CLASSID=\"" + sCid + "\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"" + pluginsPage + "\" CODEBASE=\""+ codeBase + "\" VIEWASTEXT><PARAM NAME=\"filename\" VALUE=\"" + sURL + "\">";

	if(sOrder) {
		var arrayTemp = sOrder.split("|");
		var arrayOne;

		for (var i=0; i< arrayTemp.length ; i++)
		{
			if(arrayTemp[i]) {
				arrayOne = arrayTemp[i].split("=");
				MediaHTML += "<PARAM NAME=\""+ arrayOne[0] + "\" VALUE=\""+ arrayOne[1] + "\">";
			}
		}
	}
	MediaHTML += "</OBJECT>";
	document.getElementById(sDiv).innerHTML = MediaHTML;
}


//###################################################################
// ÇÔ ¼ö ¸í : mgameDivMove()
// ÀÛ ¼º ÀÚ : ¹Ú¼º¿í
// ¼³     ¸í : µ¿¿µ»ó Å×µÎ¸® Á¦°Å
//###################################################################
function mgameDivMove(div) {
	document.getElementById(div).innerHTML	=	document.getElementById(div).innerHTML;
}

function  viewFlashmedia(sDiv, sURL, sId, sCid, sWidth , sHeight, sAlign, sWmode, sBgcolor, sOrder){

	var codeBase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
	var embedType = "application/x-shockwave-flash";
	var pluginsPage = "http://www.macromedia.com/go/getflashplayer";

	var flashHTML = "";
	flashHTML += "<OBJECT CLASSID=\""+ sCid +"\" CODEBASE=\""+ codeBase +"\" WIDTH=\""+ sWidth +"\" HEIGHT=\""+ sHeight +"\" ID=\"" + sId + "\" ALIGN=\"" + sAlign + "\">";
	flashHTML += "<PARAM NAME=\"movie\" VALUE=\"" + sURL + "\">";
	flashHTML += "<PARAM NAME=\"quality\" VALUE=\"high\">";
	flashHTML += "<PARAM NAME=\"allowScriptAccess\" VALUE=\"always\">";
	if(sWmode) flashHTML += "<PARAM NAME=\"wmode\" VALUE=\""+ sWmode + "\">";
	if(sBgcolor) flashHTML += "<PARAM NAME=\"bgcolor\" VALUE=\""+ sBgcolor + "\">";
	flashHTML += "<PARAM NAME=\"flashvars\" VALUE=\"linkSong=http://image.mgame.com/mgamezzang/games/yulgang_2007/bukhae/20071224_bukhae_bgm.mp3\">";
	if(sOrder) {
		var arrayTemp = sOrder.split("|");
		var arrayOne;

		for (var i=0; i< arrayTemp.length ; i++)
		{
			if(arrayTemp[i]) {
				arrayOne = arrayTemp[i].split("=");


				if(arrayOne.length > 2) {
					var arrayValue = "";

					arrayValue += arrayTemp[i].replace(arrayOne[0] + "=","");
				}
				else {
					arrayValue = arrayOne[1];
				}

				flashHTML += "<PARAM NAME=\""+ arrayOne[0] + "\" VALUE=\""+ arrayValue + "\">";
			}
		}
	}
	flashHTML += "<EMBED SRC=\""+ sURL + "\" QUALITY=\"high\" WMODE=\"" + sWmode + "\" BGCOLOR=\"" + sBgcolor + "\"  WIDTH=\""+ sWidth +"\" HEIGHT=\""+ sHeight +"\" NAME=\"" + sId + "\" ALIGN=\"" + sAlign + "\"TYPE=\"" + embedType + "\" flashvars=\"linkSong=http://image.mgame.com/mgamezzang/games/yulgang_2007/bukhae/20071224_bukhae_bgm.mp3\" PLUGINSPAGE=\"" + pluginsPage + "\" />";
	flashHTML += "</OBJECT>";
	document.getElementById(sDiv).innerHTML = flashHTML;
}




//###################################################################
// ÀÛ ¼º ÀÚ : ¼Û´ö¿ë
// ¼³     ¸í : ÇÃ·¡½¬ ºä
//###################################################################

function checkFlashPlayerVersion(){
	var _version;
	var _e;
	try {
		var _axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.5");
		_version = _axo.GetVariable("$version");
	} catch (_e) {
		_version = -1;
	}
	return _version;
}

function showFlash(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_){
	document.write(returnFlashContents(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_));
}

function showFlash_div(_divid,_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_){
	_object = returnFlashContents(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_);
	document.getElementById(_divid).innerHTML = _object;
}

function returnFlashContents(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_){
	_wmode_ = (_wmode_ == undefined)? "transparent" : _wmode_;
	_bgColor_ = (_bgColor_ == undefined)? "#000000" : _bgColor_;
	
	if(fc_isIE && fc_isWin && !fc_isOpera){
		_object_ ='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+_width_+'" height="'+_height_+'" id="'+_flashID_+'" align="middle">';
		_object_ += '<param name="allowScriptAccess" value="always" />';
		_object_ += '<param name="quality" value="high" />'; 
		_object_ += '<param name="movie" value="'+_swfURL_+'" />';
		_object_ += '<param name="wmode" value="'+_wmode_+'" />'; 
		_object_ += '<param name="bgcolor" value="'+_bgColor_+'" />'; 
		_object_ += '<param name="FlashVars" value="'+_flashVars_+'">';
		//_object_ += '<param name="scale" value="noscale">';
		_object_ += '</object>';
	}else{
		_object_ = '<embed src="'+_swfURL_+'" quality="high" wmode="'+_wmode_+'" FlashVars="'+_flashVars_+'" bgcolor="'+_bgColor_+'" width="'+_width_+'" height="'+_height_+'" name="'+_flashID_+'" align="middle" allowScriptAccess="always" showLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'; 
	}

	return _object_;
}

function showFlash_div_noscale(_divid,_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_){
	_object = returnFlashContents_noscale(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_);
	//_object = returnFlashContents(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_);
	document.getElementById(_divid).innerHTML = _object;
}

//flash »çÀÌÁî ÀÚµ¿ Á¶ÀýÀÏ¶§ scale ¿É¼ÇÀÌ nocale
function returnFlashContents_noscale(_swfURL_,_flashID_,_width_,_height_,_wmode_,_flashVars_,_bgColor_){
	_wmode_ = (_wmode_ == undefined)? "transparent" : _wmode_;
	_bgColor_ = (_bgColor_ == undefined)? "#000000" : _bgColor_;
	
	if(fc_isIE && fc_isWin && !fc_isOpera){
		_object_ ='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+_width_+'" height="'+_height_+'" id="'+_flashID_+'" align="middle">';
		_object_ += '<param name="allowScriptAccess" value="always" />';
		_object_ += '<param name="quality" value="high" />'; 
		_object_ += '<param name="movie" value="'+_swfURL_+'" />';
		_object_ += '<param name="wmode" value="'+_wmode_+'" />'; 
		_object_ += '<param name="bgcolor" value="'+_bgColor_+'" />'; 
		_object_ += '<param name="FlashVars" value="'+_flashVars_+'">';
		_object_ += '<param name="scale" value="noscale">';
		_object_ += '</object>';
	}else{
		_object_ = '<embed src="'+_swfURL_+'" quality="high" wmode="'+_wmode_+'" FlashVars="'+_flashVars_+'" bgcolor="'+_bgColor_+'" width="'+_width_+'" height="'+_height_+'" name="'+_flashID_+'" align="middle" allowScriptAccess="always" showLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'; 
	}

	return _object_;
}

function findFlashObj(_flashID_){
	var tarObj = fc_isIE ? document.all[_flashID_] : document[_flashID_];	
	return tarObj;
}

function flashExternalCleanup() {
	__flash_unloadHandler = function(){
		externalProbSet = true;
		obj = document.getElementsByTagName('OBJECT');
	  	for (i=0;i<obj.length;i++){
			var theObj = eval(obj[i]);
			theObj.style.display = "none";
	   	for (var prop in theObj){
	    		if (typeof(theObj[prop]) == "function"){
	     			theObj[prop]=null
	    		}
	   	}
	  	}
	}
	if (window.onunload != __flash_unloadHandler){
		__flash_savedUnloadHandler = window.onunload;
		window.onunload = __flash_unloadHandler;
	}
}

function mgameFlash(flashUrl,flashWidth,flashHeight,flashDiv) {
	var flashPath,flashVars;
	var classId			=	"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	var codeBase		=	"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
	var pluginsPage	=	"application/x-shockwave-flash";
	var embedType	=	"application/x-shockwave-flash";
	var pluginsPage	=	"http://www.macromedia.com/go/getflashplayer";
	
	var flashHtml		=	"";

	flashHtml			+=	'<object id="mgameFlashObj" classid="'+ classId +'" codebase="'+ codeBase +'" width="'+ flashWidth +'" height="'+ flashHeight +'">';
	flashHtml			+=	'	<param name="movie" value="' + flashUrl + '" />';
	flashHtml			+=	'	<param name="quality" value="high" />';
	
	// ÀÌ¹ÌÁöÅø ÇÃ·¡½Ã¿¡¼­ °ÅºÎ¹ÝÀÀ... ¤Ñ¤Ñ;
	if(location.href.indexOf("guild.mgame.com") == -1 && location.href.indexOf("blog.mgame.com") == -1) {
		flashHtml		+=	'	<param name="allowScriptAccess" value="always" />';
	}

	flashHtml			+=	'	<param name="wmode" value="transparent" />';
	flashHtml			+=	'	<embed src="'+ flashUrl + '" quality="high" wmode="transparent" width="'+ flashWidth +'" height="'+ flashHeight +'" type="' + embedType + '" pluginspage="' + pluginsPage + '" />';
	flashHtml			+=	'</object>';

	if(flashDiv) {
		document.getElementById(flashDiv).innerHTML	=	flashHtml;
	} else {
		document.write(flashHtml);
	}
}

function getFlashPluginInfo(){
	
	var info = new Object;
	var p    = navigator.plugins;
	var m    = navigator.mimeTypes;
	var f    = null;

	info.installed = false;
	info.version   = -1;
	if (typeof p != "undefined" && p.length) {
		f = p["Shockwave Flash"];
		if (f) {
			info.installed = true;
			if (f.description) {
				info.version = parseFloat(f.description.match(/[0-9.]+/)[0]);
			}
		}
		if (p["Shockwave Flash 2.0"]) {
			info.installed = true;
			info.version   = 2;
		}
	} else if (typeof m != "undefined" && m.length) {
		f = m["application/x-shockwave-flash"];
		info.installed = (f && f.enabledPlugin);
	} else {
		for(var i=9; i > 1; i--) {
			try {
				f = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);

				info.installed = true;
				info.version   = i;
				break;
			} catch(e) {}
		}
	}
	return info;
	
}

window.onbeforeunload=flashExternalCleanup;