function stopEvent(e) 
{ 
    e = e || event; 
    e.stopPropagation? e.stopPropagation() : e.cancelBubble = true; 
}

(function(w)
{
  var rh = function(s, c)
    {
      return new rh.fn.init(s, c);
    },
    boundReady = false,
    readyList = [],
    onLoad,
    slice = Array.prototype.slice;
  
  rh.fn = rh.prototype = {
    length:0,
    pointer:0,
    init: function(s, c)
    {
      if(!c)
        var c = document;
      
      if(!s)
        return this;
      
      if(typeof s === 'string')
      {
        if(s.substr(0,1) === '#')
        {
          var e = c.getElementById(s.substr(1));
          
          if(e)
          {
            this[this.length++] = e;
          }
          
          return this;
        }
        else
        {
          return rh.merge(this, c.getElementsByTagName(s));
        }
      }
      else if(rh.isFunc(s))
      {
        this.ready(s, c);
        return this;
      }
      else if(s.nodeType)
      {
        this[0] = s;
        this.length = 1;
      }
      else if(typeof s === 'object')
      {
        return rh.merge(this, s);
      }
    },
    ready : function(f, c)
    {
      rh.bindReady();
      
      if(typeof c === 'undefined')
        var c = document;
      
      if(rh.isReady)
      {
        f();
      }
      else
      {
        readyList.push([f,c]);
      }
    },
    each : function(c, a)
    {
      return rh.each(this, c, a);
    },
    toArray : function()
    {
      return slice.call(this, 0);
    },
    reset : function(x)
    {
      this.pointer = !x || x > 0 ? 0 : this.length-1;
      
      return this;
    },
    next : function(f)
    {
      if(!this[this.pointer])
        return false;
      
      f.call(this, this[this.pointer++]);
      
      return this;
    },
    previous : function(f)
    {
      if(!this[this.pointer])
        return false;
      
      f.call(this, this[this.pointer--]);
      
      return this;
    },
    current : function(f)
    {
      if(!this[this.pointer])
        return false;
      
      return rh(this[this.pointer]);
    },
    get : function(p)
    {
      return this[!p ? 0 : p];
    }
  }
  
  rh.fn.init.prototype = rh.fn;
  
  rh.extend = rh.fn.extend = function(a)
  {
    for(name in a)
    {
      this[name] = a[name];
    }
  }
  
  // Extend the RH function itself
  
  rh.extend({
    isFunc : function(f)
    {
      return typeof f === 'function';
    },
    bindReady : function()
    {
      if(boundReady)
        return;
      
      boundReady = true;
      
      if (document.readyState === "complete" )
      {
  			return rh.ready();
  		}
      
      if ( document.addEventListener )
      {
			  document.addEventListener( "DOMContentLoaded", onLoad, false );
		  }
      else if ( document.attachEvent )
      {
			  document.attachEvent("onreadystatechange", onLoad);
      }
    },
    isReady: false,
    ready: function()
    {
      if(rh.isReady)
        return;
      
      rh.isReady = true;
      
      if(!readyList)
        return;
      
      var fn, i = 0;
			while((fn = readyList[i++]))
      {
				fn[0].call(fn[1]);
			}
    },
    each: function(o, c, a)
    {
      var name, l = o.length, isObj = l || rh.isFunc((o));
      
      if(a)
      {
        for(name in o)
        {
          c.apply(o[name], a);
        }
      }
      else
      {
        if(isObj)
        {
          for(var name=0;name<o.length;name++)
          {
            c.call(o[name]);
          }
        }
        else if(o.length > 0)
        {
          c.call(o[0]);
        }
      }
      
      return o;
    },
    merge: function(o, a)
    {
      i = o.length;
      
      for(var c=0;i<a.length;c++)
      {
        o[i++] = a[c];
      }
      
      o.length = i;
      
      return o;
    }
  });
  
  if(document.addEventListener)
  {
  	onLoad = function()
    {
  		document.removeEventListener("DOMContentLoaded", onLoad, false);
  		rh.ready();
  	};
  
  }
  else if(document.attachEvent)
  {
  	onLoad = function()
    {
  		if(document.readyState === "complete" )
      {
  			document.detachEvent("onreadystatechange", onLoad);
  			rh.ready();
  		}
  	};
  }
  
  w.rh = rh;
})(window);

/* hide */

(function(rh)
{
  rh.fn.hide = function()
  {
    return this.each(function()
    {
      this.style.display = 'none';
    });
  }
})(rh);

/* hide */

(function(rh)
{
  rh.fn.show = function()
  {
    return this.each(function()
    {
      this.style.display = '';
    });
  }
})(rh);

/* set width */

(function(rh)
{
  rh.fn.width = function(w)
  {
    return this.each(function()
    {
      this.style.width = w;
    });
  }
})(rh);

/* set height */

(function(rh)
{
  rh.fn.height = function(h)
  {
    return this.each(function()
    {
      this.style.height = h;
    });
  }
})(rh);

/* set CSS */

(function(rh)
{
  rh.fn.css = function(p)
  {
    return this.each(function()
    {
      for(name in p)
      {
        this.style[name] = p[name];
      }
    });
  }
})(rh);

/* click */

(function(rh)
{
  rh.fn.click = function(cb)
  {
    return this.each(function()
    {
      this.onclick = cb;
    });
  }
})(rh);

/* click */

(function(rh)
{
  rh.fn.change = function(cb)
  {
    return this.each(function()
    {
      this.onchange = cb;
    });
  }
})(rh);

/* keyup */

(function(rh)
{
  rh.fn.keyup = function(cb)
  {
    return this.each(function()
    {
      this.onkeyup = cb;
    });
  }
})(rh);

/* keydown */

(function(rh)
{
  rh.fn.keydown = function(cb)
  {
    return this.each(function()
    {
      this.onkeydown = cb;
    });
  }
})(rh);

/* Append HTML Element */

(function(rh)
{
  rh.fn.append = function(o, p)
  {
    if(typeof o === 'string')
      o = document.createElement(o);
    
    if(p)
    {
      for(name in p)
      {
        o.setAttribute(name, p[name] === null ? name : p[name], 0);
      }
    }
    
    this[0].appendChild(o);
    
    return rh(o);
  }
})(rh);

/* Fills a element with subelements */

(function(rh)
{
  rh.fn.fill = function(o, num, p)
  {
    if(typeof num === 'undefined')
      var num = 1;
    
    var list = [];
    
    this.each(function(){
      for(var i=1;i<=num;i++)
        list.push(rh(this).append(o, p)[0]);
    });
    
    return rh(list);
  }
})(rh);

/* Append HTML Element */

(function(rh)
{
  rh.fn.first = function(o, p)
  {
    if(typeof o === 'string')
      o = document.createElement(o);
    
    if(p)
    {
      for(name in p)
      {
        o.setAttribute(name, p[name] === null ? name : p[name], 0);
      }
    }
    
    this[0].insertBefore(o, this[0].firstChild);
    
    return rh(o);
  }
})(rh);

/* overwrites the current className property */

(function(rh)
{
  rh.fn.setClass = function(c)
  {
    return this.each(function(){
      this.className = c;
    });
  }
})(rh);

/* overwrites the current className property */

(function(rh)
{
  rh.fn.hasClass = function(c)
  {
    var classList = this.get().className.split(' ');
    
    for(name in classList)
    {
      if(c == classList[name])
        return true;
    }
    
    return false;
  }
})(rh);

/* overwrites the current className property */

(function(rh)
{
  rh.fn.removeClass = function(c)
  {
    return this.each(function(){
      this.className = '';
    });
  }
})(rh);

/* removes all classes */

(function(rh)
{
  rh.fn.removeClasses = function(c)
  {
    return this.each(function(){
      this.className = '';
    });
  }
})(rh);

/* adds a classname the current className property */

(function(rh)
{
  rh.fn.addClass = function(c)
  {
    return this.each(function(){
      this.className += ' ' + c;
    });
  }
})(rh);

/* Sets innerHTML */

(function(rh)
{
  rh.fn.html = function(html)
  {
    return this.each(function()
    {
      this.innerHTML = html;
    });
  }
})(rh);

/* Set the .value */

(function(rh)
{
  rh.fn.value = function(v)
  {
    if(typeof v == 'undefined')
      return this.get(0).value;
    
    return this.each(function()
    {
      this.value = v;
    });
  }
})(rh);

/* Enables an element */

(function(rh)
{
  rh.fn.enable = function()
  {
    return this.each(function()
    {
      this.disabled = false;
    });
  }
})(rh);

/* Disabled an element */

(function(rh)
{
  rh.fn.disable = function()
  {
    return this.each(function()
    {
      this.disabled = true;
    });
  }
})(rh);

/* Sets a attribute */

(function(rh)
{
  rh.fn.set = function(k, v)
  {
    return this.each(function()
    {
      this.setAttribute(k, v);
    });
  }
})(rh);

/* Opens a popup from a link */

(function(rh)
{
  rh.fn.popup = function(o)
  {
    return this.each(function()
    {
      rh(this).click(function(event)
      {
        event.preventDefault();
        
        o = o || {};
        
        var w = window.open(this.href, this.name ? this.name : 'popup', "dependent=yes,menubar=no,resizable=yes,location=no,status=no,toolbar=no,scrollbars=yes,left=" + (o.left ? o.left : 100) +
        ',top=' + (o.top ? o.top : 100) +
        ',width=' + (o.width ? o.width : 400) +
        ',height=' + (o.height ? o.height : 600));
        w.focus();
      })
    });
  }
})(rh);

/* get parent */

(function(rh)
{
  rh.fn.parent = function(tag)
  {
    var p = false;
    
    this.each(function()
    {
      if(p)
        return;
      
      node = this;
      
      while((node = node.parentNode) && node.tagName && node.tagName.toLowerCase() !== 'body')
      {
        if(node.tagName.toLowerCase() == tag.toLowerCase())
        {
          p = node;
          return;
        }
        
      }
    });
    
    if(!p)
      return false;
    
    return rh(p);
  }
})(rh);

/* filter elements */

(function(rh)
{
  rh.fn.filterProperty = function(f)
  {
    var filters = {
      selected:function(e)
      {
        return e.selected;
      },
      disabled:function(e)
      {
        return e.disabled;
      },
      enabled:function(e)
      {
        return !e.disabled;
      },
      hasValue:function(e)
      {
        return e.value && e.value  !== '' ? true : false;
      }
    }, tmp = [];
    
    // check if the filter exists
    if(typeof filters[f] === 'function')
      this.each(function()
      {
        if(filters[f](this))
          tmp.push(this);
      });
    
    // return new rh object with results
    return rh(tmp);
  }
})(rh);

/* AJAX */

(function(rh)
{
  rh.fn.ajax = function(prop)
  {
    return this.each(function()
    {
      // Make AJAX Request
      
      var xmlObject, that = this;
      
      try
      {
    		xmlObject = new XMLHttpRequest();
    	}
    	catch (e)
    	{
    		try
    		{
    			xmlObject = new ActiveXObject("Msxml2.XMLHTTP");
    		}
    		catch (e)
    		{
    			try
    			{
    				xmlObject = new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch (e)
    			{
    				alert("Your browser does not support AJAX!");
    				return false;
    			}
    		}
    	}
      
      xmlObject.onreadystatechange = function()
      {
      	if(xmlObject.readyState == 4)
        {
      		prop.ready.call(that, {
      		  text      : this.responseText,
            xml       : this.responseXML
      		});
      	}
      };
      
      if(typeof prop.type === 'undefined')
        prop.type = 'GET';
      
      prop.url = prop.url.replace('$1', encodeURIComponent(this.value));
      
      if(prop.data)
      {
        for(name in prop.data)
        {
          if(!prop.data[name] || !prop.data[name].length)
            continue;
          
          prop.url += '&' + name + '[]=' + prop.data[name].join('&' + name + '[]=');
        }
      }
      
      xmlObject.open(prop.type, prop.url, true);
    	xmlObject.setRequestHeader("Cache-Control", "must-revalidate");
    	xmlObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    	xmlObject.send(null);
    });
  }
})(rh);

/* retreives the width */

(function(rh)
{
  rh.fn.getWidth = function()
  {
    return this[0].offsetWidth;
  }
})(rh);

/* retreives the width */

(function(rh)
{
  rh.fn.getHeight = function()
  {
    return this[0].offsetHeight;
  }
})(rh);

/* retreives the top offset */

(function(rh)
{
  rh.fn.getTop = function()
  {
    var top = 0;
    
    var o = this[0];
    
    while(typeof o.offsetTop !== 'undefined' && o.tagName && o.tagName.toLowerCase() !== 'body')
    {
      top += o.offsetTop;
      o = o.offsetParent;
    }
    
    return top;
  }
})(rh);

/* retreives the top offset */

(function(rh)
{
  rh.fn.getLeft = function()
  {
    var left = 0;
    
    var o = this[0];
    
    while(typeof o.offsetLeft !== 'undefined' && o.tagName && o.tagName.toLowerCase() !== 'body')
    {
      left += o.offsetLeft;
      o = o.offsetParent;
    }
    
    return left;
  }
})(rh);

/* top */

(function(rh)
{
  rh.fn.top = function(t)
  {
    return this.each(function(){
      this.style.top = t;
    });
  }
})(rh);

/* left */

(function(rh)
{
  rh.fn.left = function(l)
  {
    return this.each(function(){
      this.style.left = l;
    });
  }
})(rh);


/* Slider */


(function(rh)
{
  rh.fn.slider = function(options)
  {
    return this.each(function(){
      
      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;
        }
      }
    });
  }
})(rh);

/* toggle */

(function(rh)
{
  rh.fn.toggleProperty = function(property, id1, id2, state1, state2, type, container)
  {
    return this.each(function()
    {
      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;
        }
      }
      
    });
  }
})(rh);

/* toggle */

(function(rh)
{
  rh.fn.toggleCSSProperty = function(property, state1, state2)
  {
    return this.each(function()
    {
      var x = rh(this);
      
      if(x.hasClass(state1))
      {
        x.setClass(state2);
      }
      else
      {
        x.setClass(state1);
      }
    });
  }
})(rh);

/* Suggest */

(function(rh)
{
  rh.fn.suggest = function(o)
  {
    var div = rh('body').first('div').hide().css({position:'absolute'}).setClass('suggest');

    var obj = o;
    
    var that = this;
    
    div.width(this.getWidth() + 'px');
    div.top(this.getTop() + this.getHeight() + 'px');
    div.left(this.getLeft() + 'px');
    
    var li_list = div.append('ul').fill('li', 15);
    
    var onKeyUp = function(event)
    {
      event = event || window.event;
      
      switch(event.keyCode)
      {
        case 13 : // RETURN
          div.hide();
          
          o.ready(li_list.current().get().tag);
          
          event.preventDefault();
        break;
        case 38 : // UP
          li_list.previous(function(o)
          {
            try
            {
              li_list.current().setClass('active');
              rh(o).removeClass('active');
            }
            catch(e){
              li_list.reset(1);
            }
          });
        break;
        case 40 : // DOWN
          li_list.next(function(o)
          {
            try
            {
              li_list.current().setClass('active');
              rh(o).removeClass('active');
            }
            catch(e)
            {
              li_list.reset(-1);
            }
          });
        break;
        default :
          that.ajax({
            url:o.url,
            ready:function(r)
            {
              div.show();
              li_list.hide().reset().removeClasses().current().setClass('active');
              
              rh('element', r.xml).each(function()
              {
                var element = this, value = this.firstChild.data;
                
                li_list.next(function(o)
                {
                  o.tag = element;
                  o = rh(o);
                  o.show().html(value);
                  rh(this).click(function()
                  {
                    div.hide();
                    obj.ready(this.tag);
                  });
                });
              });
              li_list.reset();
            }
          });
        break;
      }
    }
    
    this.each(function()
    {
      rh(this).keyup(onKeyUp);
      rh(this).keydown(function(event){
        event = event || window.event;
        
        switch(event.keyCode)
        {
          case 13 :
            event.preventDefault();
          break;
        }
      });
    });
    
    return this;
  }
})(rh);