
var TO;
var padding = 5;  //padding-right
function InitSlideShow(id)
{
 document.onmouseup = OnMouseUp;
 var obj=document.getElementById(id);
 var imgs=obj.getElementsByTagName('IMG');
 var lft=0;
 var totalWidth=0;
 var slideControls =document.getElementById('slideshowControls');
 var obj=document.getElementById('thumbnails');
 
 if(imgs.length > 0 )
 {
     //The following lines the images up in a row.
     imgs[0].style.left='0px';
     for (var x=1;x<imgs.length;x++)
     {
       lft+=imgs[x-1].width+padding;
       imgs[x].style.left=lft+'px';
     }
     totalWidth = lft + imgs[imgs.length-1].width;
    
     
     if( totalWidth < 570)
     {
        obj.style.width = totalWidth+'px';
        slideControls.style.display = 'none';
        obj.style.backgroundColor = '#dfdfbf';
        obj.style.border = 'solid 2px #dfdfbf';
        
       
     }
     else
     {
       totalWidth=570;
       obj.style.width = totalWidth+'px';
       obj.style.backgroundColor = '#FFF';
        obj.style.border = 'solid 2px #FFF';
     }
 }
 else //hide slide show
 {
   
   obj.style.display = 'none';
 }
}

function OnMouseUp()
{
 clearTimeout(TO);
}

function SSRotate(id,lr){
 clearTimeout(TO);
 var obj=document.getElementById(id);
 var imgs=obj.getElementsByTagName('IMG');

 if (lr > 0 ) // back button
 {
    if(parseInt(imgs[0].style.left) <=0 )
    {
    for (var x=0;x<imgs.length;x++)
    {
      imgs[x].style.left=(parseInt(imgs[x].style.left)+lr)+'px';
    }
    TO=setTimeout( function(){ SSRotate(id,lr); },10);
    }
 }
 else //forward button
 {
   if(  (parseInt(imgs[imgs.length-1].style.left) + parseInt(imgs[imgs.length-1].width))  >= parseInt(obj.style.width)    )
    {
    for (var x=0;x<imgs.length;x++)
    {
      imgs[x].style.left=(parseInt(imgs[x].style.left)+lr)+'px';
    }
    TO=setTimeout( function(){ SSRotate(id,lr); },10);
    }

 }
 
}

