var weblog_touch_start_x = 0;
var weblog_touch_move_x = 0;
function weblogs_onLoad(){
	if(navigator.userAgent.indexOf('Mobile') > -1 && navigator.userAgent.indexOf('iPad') > -1){
		setTimeout("onloadScroll()",10);
		document.addEventListener("touchstart", weblog_multiTouch, false);
		document.addEventListener("touchend", weblog_multiTouch, false);
		document.addEventListener("touchmove", weblog_multiTouch, false);
	}
	if(document.getElementById('line_maker'))
		document.onmousemove = line_stalker;
}
function line_stalker(e){
	var ajustTop = 0;
	if(navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("Opera") > -1)
		ajustTop = document.documentElement.scrollTop;
	if(document.getElementById('line_maker'))
		document.getElementById('line_maker').style.top = (getMouseY(e)-110+ajustTop) + "px";
	try {
		mouseMove(e);
	}
	catch(e){
		
	}
}
function getMouseX(e){
	if(window.opera)
		return e.clientX;
	else if(document.all)
		return document.body.scrollLeft+event.clientX;
	else if(document.layers||document.getElementById)
		return e.pageX;
}
function getMouseY(e){
	if(window.opera)
		return e.clientY;
	else if(document.all)
		return document.body.scrollTop+event.clientY;
	else if(document.layers||document.getElementById)
		return e.pageY;
}

function weblog_NewMark(getId){
	var dates = new Date();
	var onehourold = Math.floor(dates.getTime() / 1000) - (60 * 60 * 24 * 3);
	if(onehourold < getId)
		document.write(' <img src="/images/new.gif" style="display: inline;">');
	
	var t = getId;
	var tm = dates.getTime() / 1000;
	var cal_time = tm - t;
	var cal_sec = cal_time % 60;
	var cal_min = Math.floor(cal_time / 60);
	var cal_hor = Math.floor(cal_min / 60);
	cal_min = cal_min % 60;
	cal_time = "";
	if(cal_hor > 24)
		cal_time = parseInt(cal_hor / 24) + "日前";
	else if(cal_hor > 0)
		cal_time += cal_hor + "時間前";
	else if(cal_min > 0)
		cal_time += cal_min + "分前";
	else
		cal_time += cal_sec + "秒前";
	document.write('<em class="time_later">('+cal_time+')</em>');
}

function weblog_multiTouch(event) {
	var d = window.document;
	switch (event.type) {
		case "touchstart":
			weblog_touch_start_x = event.touches[0].pageX;
			break;
		case "touchmove":
			weblog_touch_move_x = event.touches[0].pageX;
			break;
		case "touchend":
			var touch_move_lengh = weblog_touch_start_x - weblog_touch_move_x;
			weblog_touch_start_x = 0;
			if(touch_move_lengh > 200 && d.getElementById('weblog_prev_link') && weblog_touch_move_x != 0){
				location.href = d.getElementById('weblog_prev_link').href;
			}
			else if(touch_move_lengh < -200 && d.getElementById('weblog_next_link')){
				location.href = d.getElementById('weblog_next_link').href;
			}
			break;
	}
}
function touchstartHandler(event) {
	weblog_touch_x = event.touches[0].pageX;
	//alert(weblog_touch_x);
}
function touchendHandler(event) {
	var move_pos = weblog_touch_x - event.touches[0].pageX;
	alert(move_pos);
}
function onloadScroll(){
	//window.scrollTo(0,10);
}
function addEventSet(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}
	catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}
addEventSet(window,"load",function(){weblogs_onLoad()});
