﻿TimeFilter = createClass();

TimeFilter.prototype.init = function(args) {

    defaults = { list: null, caption: "", farePr: "", preset: null, onChange: null,
                 parentDiv: "TimeSliderDiv", caption: "", footerCap: "" };
	for(var pr in defaults)
        this[pr] = isDefined(args[pr]) ?args[pr] :defaults[pr];
    this.validRange = null;
    var filter = this;
    
    this.min = this.list.get("min(" + this.farePr + ")").get(this.farePr);
    this.max = this.list.get("max(" + this.farePr + ")").get(this.farePr);

    // Method for validating fare to be displayed
    this.isValidFare = function(fare) {
	    var mins = fare.get(this.farePr);
	    return (this.range[0] <= mins) && (mins <= this.range[1]);
    };
    
    this.hide = function() {
        $(this.parentDiv).style.display = "none";        
    };

    this.show = function() {
        $(this.parentDiv).style.display = "";        
    };
    
    this.container = new LeftFilter({ 
        caption: filter.caption,
        parentDiv: filter.parentDiv
    });
    
    this.slider = new SliderFilter({
        caption: filter.caption, 
        footerCap: filter.footerCap,
        parentDiv: this.container.body,
        min: filter.min,
        max: filter.max,
        rangeToText: function(v) { 
            v = parseInt(v); 
            return Util.formatInt(parseInt(v/60), 2) + ':' + Util.formatInt(v%60, 2); 
        },
        preset: filter.preset,
        onChange: function() {
            if(filter.onChange)
                filter.onChange(filter);
        }
    });
    
    this.range = this.slider.range;  
};



