﻿var dispFlashArea = function(fparam) {

	var obj = gByID("fla_outline_area");
	if (obj) {
		var div = document.createElement("div");
  	div.id = "fla_area";
  	div.innerHTML = "<p>Alternative content</p>";
  	obj.appendChild(div);
	}

	var f_Id = (fparam.flaId == null ? "fla_id" : fparam.flaId);

	var attributes = {
		id:f_Id,
		style:"position: absolute;Z-INDEX: 20;" + "top:" + fparam.posY() + "px;" + "left:" + fparam.posX() + "px;"
	};

	var flashvars = {
		loadtype:(fparam.loadtype == null ? "amazon_wish" : fparam.loadtype),
		item_maxcnt:fparam.maxcnt ,
		aso_id:fparam.aso,
		wlist_id:(fparam.wish == null ? "" : fparam.wish),
		flashWidth:fparam.flaW,
		flashHeight:fparam.flaH,
		circleWidth:fparam.cirW,
		circleHeight:fparam.cirH,
		itemDownRange:fparam.itemDr,
		item_speed:fparam.atsp,
		autostart:fparam.atst,
		img_maxsize:fparam.imgMs,
		iquality:(fparam.imgq == null ? "midium" : fparam.imgq),
		bgColor_mode:"transparent",
		browseNode:(fparam.brnode == null ? "" : fparam.brnode),
		fla_id:f_Id
	};
	var params = {
		quality: "high",
		wmode:"transparent",
		swLiveConnect:"true"
	};

	swfobject.embedSWF("http://andre-garden.com/amzring_link/flash/"+ fparam.flaH +"/rolling_amz_items_h"+ fparam.flaH +".swf", "fla_area", fparam.flaW, String(fparam.flaH), "9.0.0","swfobj/expressInstall.swf", flashvars, params, attributes);

}

var closeFlashArea = function(id) {
	var obj = gByID(id);
	if (obj) {
		var parent = obj.parentNode;
		if (parent)  
        parent.removeChild( obj );
	} else {
		var fla_out = gByID("fla_outline_area");
		if (fla_out)
			while (fla_out.firstChild)
    		fla_out.removeChild( fla_out.lastChild );
	}
}

var getPosX = function(xValue, fWidth) {
  if (xValue == "CENTER") {
		return (getBrowserWidth() - fWidth) / 2; 
	} else 
		return xValue;
}

var getPosY = function(yValue, fHeight, link_id) {
  if (yValue == "CENTER") {
		return getBrowserHeight() / 2; 
	} else if (yValue == "ONLINK") {
	  var link_div = gByID(link_id);
		if (link_div != null) {
			var pos = getPosition(link_div); 
  		return pos.y - fHeight;
		} else
  		return 0;
	} else
		return yValue;
}

function getIdSrcString () { 
	var d = new Date();
	return d.getTime().toString();
}

var id_src_string = getIdSrcString();

function getId(div_id) {
	if (!div_id)
		div_id = "fla_id_" + id_src_string;
	return div_id;
}

function getLinkId(link_id) {
	if (!link_id)
		link_id = "link_id_" + id_src_string;
	return link_id;
}

function getLinkAreaId(linkArea_id) 
{
	if (!linkArea_id)
		linkArea_id = "linkArea_id_" + id_src_string;
	return linkArea_id;
}

function gByID(id) 
{
  var o = document.getElementById(id);
	return o;
}

//--from http://weblibrary.s224.xrea.com/weblog/webdesign/javascript/javascript_3.html
var getBrowserWidth = function() {  
  if ( window.innerWidth ) { return window.innerWidth; }  
  else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }  
  else if ( document.body ) { return document.body.clientWidth; }  
  return 0;  
}

var getBrowserHeight = function() {  
  if ( window.innerHeight ) { return window.innerHeight; }  
  else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }  
  else if ( document.body ) { return document.body.clientHeight; }  
  return 0;  
}

//--from http://hkom.blog1.fc2.com/blog-entry-503.html
//必要となるGlobal変数の定義
// 間違いのないように全文字列を小文字に変換
var agt = navigator.userAgent.toLowerCase();
var is_ie　 = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);

　//要素のスタイル属性を取得する関数
var getElementStyle = function (targetElm,IEStyleProp,CSSStyleProp) {
　var elem = targetElm;
　if (elem.currentStyle) {
　　return elem.currentStyle[IEStyleProp];
　} else if (window.getComputedStyle) {
　　var compStyle = window.getComputedStyle(elem,"");
　　return compStyle.getPropertyValue(CSSStyleProp);
　}
}//---End Function

var getPosition = function (that) {
　var targetEle = that;　　　//thatは位置を取得したい要素Object
　var pos = new function(){ this.x = 0; this.y = 0; }
　while( targetEle ){
　　pos.x += targetEle.offsetLeft; 
　　pos.y += targetEle.offsetTop; 
　　targetEle = targetEle.offsetParent;
　　　//IEの補正：上記計算で無視されてしまう各親要素のborder幅を加算
　　if ((targetEle) && (is_ie)) {
　　　pos.x += (parseInt(getElementStyle(targetEle,"borderLeftWidth","border-left-width")) || 0);
　　　pos.y += (parseInt(getElementStyle(targetEle,"borderTopWidth","border-top-width")) || 0);
　　}
　}
　　//geckoの補正：カウントしないbody部border幅をマイナスしてしまうので２倍して加算
　if (is_gecko) {
　　　//以下の部分でbody部を取得し、borderの減算を補正する。
　　var bd = document.getElementsByTagName("BODY")[0];　　//body部を取得
　　pos.x += 2*(parseInt(getElementStyle(bd,"borderLeftWidth","border-left-width")) || 0);
　　pos.y += 2*(parseInt(getElementStyle(bd,"borderTopWidth","border-top-width")) || 0);
　}
　return pos;
}//---End Function

