//ブラウザーの判定をします。
var checkBrowser = "";
var safariVersionCheck ="";

function getBrowserName()
{
	var UA = navigator.userAgent;
	if(UA.indexOf("Safari")>-1){
		checkBrowser = "Safari"
		if(UA.indexOf("Version/3")>-1){
			safariVersionCheck = "3";
		}else{
			safariVersionCheck = "2";
		}
	}
	if(UA.indexOf("Firefox")>-1){checkBrowser = "Firefox"}
	if(UA.indexOf("MSIE")>-1){checkBrowser = "MSIE"}
}
getBrowserName();


////////////フルフラッシュの表示。//////////////////////////////////////////////////////////////////////
function swfSet(){
	var oLayer = document.createElement('div');
	oLayer.setAttribute('id','LargeSwfID');
	oLayer.style.position = 'absolute';
	oLayer.style.zIndex = 10000;
	oLayer.style.visibility = 'hidden';
	document.body.appendChild(oLayer);
	this.LayerStyleSWF = oLayer;
	
	var largehtml = "";
	largehtml += '<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="100%" height="100%" id="Movie" align="middle"><param name="movie" value="http://www.nifty.com/magazine/blogparts/niftools_blogparts_nifuo/full.swf" /><param name="allowScriptAccess" value="always" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="http://www.nifty.com/magazine/blogparts/niftools_blogparts_nifuo/full.swf" quality="high" bgcolor="#ffffff" width="100%" height="100%" name="Movie" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode= "transparent"/></object>';
	
	document.getElementById("LargeSwfID").innerHTML = largehtml;
}


////////////ウインドウサイズの調整//////////////////////////////////////////////////////////////////////
var flaLayerX;
var flaLayerY;

function setSizeSWF(){
	if(checkBrowser=="MSIE"){
		var rects = document.getElementById("flaLayer").getClientRects();
		flaLayerX = rects[0].left;
		flaLayerY = rects[0].top;
		
		//this.LayerStyleSWF.style.height = (document.documentElement.clientHeight + 300) + 'px';
		//this.LayerStyleSWF.style.width = document.documentElement.clientWidth + 'px';
		//alert(document.documentElement.clientHeight);
		this.LayerStyleSWF.style.height = (document.body.clientHeight + 300) + 'px';
		this.LayerStyleSWF.style.width = document.body.clientWidth + 'px';
		
		setPosSWF();
			
	}else if(checkBrowser=="Safari"){
		flaLayerX = document.getElementById("flaLayer").offsetLeft;
		flaLayerY = document.getElementById("flaLayer").offsetTop;
		this.LayerStyleSWF.style.width = window.innerWidth + 'px';
		this.LayerStyleSWF.style.height = window.innerHeight+300 + 'px';
	}else{
		flaLayerX = document.getElementById("flaLayer").offsetLeft;
		flaLayerY = document.getElementById("flaLayer").offsetTop;
		
		this.LayerStyleSWF.style.width = (window.innerWidth-17) + 'px';
		this.LayerStyleSWF.style.height = (window.innerHeight-17+pageYOffset+293) + 'px';		
	}
};

//setSize(ww,hh);//最初に読み込まれたときの状態。
EventListener(window, 'resize', setSizeSWF);


////////////座標を取得します//////////////////////////////////////////////////////////////////////
var eventXX;
var eventYY;
var pageYY;

function getMouseXY(evt)
{
	if(checkBrowser=="MSIE"){
		eventXX = event.x;
		eventYY = event.y;
	}else if(checkBrowser=="Safari"){
		if(safariVersionCheck == "3"){
			eventXX = event.x;
			eventYY = event.y;
		}else{
			eventXX = event.x;
			eventYY = event.y-pageYOffset;				
		}
	}else{
		pageYY = pageYOffset;
		eventXX = evt.pageX;
		eventYY = evt.pageY;
	}
}

window.document.onmousedown= getMouseXY;


////////////普通のフラッシュの表示//////////////////////////////////////////////////////////////////
function setSmallSWF(){
	var smallhtml = "";	
	smallhtml+='<div id="flaLayer">';
	smallhtml += '<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="150" height="293" id="myMovie" align="middle"><param name="movie" value="http://www.nifty.com/magazine/blogparts/niftools_blogparts_nifuo/index.swf" /><param name="allowScriptAccess" value="always" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="http://www.nifty.com/magazine/blogparts/niftools_blogparts_nifuo/index.swf" quality="high" bgcolor="#ffffff" width="150" height="293" name="myMovie" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode= "transparent"/></object>';
	smallhtml+='</div>';
	document.write(smallhtml);
}

setSmallSWF();

//位置を決める

function setPosSWF(){
	if(checkBrowser=="MSIE"){
		this.LayerStyleSWF.style.left = 0 + 'px';
		//alert(document.body.scrollTop);
		if(document.documentElement.scrollTop != 0){
			this.LayerStyleSWF.style.top = document.documentElement.scrollTop-300 + 'px';
		}else if(document.body.scrollTop != 0){
			this.LayerStyleSWF.style.top = document.body.scrollTop-300 + 'px';
		}else{
			this.LayerStyleSWF.style.top = -300 + 'px';
		}
	}else if(checkBrowser=="Safari"){
		this.LayerStyleSWF.style.left = 0 + 'px';
		this.LayerStyleSWF.style.top = pageYOffset-300 + 'px';			
	}else{
		this.LayerStyleSWF.style.left = 0 + 'px';
	}
};


////////////Flashからのアクセス//////////////////////////////////////////////////////////////////////
function divSetXY(){
	var obj = new Object();
	if(checkBrowser=="MSIE"){	
		obj.xxx = flaLayerX-2;
		obj.yyy = flaLayerY-2;
	}else{
		obj.xxx = flaLayerX;
		obj.yyy = flaLayerY;		
	}
	
	return obj;	
}


function swfSetOpen(){
	document.getElementById("LargeSwfID").style.visibility = 'visible';
	this.LayerStyleSWF.style.top = 0 + 'px';
	setSizeSWF();
	setPosSWF();
	
	var obj = new Object();
	if(checkBrowser=="MSIE"){
		obj.xxx = eventXX-2;
		obj.yyy = eventYY-2+300;
	}else if(checkBrowser=="Safari"){
		obj.xxx = eventXX;
		obj.yyy = eventYY+300;
		//alert(eventYY);
	}else{
		obj.xxx = eventXX;
		obj.yyy = eventYY;
		//alert("firefoxにきました");
	}
	
	return obj;
}

function swfSetClose(){
	this.LayerStyleSWF.style.top = 0 + 'px';
	this.LayerStyleSWF.style.left = 0 + 'px';
	document.getElementById("LargeSwfID").style.visibility = 'hidden';
}

function loadSwf(){
	swfSet();
	setSizeSWF();
	setPosSWF();
	this.LayerStyleSWF.style.top = 0 + 'px';
	this.LayerStyleSWF.style.left = 0 + 'px';
}

EventListener(window, 'load', loadSwf);



//イベントの設定。IEのときattachEvent。FirefoxのときaddEventListener。
function EventListener(target, type, func) {
  if(target.attachEvent) {
    target.attachEvent("on" + type, func);
  } else if(target.addEventListener) {
    target.addEventListener(type, func, false);
  }
}

