var rhcms = {
  slider : function(options)
  {
    this.options = options;
    
    this.slider = document.getElementById(options.id);
    
    this.slide_left = document.getElementById(options.id + '_left');
    
    this.slide_right = document.getElementById(options.id + '_right');
    
    this.slide_ul = this.slider.getElementsByTagName('ul')[0];
    
    if(!this.slider ||!this.slide_left || !this.slide_right || !this.slide_ul)
      return;
    
    var that = this;
    
    if(typeof this.options.onElementClick === 'function')
    {
      var elements = this.slide_ul.getElementsByTagName('img');
      for(e=0;e<elements.length;++e)
      {
        elements[e].tag = this;
        elements[e].onclick = function()
        {
          this.tag.options.onElementClick(this, that.slider);
        }
      }
    }
    
    this.width_slider = this.slider.offsetWidth;
    
    this.slide_direction = false;
    this.slide_interval = null;
    
    this.slide_left.tag = this;
    this.slide_left.onmousedown = function()
    {
      this.tag.startSlide('-');
    }
    
    this.slide_left.onmouseup = function()
    {
      this.tag.stopSlide();
    }
    
    this.slide_right.tag = this;
    this.slide_right.onmousedown = function()
    {
      this.tag.startSlide('+');
    }
    
    this.slide_right.onmouseup = function()
    {
      this.tag.stopSlide();
    }
    
    this.startSlide = function(direction)
    {
      that.slide_direction = direction;
      that.slide();
      that.slide_interval = window.setInterval(that.slide, 12);
    }
    
    this.stopSlide = function()
    {
      that.slide_direction = false;
      window.clearInterval(that.slide_interval);
      that.slide_interval = null;
    }
    
    this.slide = function()
    {
      if(that.slide_direction === false)
        return;
      
      var margin = that.slide_ul.style.marginLeft;
      
      if(margin === '')
      {
        margin = '0px';
      }
      
      margin = parseInt(margin.substr(0,margin.indexOf('px')));
      
      var width_ul = parseInt(that.slide_ul.offsetWidth);
      
      switch(that.slide_direction)
      {
        case '+' :
          if(margin < that.width_slider - width_ul)
          {
            that.stopSlide();
            return;
          }
          
          that.slide_ul.style.marginLeft = margin - 1 + 'px';
        break;
        case '-' :
          if(margin >= 0)
          {
            that.stopSlide();
            return;
          }
      
          that.slide_ul.style.marginLeft = margin + 1 + 'px';
        break;
      }
    }
  },
  switchCSSProperty:function(property, id1, id2, state1, state2, type, container)
  {
    var obj1 = document.getElementById(id1);
    var obj2 = document.getElementById(id2);
    
    if(type === '1' && obj1.style[property] === state2) // switch 1 back to state1
    {
      obj1.style[property] = state1;
      obj2.style[property] = state2;
      
      if(typeof container !== 'undefined')
      {
        document.getElementById(container.id).className = container.class1;
      }
    }
    else if(type === '2' && obj2.style[property] !== state1) // switch 2 to state2
    {
      obj1.style[property] = state2;
      obj2.style[property] = state1;
      
      if(typeof container !== 'undefined')
      {
        document.getElementById(container.id).className = container.class2;
      }
    }
    
    return false;
  },
  openPopup:function(href, data)
  {
    var data = typeof data !== 'undefined' ? data : {};
    var real = typeof real === 'undefined' ? true : real;
    
    var popup = window.open(href, typeof data.name === 'undefined' ? 'popup' : data.name,
      (typeof data.width !== 'undefined' ? 'width=' + data.width : 'width=400') +
      ',' +
      (typeof data.height !== 'undefined' ? 'height=' + data.height : 'height=300') +
      ',' +
      (typeof data.scrollbars !== 'undefined' ? 'scrollbars=' + data.scrollbars : 'scrollbars=yes')
    );
    popup.focus();
    
    return false;
  }
}