// cjs_swf.js ver0.01 2004-03-12

// [Flash | 2004-03-12]
// -- description
// swf manage object
// -- require
// prototype
// CJS_userAgent (useragent detector object)
// CJS_redirect (redirect manager object)
// -- usage
// 1. create flash and altContent
//    as you like
// 2. write html code
//    write swf definition in html(see [SAMPLE CODE])
// -- proccess flow
// stack swf object
// if flashcanplay
//     show swf
//   else if altContent
//     show altContent
//   else if redirect
//     redirect
//   else
//     do nothing
// else if redirect
//   redirect
// else
//   do nothing
// 
// *if float swf allowed, show objOpener and objFloat
// *if float swf not allowed, show objNormal
// *if float swf not allowed and show objNormal not defined, show altContent or redirect
// *if swf not allowed, show altContent or redirect
// 
// -- sample code
// <script type="text/javascript" language="JavaScript">
// <!--
// var obj = new Object();     //create swf object
// obj.id='id';                //id [default=swfnormal**] **=incremental number
// obj.name='name';            //name for embed
// obj.swf='foo.swf';          //path to swf file [require]
// obj.query='q1=abc&q2=123';  //querystring for swf
// obj.width='200';            //swf width
// obj.height='100';           //swf height
// obj.align='left';           //swf align
// obj.salign='lt';            //swf salign
// obj.scale='showwall';       //swf scale
// obj.quality='high';         //quality for swf
// obj.play='true';            //swf play
// obj.loop='true';            //swf loop
// obj.bgcolor='#ffffff';      //swf bgcolor
// obj.base='???';             //swf base???
// obj.menu='false';           //swf menu [default=false]
// obj.wmode='transparent';    //swf wmode for win ie
// obj.swLiveConnect='false';  //swf swLiveConnect
// obj.contentVersion=6;       //swf version
// obj.codebaseVersion=6;      //swf version for codebase
// obj.altContent='alt html';  //alt content (html)
// obj.redirectURL='red.html'; //redirect URL
// obj.redirectWait=0;         //redirect wait msec [default=1000]
// SWF_doSwf(obj);             //call normal swf write function(with detect)
// //-->
// </script>
// <noscript>alt content (javascript off)</noscript>
function _CJS_swf(pluginVersion){
	this.pluginVersion;
	this.plugin;
	this.pluginspageURL = 'http://www.macromedia.com/go/getflashplayer';
	this.codebaseURL = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab';
	this.writedSwfs = new Array();
	this.redirectWait = 1*1000;

	//plugin detect
	if ((navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash']) ? navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin : 0) {
		var words = navigator.plugins['Shockwave Flash'].description.split(' ');
		for (var i = 0; i < words.length; ++i) {
			if (isNaN(parseInt(words[i]))) continue;
			this.pluginVersion = words[i]; 
		}
	}else if (CJS_userAgent.browser.isIe && CJS_userAgent.os.isWin) { // for win ie
		this.pluginVersion = parseInt(cjs_swfGetPluginVersion(), 16);
	}

	//write swf html
	this.writeSwf = function(obj){
		var urlswf = obj.swf;
		if (obj.query) urlswf += '?' + obj.query;
		document.open();
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + this.codebaseURL + '"');
		document.write(' width="' + obj.width + '" height="' + obj.height + '"');
		if (obj.id)      document.write(' id="' + obj.id + '"');
		if (obj.align)   document.write(' align="' + obj.align + '"');
		document.write('>');
		document.write('<param name="movie" value="' + urlswf + '">');
		if (obj.play)    document.write('<param name="play" value="' + obj.play + '"' + '>');
		if (obj.loop)    document.write('<param name="loop" value="' + obj.loop + '"' + '>');
		if (obj.quality) document.write('<param name="quality" value="' + obj.quality + '">');
		if (obj.bgcolor) document.write('<param name="bgcolor" value="' + obj.bgcolor + '">');
		if (obj.scale)   document.write('<param name="scale" value="' + obj.scale + '"' + '>');
		if (obj.salign)  document.write('<param name="salign" value="' + obj.salign + '"' + '>');
		if (obj.base)    document.write('<param name="base" value="' + obj.base + '"' + '>');
		if (obj.menu)    document.write('<param name="menu" value="' + obj.menu + '"' + '>');
		if (obj.wmode)   document.write('<param name="wmode" value="' + obj.wmode + '"' + '>');
		if (obj.allowScriptAccess)   document.write('<param name="allowScriptAccess" value="' + obj.allowScriptAccess + '"' + '>');
		document.write('<embed src="' + urlswf + '" width="' + obj.width + '" height="' + obj.height + '"');
		if (obj.play)    document.write(' play="' + obj.play + '"');
		if (obj.loop)    document.write(' loop="' + obj.loop + '"');
		if (obj.swLiveConnect) document.write(' swliveconnect="' + obj.swLiveConnect + '"');
		if (obj.quality) document.write(' quality="' + obj.quality + '"');
		if (obj.bgcolor) document.write(' bgcolor="' + obj.bgcolor + '"');
		if (obj.scale)   document.write(' scale="' + obj.scale + '"');
		if (obj.align)   document.write(' align="' + obj.align + '"');
		if (obj.salign)  document.write(' salign="' + obj.salign + '"');
		if (obj.base)    document.write(' base="' + obj.base + '"');
		if (obj.menu)    document.write(' menu="' + obj.menu + '"');
		if (obj.name)    document.write(' name="' + obj.name + '"');
		if (obj.wmode)   document.write(' wmode="' + obj.wmode + '"');
		if (obj.allowScriptAccess)   document.write(' allowScriptAccess="' + obj.allowScriptAccess + '"');
		document.write(' type="application/x-shockwave-flash" pluginspage="'+ this.pluginspageURL +'"><\/embed>');
		document.write('<\/object>');
		document.close();
	}

	//write alt html
	this.writeAlt = function(obj){
		document.open();
		document.write(obj.altContent);
		document.close();
	}

	//redirect
	this.redirect = function (obj){
		if (!obj.redirectWait) obj.redirectWait = this.redirectWait;
		var pfRedirect = cjs_makeRedirect(obj.redirectURL,obj.redirectWait).start();
	}

	//ececute write normal swf(with detect) [NORMAL TYPE]
	this.execute = function(objNormal) {
		var obj = new Object();
		this.writedSwfs.push(obj);
		if (!objNormal.swf) return false;
		if ((!objNormal.contentVersion) ? true : this.pluginVersion >= objNormal.contentVersion) {
			obj.type = 'normal';
			if (!objNormal.id) objNormal.id = 'swfnormal' + this.writedSwfs.length;
			if (!objNormal.menu) objNormal.menu = 'false';
			if (objNormal.codebaseVersion) this.codebaseURL += '#version=' + objNormal.codebaseVersion;
			this.writeSwf(objNormal);
		} else if (objNormal.altContent) {
			objNormal.type = 'alt';
			this.writeAlt(objNormal);
		} else if (objNormal.redirectURL) {
			objNormal.type = 'redirect';
			this.redirect(objNormal);
		}
	}
}
// make swf object
function cjs_makeSwf(){
	return new _CJS_swf;
}

//vbscript for win ie(Function cjs_swfGetPluginVersion)
if (CJS_userAgent.browser.isIe && CJS_userAgent.os.isWin) { // for win ie
	document.open();
	document.write('<script type="text/vbscript">\n');
	document.write('Function cjs_swfGetPluginVersion()\n');
	document.write('on error resume next \n');
	document.write('cjs_swfGetPluginVersion=Left(Hex(Int(CreateObject("ShockwaveFlash.ShockwaveFlash").FlashVersion)),1)\n');
	document.write('End Function\n');
	document.write('<\/script>\n');
	document.close();
}

// make global CJS_swf
var CJS_swf = cjs_makeSwf();
// [/Flash | 2004-03-12]
