/*************************************

	レイヤーでFlashを表示する
	
	【　注意事項　】
		IE６ではレイヤーより前にプルダウンが表示されてしまうため、
		プルダウンを消す処理が入っている。

*************************************/
floating = {
	
	containerID: "floatbox",
	container: null,

	bScroller:false,
	bSelect:false,

	// IE6標準モード
	isIE6CSS: (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false,
	
	/***********************************
	***********************************/
	create: function(swf, id, width, height, bgcolor, flashvars, selectbox, scroller ) {	
		
		this.bSelect 	= selectbox;
		this.bScroller 	= scroller;


		if( this.bSelect )
			this.hideSelectBox();
		if( this.bScroller )
			this.visibleScroll( false );

		//
		this.container = this.getDivContainer();
		var html ="";
//		html += '<div>';
//		html += '<iframe src="' + swf + '" width="100%" height="100%" allowtransparency="true">'
		html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '">';
		html += '<param name="movie" value="' +  swf + '" />';
		html += '<param name="bgcolor" value="' + bgcolor + '" />';
		html += '<param name="FlashVars" value="' + flashvars + '" />';
		html += '<param name="menu" value="false" />';
		html += '<param name="quality" value="high" />';
		html += '<param name="scale" value="noscale" />';
		html += '<param name="wmode" value="transparent" />';
		html += '<param name="allowScriptAccess" value="always" />';
		html += '<embed src="' + swf + '" name="' + id + '" width="' + width + '" height="' + height + '" bgcolor="' + bgcolor + '" FlashVars="' + flashvars + '" menu="false" quality="high" allowScriptAccess="always" scale="noscale" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html += '</object>';
//		html += '</iframe>';
//		html += '</div>';

/*

		html += '<div id="flashcontent">';
		html += '	<strong>Flash Playerを最新のバージョンにアップグレードしてください。</strong>';
		html += '</div>';
		html += '<script type="text/javascript">';
		html += '	var so = new SWFObject("shell.swf", "shell", "100%", "100%", "8", "#FFFFFF", true );';
		html += '	so.setAttribute("xiRedirectUrl", "http://www.example.com/upgradefinished.html");';
		html += '	so.useExpressInstall("./plugins/helper/playerProductInstall.swf");

		html += '	so.addParam( "quality", "best" );';
		html += '	so.addParam( "menu", "false" );';
		html += '	so.addParam( "align", "middle" );';
		html += '	so.addParam( "salign", "TL" );';
		html += '	so.addParam( "scale", "noscale" );';
		html += '	so.addParam( "allowScriptAccess", "always" );';
		html += '	so.addParam( "name", "shell" );';
		html += '	so.addParam( "base", "." );';
		html += '	so.addVariable("FlashVars", getQueryParamValue( "./xml/config_site.xml" ) );';
		html += '	so.write('flashcontent');';

		html += '</script>';
		html += '<noscript>';
		html += '	この Web サイトは、JavaScriptの使用が有効になっている必要があります。';
		html += '	お使いのブラウザの設定でJavaScriptの使用を有効にしてください。';
		html += '  	<a href="http://www.adobe.com/go/getflash/">Get Flash</a>';
		html += '</noscript>';

*/

		this.container.innerHTML = html;
		
		document.body.insertBefore(this.container, document.body.firstChild);
		
		this.addEvent( window, "resize", this.onResizeEventHandler, false );
		this.addEvent( window, "scroll", this.onScrollEventHandler, false );

		//flash 領域が描画されるまで swf が実行されない。
		//したのほうにあったり、スクロールしててリロードして flash のレイヤが一番上にあったりすると swf が実行されない。
		this.onScrollEventHandler();

	},
	
	/*********************************
		削除
	**********************************/
	remove: function() {
		
		setTimeout("floating.delay()", 1);
	
	},
	delay: function() {

		if( this.bSelect )
			this.showSelectBox();			//プルダウン表示
		if( this.bScroller )
			this.visibleScroll( true );		//スクロール表示

		this.removeEvent( window, "resize", this.onResizeEventHandler, false );
		this.removeEvent( window, "scroll", this.onScrollEventHandler, false );		
		
		document.body.removeChild(document.body.firstChild);
		
		this.showHideAllElementByTag("embed", "visible");
		this.showHideAllElementByTag("object", "visible");
	
	},	
	getDivContainer: function() {
		
		this.showHideAllElementByTag("embed", "hidden");
		this.showHideAllElementByTag("object", "hidden");
		
		var container = document.createElement("div");
		container.setAttribute("id", this.containerID);
		container.style.position 	= "absolute";
		container.style.zIndex 		= "999";
		container.style.width 		= "100%";
		container.style.height 		= this.getInsideWindowHeight() + "px";
		container.style.top 		= "0px";
		container.style.left 		= "0px";
		container.style.visibility 	= "visible";

		return container;
	
	},
	

	onResizeEventHandler: function() {
		
		floating.container.style.height = floating.getInsideWindowHeight() + "px";
		
	},
	
	
	onScrollEventHandler: function(){

		floating.container.style.top = floating.scrollTop() + "px";
		
	},
		
	
	
	showHideAllElementByTag: function(tagname, visible) {
		
		var elems  = document.getElementsByTagName(tagname);
		
		for (var i = 0; i < elems.length; i++) {
			
			elems[i].style.visibility = visible;
		
		}
		
	},	
	
	
	getInsideWindowWidth: function() {
		
		if (window.innerWidth) {
			
			return window.innerWidth;
			
		} else if (this.isIE6CSS) {
			
			return document.documentElement.clientWidth;
			
		} else if (document.body && document.body.clientWidth) {
			
			return document.body.clientWidth;
			
		}
		
		return 0;
	
	},
	
	
	getInsideWindowHeight: function() {
		
		if (window.innerHeight) {
			
			return window.innerHeight;
			
		} else if (this.isIE6CSS) {
			
			return document.documentElement.clientHeight;
			
		} else if (document.body && document.body.clientHeight) {
			
			return document.body.clientHeight;
			
		}
		
		return 0;
	
	},
	
	
	scrollTop: function() {
		
		if(window.scrollY) return window.scrollY;
		if(window.pageYOffset) return window.pageYOffset;
		if(document.documentElement && document.documentElement.scrollTop) {
			
			return document.documentElement.scrollTop;
			
		} else if(document.body && document.body.scrollTop) {
			
			return document.body.scrollTop;
			
		}		  
		  
		return 0;
	
	},
	
	
	addEvent: function(elm, evtType, fn, useCapture) {
	
		if (elm.addEventListener) {
	
			elm.addEventListener(evtType, fn, useCapture);
			return true;
	
		} else if (elm.attachEvent) {
	
			var r = elm.attachEvent("on" + evtType, fn);
			return r;
	
		} else {
	
			elm["on" + evtType]=fn;
	
		}
		
	},
	
	
	removeEvent: function(elm, evtType, fn, useCapture) {
	
		if (elm.removeEventListener) {
	
			elm.removeEventListener(evtType, fn, useCapture);
			return true;
	
		} else if (elm.detachEvent) {
	
			var r = elm.detachEvent("on" + evtType, fn);
			return r;
	
		} else {
	
			elm["on" + evtType] = null;
	
		}
		
	},	

	/********************************
		IE6かチェック
	********************************/
	isIE6: function(){   
	    if (typeof document.body.style.maxHeight == "undefined"){   
	        return true;   
	    }   
	    return false;   
	},   
	/***************************************
		プルダウン非表示
	*****************************************/
	hideSelectBox: function(){   

		//thickbox
		if( typeof document.body.style.maxHeight === "undefined" ) {//if IE 6

			//すべてのオブジェクトにＣＳＳのプロパティを設定
			$("body","html").css({height: "100%", width: "100%"});
			//すべてのオブジェクトにＣＳＳのプロパティを設定
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {	//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
	//			$("#TB_overlay").click(tb_remove);
			}
		}
/*
		// IE6の場合   
		if(this.isIE6()){   
		        if(document.getElementById("hideSelect")){   
		            return;   
		        }   
		  
		        // iFrameでプルダウンを隠す   
		        var objFrame = document.createElement("iframe");   
		        objFrame.setAttribute("id", "hideSelect");   
		        objFrame.style.cssText = "z-index: 1;"+   
		                                "position: absolute;"+   
		                                "top: 0;"+   
		                                "left: 0;"+   
		                                "background-color: #fff;"+   
		                                "border: none;"+   
		                                "filter: alpha(opacity=0);"+   
		                                "-moz-opacity: 0;"+   
		                                "opacity: 0;"+   
		                                "height: 100%;"+   
		                                "width: 100%;";   
		        var objBody = document.getElementsByTagName("body").item(0);   

			//
			objBody.style.cssText = "overflow: hidden;";
			objBody.style.cssText = "overflow: auto;";

		        objBody.appendChild(objFrame);

		}
*/	  
	    	// テスト
//		setTimeout(this.showSelectBox, 3000);

	},   
	/***************************************
		プルダウン表示
	*****************************************/
	showSelectBox: function(){  

		$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
		$("#TB_load").remove();

		if (typeof document.body.style.maxHeight == "undefined") {//if IE 6

			//すべてのオブジェクトにＣＳＳのプロパティを設定
			$("body","html").css({height: "auto", width: "auto"});
			$("html").css("overflow","");
		}
/*
		//IE6の場合   
		if(this.isIE6()){   
			// iFrameの除去   
			if(document.getElementById("hideSelect")){   
				var objFrame = document.getElementById("hideSelect");   
				var objBody = document.getElementsByTagName("body").item(0);   
				objBody.removeChild(objFrame);   
			}   
		}
*/
	},
	/***************************************
		スクロールの表示・非表示
	****************************************/
	visibleScroll: function( bFlag ){

		//body取得
	        var objBody = document.getElementsByTagName("body").item(0);   
		//
		if( bFlag ){
			objBody.style.cssText = "overflow: auto;";
		}else{
			objBody.style.cssText = "overflow: hidden;";
		}

	}

}
