/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Last updated Mar 15th, 04'. Added "End of Gallery" message.
* This copyright notice must stay intact for legal use
* Modified for autowidth and optional starting positions in
* http://www.dynamicDrive.com/forums by jschuer1 8/5/06
***********************************************/

 //1) Set width of the "neutral" area in the center of the gallery.
var restarea2=6;
 //2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed2=7;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth2=1000;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var startpos2=2;
 //5) Set message to show at end of gallery. Enter "" to disable message.
var endofgallerymsg2='';

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

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

var iedom2=document.all||document.getElementById, scrollspeed2=0, movestate2='', actualwidth2='', cross_scroll2, ns_scroll2, statusdiv2, loadedyes2=0, lefttime2, righttime2;

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

function creatediv2(){
statusdiv2=document.createElement("div")
statusdiv2.setAttribute("id","statusdiv2")
document.body.appendChild(statusdiv2)
statusdiv2=document.getElementById("statusdiv2")
statusdiv2.innerHTML=endofgallerymsg2
}

function positiondiv2(){
var mainobjoffset2=getposOffset2(crossmain2, "left"),
menuheight2=parseInt(crossmain2.offsetHeight),
mainobjoffsetH2=getposOffset2(crossmain2, "top");
statusdiv2.style.left=mainobjoffset2+(menuwidth2/2)-(statusdiv2.offsetWidth/2)+"px";
statusdiv2.style.top=menuheight2+mainobjoffsetH2+"px";
}

function showhidediv2(what){
if (endofgallerymsg2!="") {
positiondiv2();
statusdiv2.style.visibility=what;
}
}

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


function moveleft2(){
if (loadedyes2){
movestate2="left";
if (iedom2&&parseInt(cross_scroll2.style.left)>(menuwidth2-actualwidth2)){
cross_scroll2.style.left=parseInt(cross_scroll2.style.left)-scrollspeed2+"px";
showhidediv2("hidden");
}
else
showhidediv2("visible");
}
lefttime2=setTimeout("moveleft2()",10);
}

function moveright2(){
if (loadedyes2){
movestate2="right";
if (iedom2&&parseInt(cross_scroll2.style.left)<0){
cross_scroll2.style.left=parseInt(cross_scroll2.style.left)+scrollspeed2+"px";
showhidediv2("hidden");
}
else
showhidediv2("visible");
}
righttime2=setTimeout("moveright2()",10);
}

function motionengine2(e){
  
var mainobjoffset2=getposOffset2(crossmain2, "left"),
dsocx2=(window.pageXOffset)? pageXOffset: ietruebody2().scrollLeft,
dsocy2=(window.pageYOffset)? pageYOffset : ietruebody2().scrollTop,
curposy2=window.event? event.clientX : e.clientX? e.clientX: "";
curposy2-=mainobjoffset2-dsocx2;

var leftbound2=(menuwidth2-restarea2)/2;
var rightbound2=(menuwidth2+restarea2)/2;

if (curposy2>rightbound2){
scrollspeed2=(curposy2-rightbound2)/((menuwidth2-restarea2)/2) * maxspeed2;
clearTimeout(righttime2);
if (movestate2!="left") moveleft2();
}
else if (curposy2<leftbound2){
scrollspeed2=(leftbound2-curposy2)/((menuwidth2-restarea2)/2) * maxspeed2;
clearTimeout(lefttime2);
if (movestate2!="right") moveright2();
}
else
scrollspeed2=0;
}

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

function stopmotion2(e){
if (!window.opera||(window.opera&&e.relatedTarget!==null))
if ((window.event&&!crossmain2.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns62(e.currentTarget, e.relatedTarget))){
clearTimeout(lefttime2);
clearTimeout(righttime2);
movestate2="";
}
}

function fillup2(){
if (iedom2){
crossmain2=document.getElementById? document.getElementById("motioncontainer2") : document.all.motioncontainer2;
try
{
if(crossmain2!=null)
{
    if(typeof crossmain2.style.maxwidth2!=='undefined')
    crossmain2.style.maxwidth2=maxwidth2+'px';
}
}
catch(ex)
{
    crossmain2.style.maxwidth2='100px';
}
menuwidth2=crossmain2.offsetWidth;
cross_scroll2=document.getElementById? document.getElementById("motiongallery2") : document.all.motiongallery2;
actualwidth2=document.getElementById? document.getElementById("trueContainer2").offsetWidth : document.all['trueContainer2'].offsetWidth;
if (startpos2)
cross_scroll2.style.left=(menuwidth2-actualwidth2)/startpos2+'px';
crossmain2.onmousemove=function(e){
motionengine2(e);
}

crossmain2.onmouseout=function(e){
stopmotion2(e);
showhidediv2("hidden");
}
}
loadedyes2=1
if (endofgallerymsg2!=""){
creatediv2();
positiondiv2();
}
}
window.onload=fillup2;

onresize=function(){
if (typeof motioncontainer2!=='undefined'&&motioncontainer2.filters){
motioncontainer2.style.width="0";
motioncontainer2.style.width="";
motioncontainer2.style.width=Math.min(motioncontainer2.offsetWidth, maxwidth2)+'px';
}
menuwidth2=crossmain2.offsetWidth;
//cross_scroll2.style.left=(menuwidth2-actualwidth2)/startpos2+'px';
}


function doit2(arg)
{
    var x=0;
    
    var bln_conditionleft = parseInt(cross_scroll2.style.left)>(menuwidth2-actualwidth2);
    var bln_conditionright = parseInt(cross_scroll2.style.left)<0;
    if(arg=="left"&&bln_conditionright==false) return;
    if(arg=="right"&&bln_conditionleft==false) return;
 	var i=parseInt(cross_scroll2.style.left);
 	if(arg=="left")
 	{ 
 	    x=20;
 	    if(i!=0)
 	     {
            if(i>-20)
            {
             cross_scroll2.style.left=0+"px";
            }	 
            else
            {
              cross_scroll2.style.left=(parseInt(cross_scroll2.style.left)+x)+"px";
 	        }
	     }
 	}
 	if(arg=="right")
 	 {
 	     x=-20;
 	     cross_scroll2.style.left=(parseInt(cross_scroll2.style.left)+x)+"px";
 	  }
 	
 	
}

