﻿//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function pausescroller(itemscount, delay, step)
{
    var scrollerinstance                        =   this;
    
    this.itemscount                             =   CInt(itemscount, 0);
    this.delay                                  =   CInt(delay, 1);
    this.step                                   =   CInt(step, 20);
    this.stripWidth                             =   672;
    
    this.marquePlaceId                          =   "scroll_wrapper";      
    this.imagesPlaceId                          =   "imagesPlace";
    this.imagesPlaceTblId                       =   "imagesPlaceTbl";
    this.imageRowId                             =   "imageRow";
    
    if(this.itemscount<=6)						return;
   
    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                              =   110; // 10+90+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;
        this.imagesPlace.style.left              =   -1*CInt(this.imagesPlace.style.width, 0) + this.stripWidth+'px';
    }
    if (window.attachEvent)     window.attachEvent("onunload", function(){scrollerinstance.marquePlace.onmouseover=scrollerinstance.marquePlace.onmouseout=null});

	//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);
 
 
    if ((width-this.stripWidth>=Math.abs(left)) && this.step>0)
    {
//		ws("LEFT: step="+this.step+"  imagesPlace.left="+left+" stripWidth="+this.stripWidth+" imagesPlace.width="+width+" itemwidth="+this.itemwidth);
        
        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)
    {
//		ws("RIGHT: step="+this.step+"  imagesPlace.left="+left+" stripWidth="+this.stripWidth+" imagesPlace.width="+width+" itemwidth="+this.itemwidth);
        
        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)
{
	try
	{
		if(scroller && scroller.indx)
		{
			if(scroller.itemscount<=6)          return;
			
			clearTimeout(scroller.indx);
		}
    }
    catch(e){}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function startAnimate(direction, delay)
{
//    return;
//    ws("step="+step);

    if(scroller.itemscount<=6)                  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);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
