var donateLayer;
var bottomLayer;

document.write('<div style="position:absolute" id="ekokoro_donate_div"></div><div style="position:absolute" id="ekokoro_bottom_div"></div>');

function loadPage() {
	donateLayer = new BPLayer();
	donateLayer.zIndex = 1;
	donateLayer.swf_url = "http://www.ekokoro.jp/blogtool/floatbp/fullsizefloat.swf";
	donateLayer.layer_name = "ekokoro_donate_div";
	
	donateLayer.flashvars_labels = ["url"];
	donateLayer.flashvars_values = [location.href];

	donateLayer.create();
	donateLayer.setSize(480,480);
	donateLayer.setWindowAlign('right');
	donateLayer.setWindowValign('top');
	
	bottomLayer = new BPLayer();
	bottomLayer.zIndex = 2;
	bottomLayer.swf_url = "http://www.ekokoro.jp/blogtool/floatbp/bottomfloat.swf";
	bottomLayer.layer_name = "ekokoro_bottom_div";
	
	bottomLayer.flashvars_labels = ["url"];
	bottomLayer.flashvars_values = [location.href];

	bottomLayer.create();
	bottomLayer.setSize(460,180);
	bottomLayer.setWindowAlign('left');
	bottomLayer.setWindowValign('bottom');

	if(checkBrowser() == "Safari"){
		window.resizeBy(1,0);
	}
	
	donateLayer.setVisible("visible");
	bottomLayer.setSize(1,1);
}

function resizePage() {
	donateLayer.correctWindowSize();
	donateLayer.setWindowAlign('right');
	donateLayer.setWindowValign('top');
	
	bottomLayer.correctWindowSize();
	bottomLayer.setWindowAlign('left');
	bottomLayer.setWindowValign('bottom');
}

function scrollPage() {
	donateLayer.setWindowAlign('right');
	donateLayer.setWindowValign('top');
	
	bottomLayer.setWindowAlign('left');
	bottomLayer.setWindowValign('bottom');
}

function checkBrowser() {
	var uName = navigator.userAgent;
	if (uName.indexOf("Safari") > -1) return "Safari";
	if (uName.indexOf("MSIE") > -1){
		return "MSIE";
	}
	return "Netscape";
}

if(checkBrowser() != "Safari"){
	document.getElementsByTagName("html")[0].style.overflow = "scroll";

}

eventObserve(window, 'load', loadPage, false);
eventObserve(window, 'resize', resizePage, false);
eventObserve(window, 'scroll', scrollPage, false);


function finishDonateSwf() {
	donateLayer.setVisible("hidden");
	bottomLayer.setSize(460,180);
	thisMovie("ekokoro_bottom_divexternal").runBottomParts();
	resizePage();
}

function hideBottomLayer() {
	bottomLayer.setVisible("hidden");
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}


function BPLayer(){
	this.swf_url = "";
	this.layer_name = "";
	this.xx = 0;
	this.yy = 0;
	this.width = 1;
	this.height = 1;
	this.zIndex = 0;
	this.body = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
	this._oLayer = "";

	this.flashvars_labels = [];
	this.flashvars_values = [];

	this._ww_full_flg = "false";
	this._hh_full_flg = "false";
}

BPLayer.prototype._createFlashVarsValue = function(){
	var value = "browser=" + this._checkBrowser() + "&";
	var flashvars_labels = this.flashvars_labels;
	var flashvars_values = this.flashvars_values;
	for(var i=0; i < flashvars_labels.length; i++){
		value += flashvars_labels[i] + "=" + flashvars_values[i] + "&";
	}
	value = value.substring(0,value.length - 1);
	return value;
};


BPLayer.prototype.create = function(){
	var swf_url = this.swf_url;
	var layer_name = this.layer_name;
	
	var html = "";
	html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" id="'+layer_name+'external" align="middle">';
	html += '<param name="allowScriptAccess" value="always" />';
	if(this.flashvars_labels.length > 0){
		html += '<param name="flashvars" value="' + this._createFlashVarsValue() + '">';
	}

	html += '<param name="movie" value="' + swf_url + '" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="quality" value="high" /><param name="wmode" value="transparent" />';
	html += '<embed src="' + swf_url + '" quality="high" scale="noscale" salign="lt" wmode="transparent" width="100%" height="100%" name="'+layer_name+'external" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"';
	if(this.flashvars_labels.length > 0){
		html += ' flashvars="' + this._createFlashVarsValue() + '"';
	}
	html += '/></object>';
	
	var oLayer = document.getElementById(layer_name);
	oLayer.innerHTML = html;
	
	this._oLayer = oLayer;

};

BPLayer.prototype._checkBrowser = function(){
	var uName = navigator.userAgent;
	if (uName.indexOf("MSIE") > -1){
		return "MSIE";
	}
	return "Netscape";
};

BPLayer.prototype.setSize = function(ww,hh){
	var browser = this._checkBrowser();
	if(ww == 'full'){
		this._ww_full_flg = "true";
		if(browser == "MSIE"){
			this.width = this.body.clientWidth;
		}else {
			this.width = window.innerWidth - 17;
		}
	}else{
		this._ww_full_flg = "false";
		this.width = ww;
	}

	if(hh == 'full'){
		this._hh_full_flg = "true";
		if(browser == "MSIE"){
			this.height = this.body.clientHeight;
		}else if(browser == "Netscape"){
			this.height = window.innerHeight-17;
		}else{
			this.height = window.innerHeight;
		}
	}else{
		this._hh_full_flg = "false";
		this.height = hh;
	}
	this._oLayer.style.width = this.width + 'px';
	this._oLayer.style.height = this.height + 'px';
};


BPLayer.prototype.setPos = function(xx,yy){
	var browser = this._checkBrowser();

	this.xx = xx;
	this.yy = yy;

	if(browser == "MSIE"){
		this._oLayer.style.left = this.xx + this.body.scrollLeft + 'px';
		this._oLayer.style.top = this.yy + this.body.scrollTop + 'px';
	}else {
		this._oLayer.style.left = this.xx + pageXOffset + 'px';
		this._oLayer.style.top = this.yy + pageYOffset + 'px';
	}

};


BPLayer.prototype.setdPos = function(d_xx,d_yy){

	this.xx += d_xx;
	this.yy += d_yy;

	this.setPos(this.xx,this.yy);
};

BPLayer.prototype.setWindowAlign = function(str){
	var browser = this._checkBrowser() ;
	if(str == 'right'){
		if(browser == "MSIE"){
			this.xx = this.body.clientWidth - this.width;
		}else {
			this.xx = window.innerWidth - this.width;
			this.xx -= 17;
		}
	}else{
		if(browser == "MSIE"){
			this.xx = 0;
		}else {
			this.xx = 0;
		}
	}


	this.setPos(this.xx,this.yy);
};

BPLayer.prototype.setWindowValign = function(str){
	var browser = this._checkBrowser();
	if(str == 'bottom'){
		if(browser == "MSIE"){
			this.yy = this.body.clientHeight - this.height;
		}else {
			this.yy = window.innerHeight - this.height;
			this.yy -= 17;
		}
	}else{
		if(browser == "MSIE"){
			this.yy = 0;
		}else {
			this.yy = 0;
		}
	}
	this.setPos(this.xx,this.yy);
};

BPLayer.prototype.setVisible = function(str){
	this._oLayer.style.visibility = str;
};

BPLayer.prototype.correctWindowSize = function(str){
	if(this._ww_full_flg == "true" && this._hh_full_flg == "true"){
		this.setSize("full","full");
	}
	else if(this._ww_full_flg == "true"){
		this.setSize("full",this.height);
	}
	else if(this._hh_full_flg == "true"){
		this.setSize(this.width,"full");
	}
};

function eventObserve(obj,e, func, bool){
	if (obj.addEventListener){
		obj.addEventListener(e, func, bool)
	}else if (obj.attachEvent){
		obj.attachEvent("on" + e, func)
	}
}


