﻿function init(nrOfImg, objParent)
{
    idTimer    = 0;
    xTime      = 0.1;
    xSpeed     = 10;
    nrOfImages = parseInt(nrOfImg);
    coordImg   = new Array(nrOfImages);   
    widthParent = parseInt(document.getElementById(objParent).clientWidth);    
    
        
    tempWidth  = 0;  
    for(i=0 ;i< nrOfImages; ++i)
    {
        tempWidth = tempWidth + (parseInt(document.getElementById("img" + i ).width + 5))
        coordImg[i] = widthParent - tempWidth;
    }
   
    move();    
}
function move()
{
    
    for(i=0 ; i< nrOfImages; ++i)
    {       
        widthImg = parseInt(document.getElementById("img" + i ).width);
        if(coordImg[i] > widthParent)
            coordImg[i]= minim(i) - (widthImg + 5) ; 
        else
           coordImg[i] += xSpeed * xTime
         
        document.getElementById("img" + i).style.left = coordImg[i] + "px";
    }   
        
    idTimer = setTimeout("move()",45);
}
function minim(i)
{
    if(i>0)
        return coordImg[i-1];
    else
        if(nrOfImages >0)
            return coordImg[nrOfImages-1];
        else 
            return 0;
}

function stop()
{
    clearTimeout(idTimer);
}



