// JavaScript Document

// 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); 


$(function() {
	
	//1000 = 1秒
	var st = 1000 * 30;
	timerID_let = setInterval( "setPage()", st );
	
	setViewLine();
});


//ページ情報を記録
function setPage() {
	
	//現在のスクロール量
	var scrollTop  = document.body.scrollTop || document.documentElement.scrollTop;
	
	//ページの高さ
	var pageHeight = document.body.offsetHeight;
	
	//ウィンドウの高さ
	var winHeight = getScreenSize().y;
	
	//alert ("set : "+scrollTop+"/"+pageHeight);
	
	
	$.get( "_controll.php", { m:"ajax_setpage", page:"let", sc:scrollTop, ph:pageHeight, wh:winHeight }, viewMsg );
}


//ウィンドウの高さ
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;
}


//デバッグ用
function viewMsg(data) {
	//alert( data );
}


//ページから離れる
$(window).unload(
	function () {
		clearInterval(timerID_let);
	}
);


//--------------------------------------------------------------


//精読率の目安
function setViewLine() {
	$.get( "_controll.php", { m:"ajax_readview" }, setViewLineComp );
}

function setViewLineComp(data) {
	
	//alert(data);
	
	//ページの高さ
	var ph = document.body.offsetHeight;
	
	//１０分の１
	var sv = ph / 10;
	
	for ( var i = 1; i < 10; i++ ) {
		var v = 10 * i;
		var ps = sv * i;
		var cls = "line_"+v;
		var tag = '<div class="'+cls+'">'+v+'%</div>';
		
		$(document.body).append(tag);
		$("."+cls).css({
									 "position":"absolute",
									 "top":ps+"px",
									 "left":"0",
									 "z-index":"500",
									 "width":"100%",
									 "height":"20px",
									 "line-height":"20px",
									 "background":"#060",
									 "color":"#fff",
									 "font-size":"16px",
									 "font-weight":"bold",
									 "text-indent":"1em"
									 });
		
		if (data == 1) {
			$("."+cls).fadeTo(100,0.6);
			
		} else {
			$("."+cls).hide();
		}
	}
}

