
	surfacemax = document.getElementById('maxsurfacead').value;
	surfacefrom = document.getElementById('surfacefrom').value;
	surfaceto = document.getElementById('surfaceto').value;


(function () {
    YAHOO.namespace('example');

    var Dom = YAHOO.util.Dom;

    // Slider has a range of 200 pixels
    var range = 169;
	var rangecf = surfacemax;

    // No ticks for this example
    var tickSize = 0;

    // We'll set a minimum distance the thumbs can be from one another
    var minThumbDistance = -13;

    // Initial values for the thumbs
	var initValues = [surfacefrom,surfaceto];

    // Conversion factor from 0-200 pixels to 100-1000
    // Note 20 pixels are subtracted from the range to account for the
    // thumb values calculated from their center point (10 pixels from
    // the center of the left thumb + 10 pixels from the center of the
    // right thumb)
	var cf = rangecf/(range);
	
    // Set up a function to convert the min and max values into something useful
    var convert = function (val) {
        //return Math.round(val * cf + 100);
		return Math.round(val * cf);
    };

    // Slider set up is done when the DOM is ready
    YAHOO.util.Event.onDOMReady(function () {
        var surface_bg = Dom.get("sliderSurface"),
            info    = Dom.get("babebibobu"),
            from    = Dom.get("surfacefrom"),
            to      = Dom.get("surfaceto");

        // Create the DualSlider
        var slider = YAHOO.widget.Slider.getHorizDualSlider(surface_bg,
            "sliderValueSurfaceMin", "sliderValueSurfaceMax",
            range, tickSize, initValues);

        slider.minRange = minThumbDistance;
        
        // Custom function to update the text fields, the converted value
        // report and the slider's title attribute
        var updateUI = function () {
			//alert(to.value);
			from.value = slider.minVal;
            to.value   = slider.maxVal;
			//alert(to.value);

            // Update the converted values and the slider's title.
            // Account for the thumb width offsetting the value range by
            // subtracting the thumb width from the max value.
            var min = convert(slider.minVal),
                max = convert(slider.maxVal);// - 20);
			
			//document.getElementById('niko').innerHTML += min + "---" + max + "<br/>";
			//document.getElementById('niko').innerHTML += range + "<br/>";
			document.getElementById('surfaceAdMin').value = min;
			document.getElementById('surfaceAdMax').value = max;
			
			document.getElementById('surfaceMinSee').innerHTML = min;
			document.getElementById('surfaceMaxSee').innerHTML = max;
			
            /*info.innerHTML = "MIN: <strong>" + min + "</strong><br>" +
                             "MAX: <strong>" + max + "</strong>";
            surface_bg.title  = "Current range " + min + " - " + max;*/
        };

        // Subscribe to the dual thumb slider's change and ready events to
        // report the state.
        slider.subscribe('ready', updateUI);
        slider.subscribe('change', updateUI);

        // Wire up the button to update the slider
        YAHOO.util.Event.on('surface_btn','click',function () {
            // Get the int values from the inputs
            var min = Math.abs(parseInt(from.value,10)|0),
                max = Math.abs(parseInt(to.value,10)|0);

            if (min > max) {
                var hold = min;
                min = max;
                max = hold;
            }

            // Verify the values are in range
            min = Math.min(min,range - 30);
            max = Math.max(Math.min(max,range),min + 20 + minThumbDistance);

            // Set the new values on the slider
            slider.setValues(min,max);
        });
        // Attach the slider to the YAHOO.example namespace for public probing
        YAHOO.example.slider = slider;
    });
})();

