FloatingBannerのテスト

ClickでFloatingLayerを出すScriptのメモ
参考
http://withd.jp/web/tips/020104/2493.html
http://www.c61.org/wd/080131/sample_02.html

/*****************************************************************
Floating banner test 0.5
2008.7.16
表示するとき>>onclick="ShowContent(true)"
閉じるとき>>onclick="ShowContent(false)"
*****************************************************************/
var idCaller="Right"; //位置を決める時に基準になるDivのID。今回は<div id="Right">の左側につくようにした
var swfPath="FloatingBanner.swf"; //HTMLからのSWFのパス
var contentWidth=640; //SWFのWidth
var contentHeight=480; //SWFのHeight
var idOverlay="flashcontent"; //SWFのコンテナ用DivのID

var overlay; //生成したDivエレメントへの参照
var nowShowing; //現在表示中のフラグ
/*===================================================================
mode=true>>表示
mode=false>>非表示
*/
function ShowContent(mode){
	if(mode&&!nowShowing){
		//表示
		overlay=document.createElement("div");
		overlay.id=idOverlay;
		//Styleを設定
		$(overlay).css({"zIndex":"1000", "position":"absolute", "width":contentWidth, "height":contentHeight});
		
		SetPosition()
		$(document.body).prepend(overlay);
		CreateSwfObject();
		nowShowing=true;
		
		//Windowサイズの変更時にFlashAreaをReposition
		$(window).bind("resize", SetPosition);
	}else{
		//非表示
		$(overlay).remove();
		nowShowing=false;
		$(window).unbind("resize", SetPosition);
	}
}
/*===================================================================
表示座標を算出&設定
*/
function SetPosition(){
	//基準エレメントの座標値を取得
	var p=$("#"+idCaller).offset();
	var targetX=p.left-contentWidth;
	var targetY=p.top;
	//表示中はアニメーションして移動
	var props={"left":targetX, "top":targetY};
	if(nowShowing){
		$(overlay).animate(props,"fast");
	}else{
		$(overlay).css(props);
	}
}
/*===================================================================
SWFObjectで作成したDIVの中にFlashAreaを生成
*/
function CreateSwfObject(){
	var so = new SWFObject( swfPath, "external_index", contentWidth, contentHeight, "9.0.45.0" );
	so.useExpressInstall( "shared/scripts/com/deconcept/expressinstall.swf" );
	so.addParam( "wmode", "transparent" );
	so.addParam( "allowScriptAccess", "sameDomain" );
	so.addParam( "loop", "false" );
	so.addParam( "scale", "noscale" );
	so.addParam( "salign", "tr" );
	
	so.write( "flashcontent" );
}