var putSWF = {
	conf : {
		flashArea :'mainswf', //設置する場所のID名
		file : 'mainvisual.swf', //swfの場所
		width : '900',
		height : '500',
		requiredVer : 8 //プラグインの必要バージョン
	},
	
	hidden : function(){
		//判別完了まで表示しないでおく
		document.write("<style type=\"text/css\">\n");
		document.write("#"+putSWF.conf.flashArea+"{visibility:hidden;}\n");
		document.write("</style>");
	},
	
	check : function(){
		// Flash Player のバージョン判定
		// IE以外でFlash Player のバージョンを取得　変数pluginVerに入る。
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : null;
		if (navigator.mimeTypes["application/x-shockwave-flash"]) {
			pluginVer = parseInt(plugin.description.replace(/Shockwave\sFlash\s/,''));
		}
		// IEの場合、Flash Player のバージョンをvbscriptで取得(IEでnavigator.mimeTypesが使えないため)
		else{
			document.write('<script type="text/vbscript">\n');
			document.write('on error resume next \n');
			document.write('Dim Flash \n');
			document.write('Dim pluginVer \n');
			document.write('Flash=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n');
			document.write('pluginVer=Hex(Int(CreateObject("ShockwaveFlash.ShockwaveFlash").FlashVersion))\n');
			document.writeln('</sc'+'ript>');
			pluginVer = parseInt(pluginVer.replace(/0000$/,''),16);
		}
	},
		
	replaceSWF : function (){
		// Flash Player のバージョンが必要バージョン以上で埋め込み
		if(pluginVer>=putSWF.conf.requiredVer){
			var flashArea = document.getElementById(putSWF.conf.flashArea);
			//put swf
			flashArea.innerHTML = ('<object data=\"'+putSWF.conf.file+'\" type=\"application/x-shockwave-flash\" width=\"'+putSWF.conf.width+'\" height=\"'+putSWF.conf.height+'\" wmode=\"opaque\"><param name=\"movie\" value=\"'+putSWF.conf.file+'\" /><param name=\"wmode\" value=\"opaque\" /></object>');
		}
	},
	
	showFlashArea : function(){
		document.getElementById(putSWF.conf.flashArea).style.visibility = "visible";
	},
	
	start : function(){
		putSWF.hidden();
		putSWF.check();
		
		try {
			window.addEventListener('load', putSWF.replaceSWF, false);
			window.addEventListener('load', putSWF.showFlashArea, false);
		} catch (e) {
			window.attachEvent('onload', putSWF.replaceSWF);
			window.attachEvent('onload', putSWF.showFlashArea);
		}
	}
	
}

putSWF.start();

(function() {

    window.onload   = onWindowResize;
    window.onresize = onWindowResize;

    var FLASH_MIN_WIDTH  = 946;

    function onWindowResize() {
        var window_width =  ( window.innerWidth ) ? window.innerWidth :
                            ( document.documentElement ) ? document.documentElement.clientWidth :
                            ( document.body )            ? document.body.clientWidth : 0;

        var flashwrapper = document.getElementById("mainswf");

        if ( flashwrapper ) {
            var targetWidth = window_width;

            if ( window_width < FLASH_MIN_WIDTH ) {
                targetWidth = FLASH_MIN_WIDTH + "px";
            }
            else {
                targetWidth = "100%";
            }
            flashwrapper.style.width = targetWidth;
        }
    }
}());
