
 //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=7;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth=1000;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var startpos=0;
 //5) Set message to show at end of gallery. Enter "" to disable message.


var iedom=document.all||document.getElementById, scrollspeed=0, movestate=false, actualwidth='', cross_scroll, ns_scroll, statusdiv, timer, coasting=false;

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 move()
{
    movestate=true;

   // var pos = parseInt(cross_scroll.style.left) - scrollspeed;
   // if (pos < -actualwidth)
    //    pos += actualwidth;
   // else if (pos > 0)
       // pos -= actualwidth;

   // cross_scroll.style.left = pos+"px";
    
    var pos2 = parseInt(cross_scroll2.style.left) - scrollspeed;
    if (pos2 < -actualwidth2)
        pos2 += actualwidth2;
    else if (pos2 > 0)
        pos2 -= actualwidth2;

    cross_scroll2.style.left = pos2+"px";    

    timer=setTimeout("move()",10);
}
/*
function motionengine(e)
{
    coasting = false;
    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;
    }
    else if (curposy<leftbound)
    {
        scrollspeed=-(leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed;
    }
    else
        scrollspeed=0;

    if (!movestate) move();
}
*/
function motionengine2(e)
{
    coasting = false;
    var mainobjoffset=getposOffset(crossmain2, "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;
    }
    else if (curposy<leftbound)
    {
        scrollspeed=-(leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed;
    }
    else
        scrollspeed=0;

    if (!movestate) move();
}



function coast()
{
    coasting = true;
    scrollspeed = scrollspeed >=0 ? 1 : -1;
    move();
}

function contains(a, b) 
{
    if (a == b) 
        return true;
    if (b.parentNode)
        return contains(a, b.parentNode);
    return false;
}

function stopmotion(e)
{
    if ((window.event&&!crossmain2.contains(event.toElement)) || (e && e.relatedTarget && !contains(crossmain2, e.relatedTarget)))
    {
        clearTimeout(timer);
        movestate=false;
        coast();
    }
}

function resizer()
{
    if (typeof motioncontainer!=='undefined'&&motioncontainer.filters)
    {
        motioncontainer.style.width="0";
        motioncontainer.style.width="";
        motioncontainer.style.width=Math.min(motioncontainer.offsetWidth, maxwidth)+'px';
    }

   	menuwidth=crossmain2.offsetWidth;
    cross_scroll2.style.left=startpos? (menuwidth-actualwidth)/startpos+'px' : 0;
}

function duplicateChildren(e)
{
    var copy = e.cloneNode(true);
    var nodes = copy.childNodes;

    var len = nodes.length;
    while (len--)
    {
        var c = nodes.item(0);
        e.appendChild(c);
    }
}


window.onload=function() 
{

	preloadImages();

    if (iedom)
    {
			/*
        crossmain=document.getElementById? 
             document.getElementById("motioncontainer") : 
            document.all.motioncontainer;
       */     
        crossmain2=document.getElementById? 
            document.getElementById("motioncontainer2") : 
            document.all.motioncontainer2;            

       // if(typeof crossmain.style.maxWidth!=='undefined')
           // crossmain.style.maxWidth=maxwidth+'px';

        if(typeof crossmain2.style.maxWidth!=='undefined')
            crossmain2.style.maxWidth=maxwidth+'px';            

       //menuwidth=crossmain.offsetWidth;
        menuwidth2=crossmain2.offsetWidth;
        
        //cross_scroll=document.getElementById? 
            //document.getElementById("motiongallery") : 
            //document.all.motiongallery;
            
        cross_scroll2=document.getElementById? 
            document.getElementById("motiongallery2") : 
            document.all.motiongallery;            

        //var trueC = document.getElementById? 
            //document.getElementById("trueContainer"): 
           // document.all['trueContainer'];
            
        var trueC2 = document.getElementById? 
            document.getElementById("trueContainer2"): 
            document.all['trueContainer2'];            

       // actualwidth=trueC.offsetWidth;
        actualwidth2=trueC2.offsetWidth;

        //duplicateChildren(trueC);
        duplicateChildren(trueC2);

        if (startpos){
           // cross_scroll.style.left=(menuwidth-actualwidth)/startpos+'px';
            cross_scroll2.style.left=(menuwidth2-actualwidth2)/startpos+'px';
	}

        //crossmain.onmousemove=motionengine
        //crossmain.onmouseout=stopmotion

        crossmain2.onmousemove=motionengine2
        crossmain2.onmouseout=stopmotion     
        
        window.onresize = resizer

        if (document.body.filters)
            onresize()

        coast();
    }
}

