floating = {

	containerID: "floatbox",
	container: null,

	// IE6標準モード
	isIE6CSS: (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false,


	create: function(swf, id, width, height, bgcolor, flashvars) {
		
		this.container = this.getDivContainer();

		var serverName = "/swf/";

		var html ="";

		html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '">';
		html += '<param name="movie" value="' + serverName + '' +  swf + '" />';
		html += '<param name="bgcolor" value="' + bgcolor + '" />';
		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="' + serverName + '' + swf + '" name="' + id + '" width="' + width + '" height="' + height + '" bgcolor="' + bgcolor + '" menu="false" quality="high" allowScriptAccess="always" scale="noscale" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html += '</object>';
		
		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 );

	},


	remove: function() {

		setTimeout("floating.delay()", 1);

	},


	delay: function() {

		this.removeEvent( window, "resize", this.onResizeEventHandler, false );
		//this.removeEvent( window, "scroll", this.onScrollEventHandler, false );

		document.body.removeChild(document.body.firstChild);

		//スクロールを復帰
		document.body.style.overflow = "";
		document.documentElement.style.overflow = ""; 

		this.showHideAllElementByTag("embed", "");
		this.showHideAllElementByTag("object", "");

		//フラッシュ再描画(トップのみ適用)
		if(document.getElementById("flashContents") != null){
			swfobject.embedSWF("./top_flash.swf", "flashContents", "940", "350", "9", "", flashvars, params, attributes);
		}

	},

	getDivContainer: function() {

		this.showHideAllElementByTag("embed", "none");
		this.showHideAllElementByTag("object", "none");

		var container = document.createElement("div");
		container.setAttribute("id", this.containerID);
		container.style.position = "absolute";
		container.style.zIndex = "9999";
		container.style.width = "100%";
		container.style.height = this.getInsideWindowHeight() + "px";
		container.style.top = this.scrollTop() + "px";
		container.style.left = "0px";

		//スクロールを無効
		document.body.style.overflow = "hidden"; 
		document.documentElement.style.overflow = "hidden"; 

		return container;
	
	},
	

	onResizeEventHandler: function() {
		
		floating.container.style.height = floating.getInsideWindowHeight() + "px";
		document.getElementById("floatcontent").style.height = floating.getInsideWindowHeight() + "px";
		
	},
	
	/*
	onScrollEventHandler: function(){

		floating.container.style.top = floating.scrollTop() + "px";
		
	},
	*/



	showHideAllElementByTag: function(tagname, param) {

		var elems  = document.getElementsByTagName(tagname);

		for (var i = 0; i < elems.length; i++) {
			
			elems[i].style.display = param;

			if(param == "none"){

				elems[i].style.visibility = "hidden";

			} else {

				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;

		}

	}


}

/*check url hash for launching floating contents*/

var checkHash = function() {
	var keyword = 'spcontents';
	if(location.hash) {
		var hash = location.hash;
		if(hash.indexOf(keyword) != -1) {
			floating.create('floating.swf', 'floatcontent', '100%', '100%', '#ffffff', '');
			//prevent launching floating contents by click browser history back button.
			location.hash = '';
			return false;
		};
	};
};

window.onload = function() {
	checkHash();
};
