 //1) Set width of the "neutral" area in the center of the gallery.
var restarea = 6;
 //2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed = 5;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth = 3000;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var startpos = 0;

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)
}

////NO NEED TO EDIT BELOW THIS LINE////////////
test            = '';
var scrollspeed = 0;
var movestate   = '';
var loadedyes = 0;
var lefttime;
var 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) {
    movestate = "left";
    if (parseInt(document.getElementById('motiongallery').style.left) > (menuwidth-actualwidth)) {
      document.getElementById('motiongallery').style.left = parseInt(document.getElementById('motiongallery').style.left)-scrollspeed+"px";
    }
  }
  lefttime = setTimeout("moveleft()",10);
}

function moveright() {
  if (loadedyes) {
    movestate = "right";
    if (parseInt($('motiongallery').style.left)<0) {
      $('motiongallery').style.left = parseInt($('motiongallery').style.left)+scrollspeed+"px";
    }
  }
  righttime = setTimeout("moveright()",10);
}

function motionengine(e) {
  var mainobjoffset = getposOffset($('motioncontainer'), "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)+62;
  var rightbound    = ((menuwidth+restarea)/2)-62;
  if (curposy > rightbound){
    scrollspeed=(curposy-rightbound)/((menuwidth-restarea)/2) * maxspeed;
    clearTimeout(righttime);
    if (movestate!="left") { moveleft(); }
  }
  else if (curposy < leftbound) {
    scrollspeed = (leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed;
    clearTimeout(lefttime);
    if (movestate != "right") { moveright(); }
  }
  else { scrollspeed = 0; }
}

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 &&! $('motioncontainer').contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))) {
    clearTimeout(lefttime);
    clearTimeout(righttime);
    movestate = "";
  }
}

function fillup(){
  if(typeof $('motioncontainer').style.maxWidth !== 'undefined') { $('motioncontainer').style.maxWidth = maxwidth+'px'; }
  menuwidth    = $('motioncontainer').offsetWidth;
  //actualwidth  = $('trueContainer').offsetWidth;
  /*
  if (startpos) { $('motiongallery').style.left = (menuwidth-actualwidth)/startpos+'px'; }
  
  $('motioncontainer').onmousemove = function(e)  { motionengine(e); }
  $('motioncontainer').onmouseout  = function(e)  { stopmotion(e); }
  $('leftblend').onmousemove = function(e)  { motionengine(e); }
  $('leftblend').onmouseout  = function(e)  { stopmotion(e); }
  $('rightblend').onmousemove = function(e)  { motionengine(e); }
  $('rightblend').onmouseout  = function(e)  { stopmotion(e); }
  loadedyes = 1;
  */
}

