function UKBreakPrices(preLoadData) {
  var callback = this;
  this.enabled = true;
  this.containerSelector = '#uk-journey-form';
  this.container = $(this.containerSelector);
  this.journeyDetailsContainer = $('#uk-journey-details');
  this.journeySelected=false;
  this.data = {};
  
  this.journeyDetailsContainer.find('.uk-journey-change').bind('click', function () {
    callback.journeySelected=false;
    callback.refreshPage();
    callback.journeyDetailsContainer.hide();
    callback.container.show();
    $('.break-price').hide();
  });

  //$('.uk-break-section p.hotel a').bind('click', function () {
  //    if(callback.validate() && callback.journeySelected) {
  //        return true;
  //    } else {
  //        location.href='#uk-journey-form';
  //        return false;
  //    }
  //});
  
  $('.break-price').hide();
  //this.journeyDetailsContainer.hide();
  
  callback.container.show();
  
  this.container.find('input.date-picker').datepicker({
        showOn: 'both',
        buttonImage: '/assets/gfx/calendar.gif',
        buttonImageOnly: true,
        dateFormat: 'dd/mm/yy',
        minDate: '+7d',
        maxDate: '+365d',
        closeText: 'X',
        closeAtTop: true
  });
  
  $stationName = this.container.find('input[name="StationName"]');
  
  var processStation = function(event, ui) {
            if(ui.item)
            {
                callback.container.find('input[name="StationName"]').val(ui.item.value);
                $('#uk-station-error').fadeOut();
                $(this).data('match', true);
            } else {
                if(event.type == 'autocompletechange')
                {
                    $stationName.autocomplete('search');
                }
                $('#uk-station-error').fadeIn();
                $(this).data('match', false);
            }
  };
            
  $stationName.autocomplete({
        source:'/ajax/ukbreaks/stationsearch',
        minLength: 2,
        select: processStation,
        change: processStation
  });
  

  this.container.find('input[name="submit"]').bind('click', function () {
    if(callback.validate()) callback.submit();
  });
  
  this.validate = function () {
      if(!this.container.find('input[name="StationName"]:first').data('match')) {
      this.container.find('input[name="StationName"]:first').focus();
      this.container.find('input[name="StationName"]:first').select();
        $('#uk-station-error').fadeIn();
    }
    
    if(!this.container.find('input[name="StationName"]:first').data('match') || this.container.find('input[name="Date"]:first').val()=='' || this.container.find('select[name="Duration"]:first').val()=='') {
      $('#uk-journey-error').fadeIn();
      return false;
    }
        
    $('#uk-journey-error').fadeOut();
    return true;
  }
  

  this.refreshPage = function () {
    this.updatePage(this.data);
  }

  
  this.updatePage = function (data, init) {

    if(typeof(data)!='object') return false;
    if(typeof(init)=='undefined') init=false;

    if(typeof(data.StationName)=='string' &&  typeof(data.Date)=='string' && typeof(data.Duration)=='string') {
      this.container.find('input[name="StationName"]').val(data.StationName).data('match', true);
      this.container.find('input[name="Date"]').val(data.Date);
        this.container.find('select[name="Duration"]').val(data.Duration);
      this.journeySelected=true;
    }

    this.journeyDetailsContainer.find('.uk-journey-station-name').text(this.container.find('input[name="StationName"]:first').val());
    this.journeyDetailsContainer.find('.uk-journey-date').text(this.container.find('input[name="Date"]:first').val());
    var nights = this.container.find('select[name="Duration"]:first').val();
    this.journeyDetailsContainer.find('.uk-journey-duration').text(nights);    
    this.journeyDetailsContainer.find('.uk-journey-duration-s').text(nights>1 ? 's' : '');
    
    if(this.journeySelected) {
      this.container.hide();
      this.journeyDetailsContainer.show();
      $('.break-price').show();
    }
    
    if(typeof(data.HotelID)!='undefined') {
      this.data.HotelID=data.HotelID;
    }
    
    
    if(typeof(data.Hotels)=='object') {
      this.data.Hotels=data.Hotels;
      if((init && data.SessionSet) || !init) {
        var hotelContainer = $('.uk-break-hotel-list:first');
        hotelContainer.hide();
        var visibleCount=0;
        for(var i=0; i<data.Hotels.length; i++) {  
            // $('p.hotel[value="'+data.Hotels[i].ID+'"] .uk-break-hotel').html(data.Hotels[i].PriceFormatted);
            $('.uk-break-hotel-fprice-'+data.Hotels[i].ID+' .fprice').html(data.Hotels[i].PriceFormatted);
          if(this.journeySelected && data.Hotels[i].Visible) {
            // $('p.hotel[value="'+data.Hotels[i].ID+'"]').show();
            $('.uk-break-hotel-fprice-'+data.Hotels[i].ID).show();
            visibleCount++;
          } else {
            // $('p.hotel[value="'+data.Hotels[i].ID+'"]').hide();
            $('.uk-break-hotel-fprice-'+data.Hotels[i].ID).hide();
          }
        }
        
        if(visibleCount==0) $('#uk-break-no-prices').show();
        else $('#uk-break-no-prices').hide();
        
        if(init) {
          hotelContainer.show();
        } else {
          hotelContainer.show('slide', {'direction': 'up'}, 'slow');
        }
      }
    }

    if(typeof(data.Rooms)=='object') {
      this.data.Rooms=data.Rooms;
      var roomContainer = $('.uk-break-rooms-list:first');
      roomContainer.hide();
      $('.uk-break-room').hide();
           
      for(var i=0; i<data.Rooms.length; i++) {
        // $('.uk-break-room[value="'+data.Rooms[i].room_id+'"]').show();
        $('.uk-break-room-'+data.Rooms[i].room_id).show();
        // $('.uk-break-room[value="'+data.Rooms[i].room_id+'"] .uk-break-room-price').html(data.Rooms[i].PriceFormatted);
        $('.uk-break-room-'+data.Rooms[i].room_id+' .uk-room-price').html(data.Rooms[i].PriceFormatted);
        // $('.uk-break-room[value="'+data.Rooms[i].room_id+'"] .uk-break-room-dates').html(data.Rooms[i].Dates);
        $('.uk-break-room-'+data.Rooms[i].room_id+' .uk-room-dates').html(data.Rooms[i].Dates);      
      }
    
      if(this.journeySelected) {
        if(data.Rooms.length==0) $('#uk-break-no-prices').show();
        else $('#uk-break-no-prices').hide();

        if(init) {
            roomContainer.show();
        } else {
          roomContainer.show('slide', {'direction': 'up'}, 'slow');
        } 
      } else {
        $('#uk-break-no-prices').hide();
      }
    }
  }
  
  this.serverError = function () {
      $('#uk-journey-server-error').fadeIn();
    this.journeyDetailsContainer.hide();
    this.container.hide();
    $('.break-price').hide();
    $('#uk-journey-error').hide();
  }
  
  this.submit = function () {
  
    this.disable();
    var callback = this;
    
    $.get('/ajax/ukbreaks/getprices', {formType: this.formType, type: 'submit', data: $.toJSON(this.getValues())},
        function(data){
          var objData;
          try {
            objData = $.secureEvalJSON(data);
          } catch (err) {
            callback.serverError();
            return;
          } 
          
          callback.submitResult(objData);
          
        });
  }
  
  this.submitResult = function (data) {
    if(typeof(data)!='object') data = {success: 0};

    if(data.success>0) {
      this.journeySelected=true;
      this.updatePage(data);
    } else {
      //alert('success=0: ' + $.toJSON(data));
      this.serverError();
    }
    this.enable();
  }
  
  this.getValues = function () {
    var data = {};
    this.container.find('input[type=text],input[type=hidden],input[type=radio]:checked,input[type=checkbox]:checked,select,textarea').each(function (i, j) {
      j=$(j);
      var name=j.attr('name');
      var value=j.val();    
      if(typeof(name)!='undefined') data[name]=value;
    });
    
    this.container.find('input.date-picker').each(function (i, j) {
      j=$(j);
      var name=j.attr('name');
      var value=$.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd/mm/yy', j.val()));
      if(typeof(name)!='undefined') data[name+'_mysql']=value;
    });
    
    if(typeof(this.data.HotelID)!='undefined') data.HotelID=this.data.HotelID;
    if(typeof(this.data.Hotels)=='object' && this.data.Hotels.length){
      data.Hotels = [];
      for(var i=0; i<this.data.Hotels.length; i++) {
        data.Hotels[i]=this.data.Hotels[i].ID;
      }
    }
    
    //$('#uk-break-debug').empty().html($.toJSON(data));
    
    return data;
  }
  
  this.disable = function () {
    
    var callback = this;
    if(!this.enabled) {
      window.setTimeout('$("'+this.containerSelector+'").trigger("callbackDisable");',1000);
      return false;
    }
    
    this.container.find('.ajax-busy').fadeIn('fast', function () {
      callback.enabled=false;
    });
    
    
  }
  
  this.enable = function () {
    var callback = this;
    
    if(this.enabled) {
      window.setTimeout('$("'+this.containerSelector+'").trigger("callbackEnable");',1000);
      return false;
    }
    
    this.container.find('.ajax-busy').fadeOut('fast', function () {
      callback.container.dialog('enable');
      callback.enabled=true;
    });
    
  }
  
  
  this.updatePage(preLoadData, true);
  
}



