// JavaScript Document
var leftValue = 0;
var flg = +1;
var sWidth = GetWindowWidthHeight().width;
var value1 = -4063+sWidth;

function imageScroll(){
	if(leftValue < value1){
		flg = -1;
	}else if(leftValue > 0){
		flg = +1;
	}
	leftValue = leftValue-0.2*flg;
	document.getElementById('index_images').style.marginLeft = leftValue+'px';
}

function setImageScroll(){
	moveId = setInterval(imageScroll,1);
}

function deleteImageScroll(){
	clearInterval(moveId);
}

function GetWindowWidthHeight(){
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {'width' : myWidth, 'height' : myHeight};
}

window.onload = function(){
	var sHeight = GetWindowWidthHeight().height;
	var sWidth = GetWindowWidthHeight().width;
	document.getElementsByTagName('h1')[0].style.marginTop = sHeight/2-60+'px';
	var defaultLeftValue = (sWidth-720);

	var profileboxWidth = 95;
	var worksboxWidth = 85;
	var compeboxWidth = 110;
	var publicationboxWidth = 160;
	var accessboxWidth = 90;
	var blogboxWidth = 70;
	var contactboxWidth = 90;
	var linksboxWidth = 80;
	var omsboxWidth = 50;

	document.getElementById('profilebox').style.left = defaultLeftValue+'px';
	
	var worksboxLeftValue = defaultLeftValue+profileboxWidth;
	document.getElementById('worksbox').style.left = worksboxLeftValue+'px';
	
	var compeboxLeftValue = worksboxLeftValue+worksboxWidth;
	document.getElementById('compebox').style.left = compeboxLeftValue+'px';
	
	var publicationboxLeftValue = compeboxLeftValue+compeboxWidth;
	document.getElementById('publicationbox').style.left = publicationboxLeftValue+'px';
	
	//var accessboxLeftValue = publicationboxLeftValue+publicationboxWidth;
	//document.getElementById('accessbox').style.left = accessboxLeftValue+'px';
	
	var blogboxLeftValue = publicationboxLeftValue+publicationboxWidth;
	document.getElementById('blogbox').style.left = blogboxLeftValue+'px';
	
	var contactboxLeftValue = blogboxLeftValue+blogboxWidth;
	document.getElementById('contactbox').style.left = contactboxLeftValue+'px';

	var linksboxLeftValue = contactboxLeftValue+contactboxWidth;
	document.getElementById('linksbox').style.left = linksboxLeftValue+'px';
	
	var omsboxLeftValue = sWidth-omsboxWidth;
	document.getElementById('omsbox').style.left = omsboxLeftValue+'px';
	setImageScroll();
}
window.onresize = function(){
	var sHeight = GetWindowWidthHeight().height;
	var sWidth = GetWindowWidthHeight().width;
	document.getElementsByTagName('h1')[0].style.marginTop = sHeight/2-60+'px';
	var defaultLeftValue = (sWidth-820);

	var profileboxWidth = 95;
	var worksboxWidth = 85;
	var compeboxWidth = 110;
	var publicationboxWidth = 160;
	var accessboxWidth = 90;
	var blogboxWidth = 70;
	var contactboxWidth = 90;
	var linksboxWidth = 80;
	var omsboxWidth = 50;

	document.getElementById('profilebox').style.left = defaultLeftValue+'px';
	
	var worksboxLeftValue = defaultLeftValue+profileboxWidth;
	document.getElementById('worksbox').style.left = worksboxLeftValue+'px';
	
	var compeboxLeftValue = worksboxLeftValue+worksboxWidth;
	document.getElementById('compebox').style.left = compeboxLeftValue+'px';
	
	var publicationboxLeftValue = compeboxLeftValue+compeboxWidth;
	document.getElementById('publicationbox').style.left = publicationboxLeftValue+'px';
	
	var accessboxLeftValue = publicationboxLeftValue+publicationboxWidth;
	document.getElementById('accessbox').style.left = accessboxLeftValue+'px';
	
	var blogboxLeftValue = accessboxLeftValue+accessboxWidth;
	document.getElementById('blogbox').style.left = blogboxLeftValue+'px';
	
	var contactboxLeftValue = blogboxLeftValue+blogboxWidth;
	document.getElementById('contactbox').style.left = contactboxLeftValue+'px';

	var linksboxLeftValue = contactboxLeftValue+contactboxWidth;
	document.getElementById('linksbox').style.left = linksboxLeftValue+'px';
	
	var omsboxLeftValue = sWidth-omsboxWidth;
	document.getElementById('omsbox').style.left = omsboxLeftValue+'px';
}

contentsArray = new Array("profile","works","compe","blog","links");

function openClose(id){
	if(document.getElementById(id).style.display == false || document.getElementById(id).style.display == 'none'){
		//var tdName = id+'Td';
		var sHeight = GetWindowWidthHeight().height;
		var subject = id+'_subject';
		document.getElementById(subject).style.backgroundImage = 'url(http://takanoriohira.com/image/arrowunder.gif)';
		document.getElementById(id).style.display = 'block';
		document.getElementById(id).style.height = sHeight/2-75+'px';
		for(i=0;i<5;i++){
			if(contentsArray[i] != id){
				if(document.getElementById(contentsArray[i]).style.display == 'block' || document.getElementById(id).style.display == false){
					subject = contentsArray[i]+'_subject';
					document.getElementById(subject).style.backgroundImage = 'url(http://takanoriohira.com/image/arrowright.gif)';
					document.getElementById(contentsArray[i]).style.display = 'none';
				}
			}
		}
	}else{
		var subject = id+'_subject';
		document.getElementById(subject).style.backgroundImage = 'url(http://takanoriohira.com/image/arrowright.gif)';
		document.getElementById(id).style.display = 'none';
	}
}