
//1) Set width of the "neutral" area in the center of the gallery.
var restarea=500;
//2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed=36;
//3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth=800;

var waitleft=null;
var holdup=null;

function enlargeimage(path, optWidth, optHeight)
{ //function to enlarge image. Change as desired.
	var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
		var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to  default height
		var winattributes="width="+actualWidth+",height="+actualHeight+",resizable=yes"
		window.open(path,"", winattributes)
}

//// edit

var xii = ['i1', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7', 'i8', 'i9', 'i10', 'i11', 'i12', 'i13', 'i14', 'i15', 'i16', 'i17', 'i18', 'i19', 'i20', 'i21', 'i22', 'i23', 'i24', 'i25', 'i26', 'i27', 'i28', 'i29', 'i30', 'i31'];

function imageHeight(dx) { return 367 - (dx * 0.1875); }


////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById, scrollspeed=0, actualwidth='', cross_scroll, ns_scroll, loadedyes=0, lefttime, righttime;

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

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function moveleft(){
	if (loadedyes){
		var j = parseInt(cross_scroll.style.left);
		if (iedom&&j>(menuwidth-(actualwidth-menuwidth))){
			cross_scroll.style.left=(j-scrollspeed)+"px";
		}
	}
	lefttime=setTimeout("moveleft()",10);
	sizepics();
}

function moveright(){
	var j =0;
	if (loadedyes){
		if (iedom&&parseInt(cross_scroll.style.left)<0){
			j = parseInt(cross_scroll.style.left)+scrollspeed;
			if (j >= 0) {
				j = 0;
			}
			cross_scroll.style.left=j+'px';
		}
	}
	if (j != 0) {
		righttime=setTimeout("moveright()",10);
		sizepics();
	}
}
function sizepics() {
	var mainobjoffset=getposOffset(crossmain, "left");
	var bg = parseInt(cross_scroll.style.left);
	var i;
	for (i = 0; i < xii.length; i++) {
		var o = document.images[ xii[i] ];
		var j = (o.offsetLeft + (mainobjoffset)) + bg;
		var h = imageHeight(j);
		if (h < 140) h = 140;
		if (h > 400) h = 400;
		if (!o._kh || o._lh != h) {
			o.style.height = h+"px";
			o._lh = h;
			o._kh=true;
		}
	}
	if (typeof motioncontainer!=='undefined'){
		var xy=Math.min(motioncontainer.offsetWidth, maxwidth);
		if (motioncontainer._xy != xy) {
			motioncontainer.style.width="0";
			motioncontainer.style.width="";
			motioncontainer.style.width=xy+'px';
			motioncontainer._xy = xy;
		}
	}
	menuwidth=crossmain.offsetWidth;
}

function motionengine(e){
	if (holdup) return;
	var mainobjoffset=getposOffset(crossmain, "left"),
	    dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft,
	    dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop,
	    curposy=window.event? event.clientX : e.clientX? e.clientX: "";
	curposy-=mainobjoffset-dsocx;
	var leftbound=(menuwidth-restarea)/2;
	var rightbound=(menuwidth+restarea)/2;
	if (waitleft) {
		if (curposy<rightbound && curposy>leftbound) {
			waitleft=null;
		}
	} else {
		scrollspeed=0;
		clearTimeout(lefttime);
		clearTimeout(righttime);
		if (curposy>rightbound){
			scrollspeed=(curposy-rightbound)/((menuwidth-restarea)/2) * maxspeed;
			if (scrollspeed > 0) {
				moveleft();
			}
		} else if (curposy<leftbound){
			scrollspeed=(leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed;
			if (scrollspeed > 0) {
				moveright();
			}
		}
	}
	sizepics();
}

function contains_ns6(a, b) {
	if (b!==null) {
		while (b.parentNode) {
			if ((b = b.parentNode) == a) {
				return true;
			}
		}
	}
	return false;
}

function stopmotion(e){
	if (!window.opera||(window.opera&&e.relatedTarget!==null)) {
		if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
			clearTimeout(lefttime);
			clearTimeout(righttime);
		}
	}
}

function fillup(){
	if (iedom){
		crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer;
		menuwidth=crossmain.offsetWidth;
		cross_scroll=document.getElementById? document.getElementById("motiongallery") : document.all.motiongallery;
		actualwidth=document.getElementById? document.getElementById("trueContainer").offsetWidth : document.all['trueContainer'].offsetWidth;
		crossmain.onmousemove=motionengine;
		crossmain.onmouseout=stopmotion;
	}
	loadedyes=1;
	window.setTimeout("sizepics();",10);
	document.getElementById('loadmsg').style.display='none';
}
function do_showme(x) {
	document.getElementById(x).style.display='block';

	scrollspeed=0;
	clearTimeout(righttime);
	clearTimeout(lefttime);
	stopmotion();
	holdup=true;
	waitleft=true;
}
function do_closeme(x) {
	document.getElementById(x).style.display='none';
	crossmain.onmousemove=motionengine;
	crossmain.onmouseout=stopmotion;
	scrollspeed=0;
	clearTimeout(righttime);
	clearTimeout(lefttime);
	stopmotion();
	waitleft=true;
	holdup=null;
}

window.onload=fillup;

onresize=sizepics;
