﻿//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function pausescroller(itemscount, delay, step, lang)
{
    var scrollerinstance                        =   this;
    
    this.delay                                  =   0;              
    this.lang									=   lang;              
    this.step                                   =   0;
    this.itemscount                             =   CInt(itemscount, 0);
    this.delay                                  =   CInt(delay, 1);
    this.step                                   =   CInt(step, 20);
    this.stripWidth                             =   351;
    this.padding								=   10;
    
    this.marquePlaceId                          =   "marquePlace";      
    this.imagesPlaceId                          =   "imagesPlace";
    this.imagesPlaceTblId                       =   "imagesPlaceTbl";
    this.imageRowId                             =   "imageRow";
   
    if      (window.addEventListener)           window.addEventListener("load", function(){scrollerinstance.initialize()}, false);
    else if (window.attachEvent)                window.attachEvent("onload", function(){scrollerinstance.initialize()});
    else if (document.getElementById)           setTimeout(function(){scrollerinstance.initialize()}, 500);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
pausescroller.prototype.initialize              =   function()
{
    var scrollerinstance                        =   this;
    
    this.marquePlace                            =   document.getElementById(this.marquePlaceId);
    this.itemwidth                              =   117; // 10+117+10
    this.imagesPlace                            =   document.getElementById(this.imagesPlaceId);
    this.imagesPlaceTbl                         =   document.getElementById(this.imagesPlaceTblId);
    this.imageRow                               =   document.getElementById(this.imageRowId);
  
    if(this.imagesPlace) 
    {
        this.imagesPlace.style.width            =   this.itemwidth*this.itemscount+'px';
        
//      ws("  itemscount="+this.itemscount+" itemwidth="+this.itemwidth+" imagesPlace.width="+this.imagesPlace.style.width);
        
        this.imagesPlaceTbl.style.width         =   this.imagesPlace.style.width;
		
		if(this.lang=='he')
		{ 
			this.imagesPlace.style.left         =   -1*CInt(this.imagesPlace.style.width, 0) + this.stripWidth+'px';
        }
        else
        {
			this.imagesPlace.style.left			-=	this.padding;
        }		
    }
    if (window.attachEvent)     
    {
        try
        {
            if ( scrollerinstance != null && scrollerinstance.marquePlace != null)
                window.attachEvent("onunload", function(){scrollerinstance.marquePlace.onmouseover=scrollerinstance.marquePlace.onmouseout=null});
        }
        catch(e)
        {
        }
    }

//  ws("step="+this.step+"  imagesPlace.left="+this.imagesPlace.style.left+" stripWidth="+this.stripWidth+" imagesPlace.width="+this.imagesPlace.style.width+" itemwidth="+this.itemwidth);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
pausescroller.prototype.animate                 =   function()
{
    if(!this.imagesPlace)                        return;
    
    if(this.indx)                               clearTimeout(scroller.indx);

    var scrollerinstance                        =   this;
    var left                                    =   CInt(this.imagesPlace.style.left, 0);
    var width                                   =   CInt(this.imagesPlace.style.width, 0);
    var add										=	this.lang=='he'?'':this.itemwidth+this.padding;
 
//  ws("step="+this.step+"  imagesPlace.left="+left+" stripWidth="+this.stripWidth+" imagesPlace.width="+width+" itemwidth="+this.itemwidth+" sum="+(width-this.stripWidth-add));
 
    if (((width-this.stripWidth-add)>=Math.abs(left)) && this.step>0)
    {
        this.imagesPlace.style.left             =   (CInt(this.imagesPlace.style.left)-this.step)+"px";
        
        this.indx                               =   setTimeout(function(){scrollerinstance.animate()}, this.delay);
    }
    else if (left<0 && this.step<0)
    {
        this.imagesPlace.style.left             =   (CInt(this.imagesPlace.style.left)-this.step)+"px";
       
        this.indx                               =   setTimeout(function(){scrollerinstance.animate()}, this.delay);
    }
    else if(this.imageRow.firstChild)
    {
//        if(this.indx) clearTimeout(scroller.indx);   return;
    
        if(this.step>0)
        {
            if(this.imagesPlace) 
            {
                var firstChild                  = this.imageRow.firstChild;
                var lastChild                   = this.imageRow.lastChild;
                
                this.imageRow.removeChild(firstChild);
                this.imageRow.appendChild(firstChild);
                this.imagesPlace.style.left     =   (left + this.itemwidth)+'px';

                this.indx                       =   setTimeout(function(){scrollerinstance.animate()}, this.delay);
            }  
            else
            {
                if(this.indx)                   clearTimeout(scroller.indx);
            } 
        }
        else if(this.step<0)
        {
            if(this.imagesPlace) 
            {
                var firstChild                  = this.imageRow.firstChild;
                var lastChild                   = this.imageRow.lastChild;

                this.imageRow.removeChild(lastChild);
                this.imageRow.insertBefore(lastChild, firstChild);
                this.imagesPlace.style.left     =   (left - this.itemwidth)+'px';

                this.indx                       =   setTimeout(function(){scrollerinstance.animate()}, this.delay);
            }  
            else
            {
                if(this.indx)                   clearTimeout(scroller.indx);
            } 
        }
        else
        {
            if(this.indx)                       clearTimeout(scroller.indx);
        }
    }
    else
    {
        if(this.indx)                           clearTimeout(scroller.indx);
    }
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function stopAnimate(o)
{
    if(scroller && scroller.indx)
    {
        clearTimeout(scroller.indx);
    }
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function startAnimate(direction, delay)
{
//    return;
//    ws("step="+step);

    this.lang									=   document.getElementById("marquePlace").lang;              
    
    if(this.lang=='he')
    {
		if(scroller.itemscount<4)                  return;
    }
    else
    {
		if(scroller.itemscount<5)					return;
    }
    stopAnimate(null);
    
    scroller.linkedbutton                       =   null;
    scroller.direction                          =   direction;
    scroller.step                               =   direction>0?Math.abs(scroller.step):-1*Math.abs(scroller.step);
    scroller.left                               =   '0px';
    
    scroller.indx                               =   setTimeout(function(){scroller.animate()}, delay?delay:scroller.delay);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
