/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* This copyright notice must stay intact for legal use
* Modified for autowidth and optional starting positions in
* http://www.dynamicdrive.com/forums/showthread.php?t=11839 by jschuer1 8/5/06
***********************************************/

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


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

var scrollspeed=0, movestate='', actualwidth='', cross_scroll, ns_scroll, statusdiv, lefttime, righttime;

function ietruebody()
{
  return 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()
{
  movestate="left";
  if( parseInt( cross_scroll.style.left ) > ( menuwidth - actualwidth ) )
  {
    cross_scroll.style.left = parseInt( cross_scroll.style.left ) - scrollspeed + "px";
  }
  lefttime = setTimeout( "moveleft()", 10 );
}

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

function motionengine( e )
{
  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( 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 stopmotion( e )
{
  if( ( window.event && !crossmain.contains( event.toElement ) ) || ( e && e.currentTarget && e.currentTarget != e.relatedTarget ) )
  {
    clearTimeout( lefttime );
    clearTimeout( righttime );
    movestate = "";
  }
}

function fillup()
{
  crossmain = document.getElementById( "motioncontainer" );
  menuwidth = crossmain.offsetWidth;
  cross_scroll = document.getElementById( "motiongallery" );
  actualwidth = document.getElementById( "trueContainer" ).offsetWidth;
  crossmain.onmousemove = function( e )
  {
    motionengine( e );
  }
  crossmain.onmouseout = function( e )
  {
    return;
    if( e.relatedTarget )
    {
      if( e.target.tagName == 'img' )
        return;
    
    }
    
    
    stopmotion(e);
  }

  menuwidth = crossmain.offsetWidth;
  cross_scroll.style.left = 0;
  
  
}

window.onload = fillup;




