var yomotsuPutSWF = {	
	
	conf : [
		//e.g.
		//{targetId:"#div1",filePath:"swf/movie.swf",width:500,height:200,ver:7},
		  {targetId:"#indexswf", filePath:"main.swf", width:856, height:428, ver:7}
	],
	
	hideFlashArea : function(){
		var i, selectorText="";
		for( i = 0; i < yomotsuPutSWF.conf.length; i++ ){
			selectorText += yomotsuPutSWF.conf[i]["targetId"]+",";
		}
		document.writeln('<style type="text/css">'+selectorText.slice(0,-1)+'{visibility:hidden;}</style>');
	},
	
	getFlashVer : function(){
		var flashVer = 0;
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) {
			flash = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
			if (flash) {
				flashVer = flash.description.match(/(\d+(\.\d+)*) +r(\d+)/);
				if (flashVer) {
					flashVer = flashVer[1] + "." + ((flashVer.length >= 4) ? flashVer[3] : 0);
				}
			}
		}
		else if (typeof(ActiveXObject) == "object" || typeof(ActiveXObject) == "function") {
			try{
				flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				if(flash){
					flashVer = flash.GetVariable("$version");
					flashVer = flashVer.match(/(\d+(\,\d+)+)/)[1].replace(/,/g, ".");
				}
			}catch(e){}
		}
		
		return parseInt(flashVer);
	},
	
	replaceSWF : function (){
		var i, putArea, object, param;
		for(i = 0; i < yomotsuPutSWF.conf.length; i++){
			putArea = document.getElementById(yomotsuPutSWF.conf[i].targetId.slice(1));
			if((yomotsuPutSWF.getFlashVer()>=yomotsuPutSWF.conf[i].ver)&&putArea){
				//put swf
				putArea.innerHTML = ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+yomotsuPutSWF.conf[i].width+'" height="'+yomotsuPutSWF.conf[i].height+'"><param name="movie" value="'+yomotsuPutSWF.conf[i].filePath+'"><param name="quality" value="high"><param name="wmode" value="opaque"><embed src="'+yomotsuPutSWF.conf[i].filePath+'" width="'+yomotsuPutSWF.conf[i].width+'" height="'+yomotsuPutSWF.conf[i].height+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="opaque"></embed></object>');
			}
		}
	},
	
	showFlashArea : function(){
		var i;
		for(i = 0; i < yomotsuPutSWF.conf.length; i++ ){
			document.getElementById(yomotsuPutSWF.conf[i]["targetId"].slice(1)).style.visibility = "visible";
		}
	},
	
	start : function(){
		this.hideFlashArea();
		this.getFlashVer();
		try {
			window.addEventListener('load', this.replaceSWF, false);
			window.addEventListener('load', this.showFlashArea, false);
		} catch (e) {		
			window.attachEvent('onload', this.showFlashArea);
			window.attachEvent('onload', this.replaceSWF);
		}
	}
}

yomotsuPutSWF.start();
