// UA判別 --------------------------------------------

var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
if (isOpera) isIE = false;
var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);

var $f = 0;

// フォームに出力 -------------------------------

function setPosition() {

var PageSizeY = getPageSize().y;
var ScrollY = getScrollPosition().y;
var ScreenY = getScreenSize().y;

if(PageSizeY) {
if(PageSizeY <= ScrollY + ScreenY ) {
	if($f == 0 ) {
		parent.window.showCloseButton();
		$f = 1
		}
	} else if ( $f == 1) {
		parent.window.hideCloseButton();
		$f = 0
	}
}
	setTimeout( function(){setPosition()},500 );
}



// 表示ページサイズ -------------------------------

function getPageSize() {
	var obj = new Object();

	if (isIE) {
		obj.x = document.documentElement.scrollWidth || document.body.scrollWidth;
		obj.y = document.documentElement.scrollHeight || document.body.scrollHeight;
	} else if (!isSafari && !isOpera) {
		obj.x = document.body.scrollWidth || document.documentElement.scrollWidth || document.body.clientWidth + window.scrollMaxX || document.documentElement.clientWidth + window.scrollMaxX;
		obj.y = document.body.scrollHeight || document.documentElement.scrollHeight || document.body.clientHeight + window.scrollMaxY || document.documentElement.clientHeight + window.scrollMaxY;
	}
	else {
		obj.x = document.documentElement.scrollWidth;
		obj.y = document.documentElement.scrollHeight;
	}
	
	return obj;
}

// スクロール量 ---------------------------------

function getScrollPosition() {
	var obj = new Object();

	obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	obj.y = document.documentElement.scrollTop  || document.body.scrollTop;

	if(isSafari){
//		obj.x = document.body.scrollLeft;
//		obj.y = document.body.scrollTop;
	}
	
	return obj;
}

// 表示領域サイズ -------------------------------

function getScreenSize() {
	var obj = new Object();

	if (!isSafari && !isOpera) {
		obj.x = document.documentElement.clientWidth  || document.body.clientWidth  || document.body.scrollWidth;
		obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
	}
	else {
		obj.x = window.innerWidth;
		obj.y = window.innerHeight;
	}
	
	obj.mx = parseInt((obj.x)/2);
	obj.my = parseInt((obj.y)/2);

	return obj;
}

setPosition();
