/***********************************************
* 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 prodRestarea=6;
 //2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var prodMaxspeed=7;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var prodMaxwidth=1000;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var prodStartpos=0;
 //5) Set message to show at end of gallery. Enter "" to disable message.
//var prodEndofgallerymsg='<span style="font-size: 11px;">End of Gallery</span>';
var prodEndofgallerymsg='';


////NO NEED TO EDIT BELOW THIS LINE////////////

var prodIedom=document.all||document.getElementById, scrollspeed=0, movestate='', actualwidth='', prodCross_scroll, ns_scroll, productstatusdiv, prodLoadedyes=0, lefttime, righttime;

function prodIetruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function prodCreatediv(){
productstatusdiv=document.createElement("div")
productstatusdiv.setAttribute("id","productstatusdiv")
document.body.appendChild(productstatusdiv)
productstatusdiv=document.getElementById("productstatusdiv")
productstatusdiv.innerHTML=prodEndofgallerymsg
}

function prodPositiondiv(){
var prodMainobjoffset=prodGetposOffset(prodCrossmain, "left"),
prodMenuheight=parseInt(prodCrossmain.offsetHeight),
prodMainobjoffsetH=prodGetposOffset(prodCrossmain, "top");
productstatusdiv.style.left=prodMainobjoffset+(prodMenuwidth/2)-(productstatusdiv.offsetWidth/2)+"px";
productstatusdiv.style.top=prodMenuheight+prodMainobjoffsetH+"px";
}

function prodShowhidediv(what){
if (prodEndofgallerymsg!="") {
prodPositiondiv();
productstatusdiv.style.visibility=what;
}
}

function prodGetposOffset(what, offsettype){
var prodTotaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var prodParentEl=what.offsetParent;
while (prodParentEl!=null){
prodTotaloffset=(offsettype=="left")? prodTotaloffset+prodParentEl.offsetLeft : prodTotaloffset+prodParentEl.offsetTop;
prodParentEl=prodParentEl.offsetParent;
}
return prodTotaloffset;
}


function prodMoveleft(){
if (prodLoadedyes){
movestate="left";
if (prodIedom&&parseInt(prodCross_scroll.style.left)>(prodMenuwidth-actualwidth)){
prodCross_scroll.style.left=parseInt(prodCross_scroll.style.left)-scrollspeed+"px";
prodShowhidediv("hidden");
}
else
prodShowhidediv("visible");
}
lefttime=setTimeout("prodMoveleft()",10);
}

function prodMoveright(){
if (prodLoadedyes){
movestate="right";
if (prodIedom&&parseInt(prodCross_scroll.style.left)<0){
prodCross_scroll.style.left=parseInt(prodCross_scroll.style.left)+scrollspeed+"px";
prodShowhidediv("hidden");
}
else
prodShowhidediv("visible");
}
righttime=setTimeout("prodMoveright()",10);
}

function prodMotionengine(e){
var prodMainobjoffset=prodGetposOffset(prodCrossmain, "left"),
dsocx=(window.pageXOffset)? pageXOffset: prodIetruebody().scrollLeft,
dsocy=(window.pageYOffset)? pageYOffset : prodIetruebody().scrollTop,
curposy=window.event? event.clientX : e.clientX? e.clientX: "";
curposy-=prodMainobjoffset-dsocx;
var prodLeftbound=(prodMenuwidth-prodRestarea)/2;
var prodRightbound=(prodMenuwidth+prodRestarea)/2;
if (curposy>prodRightbound){
scrollspeed=(curposy-prodRightbound)/((prodMenuwidth-prodRestarea)/2) * prodMaxspeed;
clearTimeout(righttime);
if (movestate!="left") prodMoveleft();
}
else if (curposy<prodLeftbound){
scrollspeed=(prodLeftbound-curposy)/((prodMenuwidth-prodRestarea)/2) * prodMaxspeed;
clearTimeout(lefttime);
if (movestate!="right") prodMoveright();
}
else
scrollspeed=0;
}

function prodContains_ns6(a, b) {
if (b!==null)
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function prodStopmotion(e){
if (!window.opera||(window.opera&&e.relatedTarget!==null))
if ((window.event&&!prodCrossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !prodContains_ns6(e.currentTarget, e.relatedTarget))){
clearTimeout(lefttime);
clearTimeout(righttime);
movestate="";
}
}


function prodFillup()
{
    if (prodIedom)
    {
        prodCrossmain=document.getElementById? document.getElementById("productcontainer") : document.all.productcontainer;
        if(typeof prodCrossmain.style.maxWidth!=='undefined')
            prodCrossmain.style.maxWidth=prodMaxwidth+'px';
        prodMenuwidth=prodCrossmain.offsetWidth;
        prodCross_scroll=document.getElementById? document.getElementById("productgallery") : document.all.productgallery;
        actualwidth=document.getElementById? document.getElementById("productNobr").offsetWidth : document.all['productNobr'].offsetWidth;
        if (prodStartpos)
            prodCross_scroll.style.left=(prodMenuwidth-actualwidth)/prodStartpos+'px';
        prodCrossmain.onmousemove=function(e){
        prodMotionengine(e);
}

prodCrossmain.onmouseout=function(e)
{
    prodStopmotion(e);
    prodShowhidediv("hidden");
}
}
prodLoadedyes=1
if (prodEndofgallerymsg!=""){
prodCreatediv();
prodPositiondiv();
}
if (document.body.filters)
prodOnresize()
}

window.onload=prodFillup;


prodOnresize=function(){
if (typeof productcontainer!=='undefined'&&productcontainer.filters){
productcontainer.style.width="0";
productcontainer.style.width="";
productcontainer.style.width=Math.min(productcontainer.offsetWidth, prodMaxwidth)+'px';
}
prodMenuwidth=prodCrossmain.offsetWidth;
prodCross_scroll.style.left=prodStartpos? (prodMenuwidth-actualwidth)/prodStartpos+'px' : 0;
}
