jQuery.fn.jqueryTabs = function(targetUL, params){
  
  var animationSpeed = 500;
  
  var targets = jQuery(targetUL).find("> li");
  if(targets.length < 1) return;
  
  var current = 0;
  var wrapItems = false;
  // added horizontal scrolling as a parameter, set to True by default.
  // this was causing issues in the website proper which never uses it
  var horizontal_scrolling = true;
  
  if(params){
    if(params.currentLi) current = params.currentLi;
    if(params.wrap) wrapItems = params.wrap;
    // modified 2009-12-30, Luke Skibinski
    if(params.hasOwnProperty('hscroll')) horizontal_scrolling = params.hscroll;
  }
   
  //loop through all the target ULs lis and store their original displays
  targets.each(function(i, e){
    jQuery(this).data("tabDisplay", jQuery(this).css("display"));
    //hide this li if its not the current one
    if(i != current) jQuery(this).css({display:"none"});
  });
  
  //build nav for each item
  jQuery(this).each(function(i, e){
    
    var container = jQuery(e);
    if(container.css("position") != "absolute") container.css({position:"relative"});
    
    var containerWidth = container.outerWidth();
    var itemsWidth = 0;
    var offset = 0;
    
    var items = jQuery(e).find("> li");
    if(items.length < 1) return;
    
    items.each(function(i, e){
      var item = jQuery(e);
      //store this items id
      item.data("tabID", i);
      //if this is the current tab, add current class to it
      if(i == current) item.addClass("current");
      //setup position
      //item.css({position:"absolute", left:itemsWidth+"px"});
      item.data("left", itemsWidth);
      itemsWidth += item.outerWidth(true);
    });
    
    
    if(wrapItems){
      //put all the children in wrap
      var wrap = jQuery('<div></div>').css({overflow:"hidden", position:"absolute", top:"0", left:"0", width:container.outerWidth()+"px", height:container.outerHeight()+"px"});
      wrap.append(container.children());
      container.append(wrap);
    }   
    
    // the below adds horizontal scrolling to the booking site when the number 
    // of tabs required is greater than the space available
    if(horizontal_scrolling && (itemsWidth > containerWidth)) {
      var arrowRight = jQuery('<a class="arrow-right"></a>');
      container.append( arrowRight );
      arrowRight.click(function(){
        offset += containerWidth;
        if(offset > itemsWidth) {
          offset -= containerWidth;
          arrowRight.css({opacity:'0.2'});
          arrowLeft.css({opacity:'1'});
          return;
        } else {
          arrowLeft.css({opacity:'1'});
        }
        items.each(function(){
          jQuery(this).stop().animate({left: (jQuery(this).data("left")-offset)+"px"});
        });
      });
      
      var arrowLeft = jQuery('<a class="arrow-left"></a>');
      arrowLeft.css({opacity:'0.2'});
      container.append( arrowLeft );
      arrowLeft.click(function(){
        offset -= containerWidth;
        if(offset < 0) {
          offset = 0;
          arrowLeft.css({opacity:'0.2'});
          arrowRight.css({opacity:'1'});
          return;
        } else {
          arrowRight.css({opacity:'1'});
        }
        items.each(function(){
          jQuery(this).stop().animate({left: (jQuery(this).data("left")-offset)+"px"});
        });
      });
        
    }

    
    //setup clicks for each tab li
    items.click(function(){
      //hide all target uls lis
      targets.css({display:"none"});
      //find the li associated with this item
      var target = jQuery(targets.get(jQuery(this).data("tabID")));
      //set the target lis display back to what it was
      target.css({display:target.data("tabDisplay")});
      //set the current class on the correct tab
      jQuery(this).siblings().removeClass("current");
      jQuery(this).addClass("current");
      //override default click behaviour
      return false;
      
    });
      
  });
}
