var putCM03 = {	
	
	conf : [
		//e.g.
		//{targetId:"#div1",filePath:"swf/movie.swf",width:500,height:200,ver:7},
		  {targetId:"#uv", filePath:"swf/uv.swf", width:251, height:214, ver:7}
	],
	
	hideFlashArea : function(){
		var i, selectorText="";
		for( i = 0; i < putCM03.conf.length; i++ ){
			selectorText += putCM03.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 < putCM03.conf.length; i++){
			putArea = document.getElementById(putCM03.conf[i].targetId.slice(1));
			if((putCM03.getFlashVer()>=putCM03.conf[i].ver)&&putArea){
				//put swf
				putArea.innerHTML = ('<object data="'+putCM03.conf[i].filePath+'" type="application/x-shockwave-flash" width="'+putCM03.conf[i].width+'" height="'+putCM03.conf[i].height+'"><param name="movie" value="'+putCM03.conf[i].filePath+'" /></object>');
			}
		}
	},
	
	showFlashArea : function(){
		var i;
		for(i = 0; i < putCM03.conf.length; i++ ){
			document.getElementById(putCM03.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);
		}
	}
}

putCM03.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;
        }
    }
}());