// JavaScript Document
(function () {
    YAHOO.namespace('example');

    var Dom = YAHOO.util.Dom;

    // Slider has a range of 300 pixels
    var range = 300;

    // Set up 30 pixel ticks
    var tickSize = 30;

    // Initial values for the thumbs
    //var initValues = [<!--{$pval_min}-->,<!--{$pval_max}-->];

    YAHOO.util.Event.onDOMReady(function () {

        // Create the DualSlider
        var slider = YAHOO.widget.Slider.getHorizDualSlider("p_slider_bg",
            "p_slider_min_thumb", "p_slider_max_thumb",
            range, tickSize, initValues);
        
        // Decorate the DualSlider instance with some new properties and
        // methods to maintain the highlight element
        YAHOO.lang.augmentObject(slider, {
            _highlight : Dom.get("p_slider_highlight"),

            updateHighlight : function () {
                var delta = this.maxVal - this.minVal;
                
                if (this.activeSlider === this.minSlider||this.activeSlider === this.maxSlider) {
					// If the min thumb moved, move the highlight's left edge
                    Dom.setStyle(this._highlight,'left', (this.minVal + 12) + 'px');
                }
                // Adjust the width of the highlight to match inner boundary
                Dom.setStyle(this._highlight,'width', Math.max(delta - 7,0) + 'px');
            }
        },true);


        // Attach the highlight method to the slider's change event
        slider.subscribe('change',slider.updateHighlight,slider,true);
        slider.subscribe('ready',slider.updateHighlight,slider,true);

		// Create an event callback to update some display fields
        var report = function () {
			price_min = fngetRealVal(p_min,p_max,range,slider.minVal);
			fnprintp_minval(price_min);
			price_max = fngetRealVal(p_min,p_max,range,slider.maxVal);
			fnprintp_maxval(price_max);
        };


        var se = function () {
			price_min = fngetRealVal(p_min,p_max,range,slider.minVal);
			price_max = fngetRealVal(p_min,p_max,range,slider.maxVal);
			fnChangePrice();//js動かないときはブラウザでエラーチェック
			initValues = [slider.minVal,slider.maxVal];
        };

        // Subscribe to the slider's change event to report the status.
        slider.subscribe('change',report);
        slider.subscribe('slideEnd',se);

    });
})();
