//ページ移動js

//初期化
var sFlag  = true;
var startX = 0;

//IE以外のモダンブラウザでevent.###を使えるようにする
if (!document.all) {
	(function () {
		for (var property in Event.prototype) {
			if (property.match(/MOUSE|CLICK/)) {
				window.addEventListener(property.toLowerCase(), function (e) {window.event = e;}, true);
			}
		}
	}());
}

//読み込み完了時
function pageMove() {
	if (document.getElementById('pageTop')) {
		var btnWidth = document.getElementById('pageTop').offsetWidth;

		if (btnWidth > 200) {
			document.getElementById('pageMoveWrapTop').innerHTML += '<li id="sliderBaseTop" class="sliderBase clr"><div id="sliderFaceTop" class="sliderFace" onmousedown="objMove(\'Top\');"></div></li>';

			var moveSpan = btnWidth - 200;
			var leftSpan = document.getElementById('pageTopIn').offsetWidth;

			if (leftSpan > 90) {
				var move = leftSpan - 90;
				if (moveSpan < move) {
					move = moveSpan;
				}
				var setting = parseInt(move * 190 / moveSpan);
				document.getElementById('pageTop').style.left             = '-' + String(move) + 'px';
				document.getElementById('sliderFaceTop').style.marginLeft = String(setting) + 'px';
				sFlag  = false;
			}

			//下部
			document.getElementById('pageMoveWrapBtm').innerHTML += '<li id="sliderBaseBtm" class="sliderBase clr"><div id="sliderFaceBtm" class="sliderFace" onmousedown="objMove(\'Btm\');"></div></li>';
			//同期
			pageSynchronize('Top', 'Btm');
		}
	}
}

//ページ移動（起動）
function objMove(id) {
	startX = event.clientX;
	if (sFlag == true) {
		startX = startX;
		sFlag  = false;
	} else {
		startX = startX - parseInt(document.getElementById('sliderFace' + id).style.marginLeft);
	}
	if (!document.all) {
		window.document.captureEvents(Event.MOUSEMOVE);
	}
	if (id != 'Btm') {
		window.document.onmousemove = moveingTop;
		window.document.onmouseup   = moveEndTop;
	} else {
		window.document.onmousemove = moveingBtm;
		window.document.onmouseup   = moveEndBtm;
	}
}

//ページ移動(本体)
function moveingTop() {
	var moveX = event.clientX - startX;
	if (moveX >= 0 && moveX <= 190) {
		var btnWidth = document.getElementById('pageTop').offsetWidth;
		var moveSpan = btnWidth - 200;
		var setting  = parseInt(moveX * moveSpan / 190);

		document.getElementById('sliderFaceTop').style.marginLeft = String(moveX) + 'px';
		document.getElementById('pageTop').style.left             = '-' + String(setting) + 'px';
	}
}

//ページ移動(本体)
function moveingBtm() {
	var moveX = event.clientX - startX;
	if (moveX >= 0 && moveX <= 190) {
		var btnWidth = document.getElementById('pageBtm').offsetWidth;
		var moveSpan = btnWidth - 200;
		var setting  = parseInt(moveX * moveSpan / 190);

		document.getElementById('sliderFaceBtm').style.marginLeft = String(moveX) + 'px';
		document.getElementById('pageBtm').style.left             = '-' + String(setting) + 'px';
	}
}

//ページ移動終了
function moveEndTop() {
	window.document.onmousemove = '';
	window.document.onmouseup   = '';
	//同期
	pageSynchronize('Top', 'Btm');
}

//ページ移動終了
function moveEndBtm() {
	window.document.onmousemove = '';
	window.document.onmouseup   = '';
	//同期
	pageSynchronize('Btm', 'Top');
}

//上部・下部を同期
function pageSynchronize(base, target) {
	document.getElementById('page' + target).style.left             = document.getElementById('page' + base).style.left;
	document.getElementById('sliderFace' + target).style.marginLeft = document.getElementById('sliderFace' + base).style.marginLeft;
}

