window.onresize = PositionFix;
window.onscroll = PositionFix;
window.onload =  PositionFix;

function PositionFix(){

	
	//document.getElementById('head').style.height = 300px;
	
	var ContentsWidth = 975;
	//var headHEIGHT = document.getElementById('head').style.height;
	var headHEIGHT;
	if(document.getElementById('head')){
		headHEIGHT = 300;
	}else{
		headHEIGHT = 460;
	}
	var footHEIGHT = 400;
	
	//document.write("ƒeƒXƒg = " + document.getElementById('head').style.height);
	
	var Element = document.getElementById('PAGETOP');
	var WT = (document.body.scrollTop || document.documentElement.scrollTop);
	var PGH = (document.body.offsetHeight || document.documentElement.offsetHeight);
	var Win = getWindowSize();
	var MCY = WT + (Win.height / 2)
	
    //Element.style.right = (ContentsWidth + (Win.width - ContentsWidth)) + 'px';
    Element.style.right = ((Win.width - ContentsWidth) / 2) + 'px';
    
    
    if(MCY < headHEIGHT){
		Element.style.top = headHEIGHT + 'px';
    }else if((PGH - footHEIGHT) < MCY){
		Element.style.top = (PGH - footHEIGHT) + 'px';
    }else{
		Element.style.top = MCY + 'px';
    }
    
}

function getWindowSize() {
	var width, height;
	
	if (window.innerHeight) {
		width = window.innerWidth - 20;
		height = window.innerHeight;
		
	} else if (document.documentElement && document.documentElement.clientHeight) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
		
	} else if (document.body) {
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		
	}
	
	return {width: width, height: height};
}
