var MonthName = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

function WriteStartCSS(){
	document.write('<style media="screen">');
	document.write('#Updates.start #LocalUpdates{');
	document.write('display:none;');
	document.write('})');
	document.write('</style>');
}
function RemoveStartCSS(){
	document.getElementById('Updates').className = '';
}

function CheckWindowSize(){
	wheight = 0;
	if(window.innerHeight){
		wheight = window.innerHeight;
	}else if(document.documentElement.clientHeight){
		wheight = document.documentElement.clientHeight;
	}
	
	WriteCookie('devprof', screen.width + 'x' + screen.height + '/' + wheight);
}

function SwitchUpdatesStyle(){
	if(CheckCookie('homeUTmode') == 'absolute'){
		ChangeUpdateStyleTo('relative');
	}else{
		ChangeUpdateStyleTo('absolute');
	}
}
function ChangeUpdateStyleTo(mode){
	if(mode == 'absolute'){
		WriteCookie('homeUTmode', 'absolute');
	}else{
		WriteCookie('homeUTmode', 'relative');
	}
	
	SetLocalUpdates(0);
	SetLocalUpdates(1);
	SetLocalUpdates(2);
	SetLocalUpdates(3);
	
	ReloadClockView();
}
function ReloadClockView(){
	if(CheckCookie('homeUTmode') == 'absolute'){
		document.getElementById('TheClockTitle').innerHTML = 'absolute date';
	}else{
		document.getElementById('TheClockTitle').innerHTML = 'relative date';
	}
}

function SetLocalUpdates(n){
	if(location.host != 'marblecake.jp'){
		document.getElementById('LocalUpdateDateTime' + n).innerHTML = "Update Time Unknown";
		document.getElementById('LocalUpdates' + n).className = 'hostNotMatch';
		return false;
	}
	
	if(CheckCookie('homeUTmode') == 'absolute' && 1 == 2){
		document.getElementById('LocalUpdateDateTime' + n).innerHTML = AbsolTime(UpdateTimesArray[n]);
	}else{
		document.getElementById('LocalUpdateDateTime' + n).innerHTML = SotaiTime(UpdateTimesArray[n]);
	}
}

function AbsolTime(inputtime){
	NowTime = parseInt((new Date()).getTime() / 1000);

	UpDateYYYYMMDD = YYYYMMDD(inputtime);
	NowDateYYYYMMDD = YYYYMMDD(NowTime);
	
	TheTimeObj = new Date();
	TheTimeObj.setTime(inputtime * 1000);
	
	if(UpDateYYYYMMDD == NowDateYYYYMMDD){
		if(TheTimeObj.getMinutes() < 10){
			return '<strong>' + TheTimeObj.getHours() + ':0' + TheTimeObj.getMinutes() + ', Today</strong>';
		}else{
			return '<strong>' + TheTimeObj.getHours() + ':' + TheTimeObj.getMinutes() + ', Today</strong>';
		}
	}else{
		return MonthName[TheTimeObj.getMonth()] + ' ' + TheTimeObj.getDate() + ', ' + TheTimeObj.getFullYear();
	}
}

function SotaiTime(inputtime){
	NowTime = parseInt((new Date()).getTime() / 1000);

	tempUptime = NowTime - inputtime;
	UpDateYYYYMMDD = YYYYMMDD(inputtime);
	UpDateYYYYMM = YYYYMM(inputtime);
	
	tempKeisoku = NowTime;
	tempNdaysAgo = 0;
	while(YYYYMMDD(tempKeisoku) > UpDateYYYYMMDD){
		tempNdaysAgo ++;
		tempKeisoku -= 86400;
	}
	
	tempKeisoku = YYYYMM(NowTime);
	tempNmonthsAgo = 0;
	while(tempKeisoku > UpDateYYYYMM && tempNmonthsAgo < 16){
		tempNmonthsAgo ++;
		tempKeisoku --;
		if(tempKeisoku % 100 == 0){
			tempKeisoku -= 88;
		}
	}

	if(tempUptime <= 60 * 30){
		return '<strong>Just Now!</strong>';
	}else if(tempUptime <= 60 * 75){
		return '<strong>' + parseInt(tempUptime / (60) + 0.5) + ' minutes ago</strong>';
	}else if(tempUptime <= 60 * 60 * 1.5){
		return '<strong>1 hour ago</strong>';
	}else if(tempUptime <= 60 * 60 * 6){
		return '<strong>' + parseInt(tempUptime / (60 * 60) + 0.5) + ' hours ago</strong>';
	}else if(tempUptime <= 60 * 60 * 12 && tempNdaysAgo == 0){
		return '<strong>' + parseInt(tempUptime / (60 * 60) + 0.5) + ' hours ago</strong>';
	}else if(tempNdaysAgo == 0){
		return '<strong>Today</strong>';
	}else if(tempNdaysAgo == 1){
		return 'Yesterday';
	}else if(tempNdaysAgo < 7){
		return tempNdaysAgo + ' days ago';
	}else if(tempUptime <= 60 * 60 * 24 * 7 * 1.5){
		return '1 week ago';
	}else if(tempUptime <= 60 * 60 * 24 * 7 * 2.5){
		return parseInt(tempUptime / (60 * 60 * 24 * 7) + 0.5) + ' weeks ago';
	}else if(tempUptime <= 60 * 60 * 24 * 7 * 4 && tempNmonthsAgo == 0){
		return parseInt(tempUptime / (60 * 60 * 24 * 7) + 0.5) + ' weeks ago';
	}else if(tempNmonthsAgo == 0){
		return 'Early this month';
	}else if(tempNmonthsAgo == 1){
		return 'Last month';
	}else if(tempNmonthsAgo < 10){
		return tempNmonthsAgo + ' months ago';
	}else if(tempNmonthsAgo < 14){
		return '1 year ago';
	}else{
		return 'Recently no updates';
	}
}

function YYYYMMDD(sec){
	thistime = new Date();
	thistime.setTime(sec * 1000);
	return (thistime.getFullYear()) * 10000 + (thistime.getMonth() + 1) * 100 + thistime.getDate();
}
function YYYYMM(sec){
	thistime = new Date();
	thistime.setTime(sec * 1000);
	return (thistime.getFullYear()) * 100 + (thistime.getMonth() + 1);
}