
/* ===============================================
	レイヤーの高さ取得
=============================================== */
	function getLayerHeight(id){
		if(document.all || document.getElementById){
			if(document.all){
//			return document.all(id).clientHeight;
				return document.all(id).offsetHeight;
			} else if(document.getElementById){
//			return document.getElementById(id).clientHeight;
				return document.getElementById(id).offsetHeight;
			}
		}
	}

/* ===============================================
	レイヤーの高さ設定
=============================================== */
	function setLayerHeight(id,h){
		if(document.all || document.getElementById){
			if(document.all){
				document.all(id).style.height = h + "px";
			} else if(document.getElementById){
				document.getElementById(id).style.height = h + "px";
			}
		}
	}

/* ===============================================
	レイヤーの座標設定
=============================================== */
	function setLayerPosition(id,x,y){
		if(document.all || document.getElementById){
			if(document.all){
				document.all(id).style.top  = y + "px";
				document.all(id).style.left = x + "px";
			} else if(document.getElementById){
				document.getElementById(id).style.top  = y + "px";
				document.getElementById(id).style.left = x + "px";
			}
		}
	}

/* ===============================================
	レイヤーのx座標取得
=============================================== */
	function getLayerPositionX(id){
		if(document.all || document.getElementById){
			if(document.all){
				return document.all(id).style.pixelLeft;
			} else if(document.getElementById){
				return parseInt(document.getElementById(id).style.left);
			}
		}
	}

/* ===============================================
	form elment数取得
=============================================== */
	function getFormElementsNum(fname,ename){
		return document.forms[fname].elements[ename].length;
	}

/* ===============================================
	全てのレイヤーの高さ設定
=============================================== */
	function setAllLayerHeight(id){
		var idName = id + allLayerNum;
		var h = getLayerHeight(idName);
		for(i = 1; i <= allLayerNum ; i++){
			var idName = id + i;
			var hc = getLayerHeight(idName);
			h = ( h < hc ) ? hc : h;
		}

		setLayerHeight(slideAreaId,h);
		for(i = 1; i <= allLayerNum ; i++){
			var idName = id + i;
			setLayerHeight(idName,h);
		}
	}

/* ===============================================
	全てのレイヤーの標準座標設定
=============================================== */
	function setAllLayerPosition(id){
		var x = 0;
		for(i = 1; i <= allLayerNum ; i++){
			var idName = id + i;
			if( i == 1 ){
				x = leftPad;
			}else{
				x = x + leftPad + cellWidth;
			}
			setLayerPosition(idName,x,'0');
		}
	}


	var leftPad = 5;
	var cellWidth = 150;
	var cellMaxWidth = leftPad + cellWidth;
	var fname = 'slideshow';
	var ename = 'slide-cell';
	var slideAreaId = 'slide-area';
	var cellId = 'slide-cell-';

	var action = "true";
	var lockCellNum = 3;
	var allLayerNum;

	// 移動回数
	var moveFrequency = 20;
	// 移動時間 1/1000秒単位
	var moveSec = 20;

	var movePx = new Array();
	function setMovePx(){
		moveFrequency = (moveFrequency <= 1) ? 2:moveFrequency;
		moveFrequency = (cellMaxWidth <= moveFrequency) ? cellMaxWidth:moveFrequency;
		movePx[0] = parseInt(cellMaxWidth / (moveFrequency - 1));
		movePx[moveFrequency] = cellMaxWidth - (movePx[0] * (moveFrequency - 1));
		for(i = 1; i <= (moveFrequency - 1) ; i++){
			movePx[i] = movePx[0];
		}
	}

	function preLoad(){
		allLayerNum = getFormElementsNum(fname,ename);
		setAllLayerHeight(cellId);
		setAllLayerPosition(cellId);
		setMovePx();
		action = (allLayerNum <= lockCellNum) ? "false":"true";
	}


/* ===============================================
	move Left
=============================================== */
	var moveFrequencyNum = 1;
	function moveLeftCell(){
		if( action == "false" ){
		}else{
			moveLeftCellCheck();
			action = "false";
			moveLeftCellSub();
			var moveSecNum;
			for(i = 1; i < moveFrequency ; i++){
				moveSecNum = moveSec * i;
				moveCell = setTimeout('moveLeftCellSub()', moveSecNum);
			}
			moveCell = setTimeout(function(){action = "true";}, moveSec*(moveFrequency+1));
		}
	}
	function moveLeftCellSub(){
		moveFrequencyNum = (moveFrequencyNum <= moveFrequency) ? moveFrequencyNum:1;
		var mx = movePx[moveFrequencyNum];
		for(i = 1; i <= allLayerNum ; i++){
			var idName = cellId + i;
			var nx = getLayerPositionX(idName);
			var x = nx - mx;
			setLayerPosition(idName,x,'0');
		}
		moveFrequencyNum++;
	}
	function moveLeftCellCheck(){
		var x = (leftPad * allLayerNum) + (cellWidth * (allLayerNum - 1));
		for(i = 1; i <= allLayerNum ; i++){
			var idName = cellId + i;
			if( getLayerPositionX(idName) < 1 ){
				setLayerPosition(idName,x,'0');
			}
		}
	}


/* ===============================================
	move Right
=============================================== */
	function moveRightCell(){
		if( action == "false" ){
		}else{
			moveRightCellCheck();
			action = "false";
			moveRightCellSub();
			var moveSecNum;
			for(i = 1; i < moveFrequency; i++){
				moveSecNum = moveSec * i;
				moveCell = setTimeout('moveRightCellSub()', moveSecNum);
			}
			moveCell = setTimeout(function(){action = "true";}, moveSec*(moveFrequency+1));
		}
	}
	function moveRightCellSub(){
		moveFrequencyNum = (moveFrequencyNum <= moveFrequency) ? moveFrequencyNum:1;
		var mx = movePx[moveFrequencyNum];
		for(i = 1; i <= allLayerNum ; i++){
			var idName = cellId + i;
			var nx = getLayerPositionX(idName);
			var x = nx + mx;
			setLayerPosition(idName,x,'0');
		}
		moveFrequencyNum++;
	}
	function moveRightCellCheck(){
		var x = 0 - cellWidth;
		var xx = (leftPad * (allLayerNum - 1)) + (cellWidth * (allLayerNum - 1));
		for(i = 1; i <= allLayerNum ; i++){
			var idName = cellId + i;
			if( getLayerPositionX(idName) > xx){
				setLayerPosition(idName,x,'0');
			}
		}
	}



