﻿PriceFilter = createSingleton(PriceFilter = {});

PriceFilter.prototype.init = function(args) {

    defaults = { list: null, preset: null, onChange: null, currency: '$', parentDiv: "" };
	for(var pr in defaults)
        this[pr] = isDefined(args[pr]) ?args[pr] :defaults[pr];
    this.validRange = null;
    var filter = this;
    
    var minFare = this.list.get('min(total)');
    var maxFare = this.list.get('max(total)');
    this.min = Math.floor(minFare.get('total'));
    this.max = Math.ceil(maxFare.get('total'));
    this.currency = minFare.get('currency');
    
    
    // Method for validating fare to be displayed
    this.isValidFare = function(fare) {
	    var amt = fare.get('total');
	    return (this.range[0] <= amt) && (amt <= this.range[1]);
    };
    
   this.hide = function() {
        $(this.parentDiv).style.display = "none";        
    };

    this.show = function() {
        $(this.parentDiv).style.display = "";        
    };
    
    this.container = new LeftFilter({ 
        caption: "Select Price Range",
        parentDiv: filter.parentDiv
    });
            
    this.slider = new SliderFilter({
        parentDiv: this.container.body,
        caption: "Select Price Range", 
        min: filter.min,
        max: filter.max, 
        rangeToText: function(v) { 
            return "<span style='font-family: tahoma'>" + 
			        filter.currency + "</span>&nbsp;" + v; 
        },
        preset: filter.preset,
        onChange: function() {
            if(filter.onChange)
                filter.onChange(filter);
        }
    });
    
    this.range = this.slider.range;  
    
    
};