
var restarea=6 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed=4.5 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.

var iedom = document.all||document.getElementById;
var scrollspeed = 1;
var scrollspeed2 = 1;
var movestate = "";
var movestate2 = "";

var menuwidth;
var menuwidth2;
var mainobjoffset;
var mainobjoffset2;
var actualwidth='';
var actualwidth2='';
var cross_scroll, ns_scroll;
var cross_scroll2, ns_scroll2;
var loadedyes=0;

var timer_init;

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function getposOffset(what){
	var totaloffset = what.offsetLeft;
	var parentEl = what.offsetParent;
	while (parentEl!=null){
		totaloffset += parentEl.offsetLeft;
		parentEl = parentEl.offsetParent;
	}
	return totaloffset;
}

function moveleft(){
	if (loadedyes){
		movestate = "left";
		if (iedom && parseInt(cross_scroll.style.left) > (menuwidth-actualwidth)){
			cross_scroll.style.left = parseInt(cross_scroll.style.left) - scrollspeed + "px";
		}
	}
	lefttime = setTimeout("moveleft()",10);
}
function moveleft2(){
	if (loadedyes){
		movestate2 = "left";
		if (iedom && parseInt(cross_scroll2.style.left) > (menuwidth2-actualwidth2)){
			cross_scroll2.style.left = parseInt(cross_scroll2.style.left) - scrollspeed2 + "px";
		}
	}
	lefttime = setTimeout("moveleft2()",10);
}


function moveright(){
	if (loadedyes){
		movestate = "right";
		if (iedom && parseInt(cross_scroll.style.left) < 0){
			cross_scroll.style.left = parseInt(cross_scroll.style.left) + scrollspeed + "px";
		}
	}
	righttime=setTimeout("moveright()",10)
}
function moveright2(){
	if (loadedyes){
		movestate2 = "right";
		if (iedom && parseInt(cross_scroll2.style.left) < 0){
			cross_scroll2.style.left = parseInt(cross_scroll2.style.left) + scrollspeed2 + "px";
		}
	}
	righttime=setTimeout("moveright2()",10)
}

function motionengine(e){

	clearInterval(timer_init);

	var dsocx = (window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
	var curposx = window.event? event.clientX : e.clientX? e.clientX: "";
	curposx -= mainobjoffset - dsocx;
	var leftbound = (menuwidth-restarea)/2;
	var rightbound = (menuwidth+restarea)/2;
	if (curposx > rightbound){
		scrollspeed = (curposx-rightbound)/rightbound * maxspeed;
		if (window.righttime) clearTimeout(righttime);
		if (movestate!="left") moveleft();
	}
	else if (curposx < leftbound){
		scrollspeed = (leftbound-curposx)/leftbound * maxspeed;
		if (window.lefttime) clearTimeout(lefttime);
		if (movestate!="right") moveright();
	}
	else {
		scrollspeed = 0;
	}
}

function motionengine2(e){
	var dsocx = (window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
	var curposx = window.event? event.clientX : e.clientX? e.clientX: "";
	curposx -= mainobjoffset2 - dsocx;
	var leftbound = (menuwidth2-restarea)/2;
	var rightbound = (menuwidth2+restarea)/2;
	if (curposx > rightbound){
		scrollspeed2 = (curposx-rightbound)/rightbound * maxspeed;
		if (window.righttime) clearTimeout(righttime);
		if (movestate2!="left") moveleft2();
	}
	else if (curposx < leftbound){
		scrollspeed2 = (leftbound-curposx)/leftbound * maxspeed;
		if (window.lefttime) clearTimeout(lefttime);
		if (movestate2!="right") moveright2();
	}
	else {
		scrollspeed2 = 0;
	}
}

function stopmotion(e){
	//if (window.event && !crossmain.contains(event.toElement)){
		if (window.lefttime) clearTimeout(lefttime);
		if (window.righttime) clearTimeout(righttime);
		movestate = "";
	//}
}

function stopmotion2(e){
	//if (window.event && !crossmain.contains(event.toElement)){
		if (window.lefttime) clearTimeout(lefttime);
		if (window.righttime) clearTimeout(righttime);
		movestate2 = "";
	//}
}

function fillup(){
	if (iedom){
		crossmain = document.getElementById? document.getElementById("photo_new3") : document.all.photo_new3;
		if (crossmain) {
			menuwidth = parseInt(crossmain.style.width);
			mainobjoffset = getposOffset(crossmain);
			cross_scroll = document.getElementById? document.getElementById("photo_new3_cont") : document.all.photo_new3_cont;
			actualwidth = parseInt(cross_scroll.style.width);
			
			//alert("menuwidth=" + menuwidth + "\n mainobjoffset = " + mainobjoffset + "\n actualwidth = " + actualwidth);
			
			crossmain.onmousemove = function(e){
				motionengine(e);
			}
			
			crossmain.onmouseout = function(e){
				stopmotion(e);
			}
		}
		
		crossmain2 = document.getElementById? document.getElementById("photo_new3_2") : document.all.photo_new3_2;
		if (crossmain2) {
			menuwidth2 = parseInt(crossmain2.style.width);
			mainobjoffset2 = getposOffset(crossmain2);
			cross_scroll2 = document.getElementById? document.getElementById("photo_new3_2_cont") : document.all.photo_new3_2_cont;
			actualwidth2 = parseInt(cross_scroll2.style.width);
			
			crossmain2.onmousemove = function(e){
				motionengine2(e);
			}
			
			crossmain2.onmouseout = function(e){
				stopmotion2(e);
			}
		}
		
		loadedyes = 1;
		
		if (crossmain || crossmain2) {
			timer_init = setInterval("scrollRight(1)",30);	// 繧ｹ繧ｯ繝ｭ繝ｼ繝ｫ縺ｮ騾溷ｺｦ繧貞､峨∴繧区凾縺ｯscrollRight縺ｮ蠑墓焚縺ｨ繧､繝ｳ繧ｿ繝ｼ繝舌Ν繧貞､峨∴繧倶ｺ九
		}
	}

}

function scrollRight(speed){

	if (loadedyes){
		movestate = "left";
		if (iedom && parseInt(cross_scroll.style.left) > (menuwidth-actualwidth)){
			cross_scroll.style.left = parseInt(cross_scroll.style.left) - speed + "px";
		}else{
			clearInterval(timer_init);
		}
	}
}


window.onload=fillup;
