

function prasAffiliateScroller(divid,options)
{
  this.imageWidth=options.width;
  this.imageHeight = options.height;
  this.delay=options.delay;
  //this.delay=5;
  this.increment = this.savedincrement=1;
  this.url=options.url;
  this.divid=$(divid);
  
  this.viewPortdiv=$(divid).parentNode;
  //var numHeight = this.viewPortdiv.style.height.replace(/px/,"");
  //numHeight=parseInt(numHeight)+10;
  //this.viewPortdiv.style.height = numHeight+'px';
  
  this.tmpid = $(divid+'_'+'tmp');
  this.divid.onmouseover=this.pauseScroll.bind(this);
  this.divid.onmouseout=this.resumeScroll.bind(this);
  
  //this.divid.onmouseout=this.resumeScroll.bind(this);
  $(divid+'_'+'up').onmouseover=this.downScroll.bind(this);
  $(divid+'_'+'down').onmouseover=this.upScroll.bind(this);
//  $(divid+'_'+'upload').onclick=this.doUpload.bind(this);

//  $(divid).onmouseover=this.pauseScroll.bind(this);
 //var button_ids = options.button_ids.split('|');
  this.loadData();
  var thispointer=this;
 
}


function getCount(str,pat)
{
  var count=0;
  for (var i=0;i<str.length;i++) {
   if (pat == str.substr(i,pat.length))
     count++;
  }
 return count;
}


prasAffiliateScroller.prototype = {
  loadData: function()
  {
    var thispointer = this;
        new Ajax.Request(thispointer.url+"?height="+this.imageHeight+"&width="+this.imageWidth, 
        { 
          asynchronous:true, 
          onSuccess: function(transport)
          {
                var data=transport.responseText;
                //alert(data);
                thispointer.divid.innerHTML = data;
                thispointer.divWidth=getCount(data,"<img") * 100;
                thispointer.startScroll();
          }
        }
        
  );
  },
  startScroll: function()
  {
  //alert(this.divid.style.left);
    //this.tmpid.innerHTML = this.divid.style.left+"   "+this.divWidth+" "+this.viewPortdiv.offsetWidth;
    if(parseInt(this.divid.style.left) < this.divWidth * (-1))
    {
      this.divid.style.left = this.viewPortdiv.offsetWidth+"px";
    }
    else if(parseInt(this.divid.style.left) > this.viewPortdiv.offsetWidth)
    {
      this.divid.style.left = ((this.divWidth * (-1))+10)+'px';
    }
    else
    {
      this.divid.style.left = (parseInt(this.divid.style.left) - this.increment) + "px";
    }
    this.timer = setTimeout(this.startScroll.bind(this),this.delay*5);
  },
  pauseScroll: function(e)
  {
    this.increment=0;
  },
  resumeScroll: function()
  {
    this.increment=this.savedincrement;
  },
  downScroll: function()
  {
    this.increment=-1;
  },
  upScroll: function()
  {
    this.increment=1;
  },
  doUpload:function()
  {
    $('imagesubmitdiv').style.display='block';
  }
  
   
  };   
