var slide = function(properties)
{
  var that = this;
  
  /* PROPERTIES */
  
  this.properties = properties;
  
  if(typeof that.properties.scrollAmount === 'undefined')
    that.properties.scrollAmount = 1;
  
  if(typeof that.properties.elementWidth === 'undefined')
    that.properties.elementWidth = 140;
  
  if(typeof that.properties.show === 'undefined')
    that.properties.show = 4;
  
  /* OPTIONS */
  
  this.isScrolling = false;
  
  this.ul = null;
  
  this.currentWidth = null;
  
  this.maxOffset = that.properties.show - 1;
  
  this.offset = that.properties.show - 1; 
  
  this.id = 'SLIDE_' + Math.random();
  
  window[this.id] = that;
  
  /* SET THE TOTAL NUMBER */
  
  this.setTotal = function(num)
  {
    that.total = num;
  }
  
  /* Scroll by type */
  
  this.scrollByType = function(type)
  {
    if(that.isScrolling)
      return false;
      
    if(that.ul === null)
    {
      that.ul = document.getElementById(that.properties.id);
      
      if(!that.ul.tagName || that.ul.tagName.toLowerCase() !== 'ul')
      {
        that.ul = that.ul.getElementsByTagName("ul")[0];
      }
    }

    if(that.currentWidth === null)
    {
      that.currentWidth = that.ul.offsetWidth;
    }
    
    /* alert(that.properties.total + ', ' + (that.offset + that.properties.scrollAmount)); */
    
    if(type === '+' && (that.properties.total === null || that.offset + that.properties.scrollAmount < that.properties.total || (that.properties.scrollAmound > 1 && that.offset + (2 * that.properties.scrollAmount) < that.properties.total)))
    {
      that.offset += that.properties.scrollAmount;
      that.currentWidth += that.properties.elementWidth;
      that.ul.style.width = that.currentWidth + 'px';
      
      that.slide(type);
      
      if(that.offset > that.maxOffset)
      {
        that.maxOffset = that.offset;
        var request = new ajaxRequest({
          url       : that.properties.url + '?offset=' + that.offset + '&show=' + that.properties.show,
          type      : 'GET',
          callback  : that.elementCallback
        });
        request.startRequest();
      }
    }
    else if(type === '-')
    {
      if(that.offset <= that.properties.show - 1)
        return;
      
      that.offset -= 1;
      that.slide(type);
    }
  }
  
  /* Slide it =) */
  
  this.slide = function(type)
  {
    var currentMarginLeft = that.ul.style.marginLeft;
    
    if(currentMarginLeft === '')
    {
      currentMarginLeft = 0;
    }
    else
    {
      currentMarginLeft = parseInt(currentMarginLeft.substr(0, currentMarginLeft.indexOf("px")));
    }
    
    if(type === '+')
    {  
      currentMarginLeft -= 140;
      
      that.isScrolling = true;
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft + 45) + "px';", 75);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft + 25) + "px';", 150);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft + 15) + "px';", 225);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft + 10) + "px';", 300);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft + 5) + "px';", 375);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft) + "px'; window['" + that.id + "'].isScrolling = false;", 450);
    }
    else if(type === '-')
    {
      currentMarginLeft += 140;
      
      that.isScrolling = true;
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft - 45) + "px';", 0);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft - 25) + "px';", 75);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft - 15) + "px';", 150);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft - 10) + "px';", 225);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft - 5) + "px';", 300);
      window.setTimeout("window['" + that.id + "'].ul.style.marginLeft = '" + (currentMarginLeft) + "px'; window['" + that.id + "'].isScrolling = false;", 375);
    }
  }
  
  this.elementCallback = function(response)
  {
    var elements = response.xml.getElementsByTagName(that.properties.element);
    
    for(var e=0;e<elements.length;e+=1)
    {
      var element = elements[e];
      
      that.ul.appendChild(that.properties.callback(element));
    }
  }
}