// Custom function to update the text fields, the converted value
// report and the slider's title attribute
function priceSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
		var Dom = YAHOO.util.Dom;
		
		var     from    = Dom.get("priceSlideL"),
				to      = Dom.get("priceSlideR"),
				fromBox = Dom.get("priceknob1"),
				toBox   = Dom.get("priceknob2");
				
				//tores    = Dom.get("swa_span"),
				
		
			//tores.innerHTML   = "Current range " + CurrencyFormatted(valLeft) + " - " + CurrencyFormatted(valRight);
	
		if(!updtMethod){ updtMethod = ''}
		switch(updtMethod)
		{
			case 'ready':
			{
				// ----------- execute code block 'ready'
				from.innerHTML = CurrencyFormatted(valLeft);
				to.innerHTML   = CurrencyFormatted(valRight);
				
				fromBox.value = CurrencyFormatted(valLeft);
				toBox.value   = CurrencyFormatted(valRight);
				//saveIt("cookiePrice",valLeft,valRight);
				break;
			}
			case 'slideStart':
			{
				// ----------- execute code block 'slideStart'
				break;
			}
			case 'change':
			{
				// ----------- execute code block 'change'
				from.innerHTML = CurrencyFormatted(valLeft);
				to.innerHTML   = CurrencyFormatted(valRight);
				
				fromBox.value = CurrencyFormatted(valLeft);
				toBox.value   = CurrencyFormatted(valRight);
				break;
			}
			case 'slideEnd':
			{ 
				// ----------- execute code block 'slideEnd'
				theResult();
				break;
			}
			default:
			{
				// ----------- execute default code block
				break;
			}
			
		}
		
	}

function claritySlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
		var Dom = YAHOO.util.Dom;
		
		var     from    = Dom.get("claritySlideL"),
				to      = Dom.get("claritySlideR"),
				fromBox = Dom.get("clarityknob1"),
				toBox   = Dom.get("clarityknob2");
		
			//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;
	
		if(!updtMethod){ updtMethod = ''}
		switch(updtMethod)
		{
			case 'ready':
			{
				// ----------- execute code block 'ready'
				from.innerHTML = ArrayClarity[Math.floor(valLeft)];
				to.innerHTML   = ArrayClarity[Math.floor(valRight)];
				
				fromBox.value = Math.floor(valLeft);
				toBox.value   = Math.floor(valRight);
				break;
			}
			case 'slideStart':
			{
				// ----------- execute code block 'slideStart'
				break;
			}
			case 'change':
			{
				// ----------- execute code block 'change'
				from.innerHTML = ArrayClarity[Math.floor(valLeft)];
				to.innerHTML   = ArrayClarity[Math.floor(valRight)];
				
				fromBox.value = Math.floor(valLeft);
			    toBox.value   = Math.floor(valRight);
				break;
			}
			case 'slideEnd':
			{ 
				// ----------- execute code block 'slideEnd'
				theResult();
				break;
			}
			default:
			{
				// ----------- execute default code block
				break;
			}
			
		}
		
	}

function caratSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("caratSlideL"),
            to      = Dom.get("caratSlideR"),
            fromBox = Dom.get("caratknob1"),
			toBox   = Dom.get("caratknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = CurrencyFormatted(valLeft);
			toBox.value   = CurrencyFormatted(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = CurrencyFormatted(valLeft);
			toBox.value   = CurrencyFormatted(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'

				
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function colorSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("colorSlideL"),
            to      = Dom.get("colorSlideR"),
            fromBox = Dom.get("colorknob1"),
			toBox   = Dom.get("colorknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = ArrayColor[Math.floor(valLeft)];
			to.innerHTML   = ArrayColor[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = ArrayColor[Math.floor(valLeft)];
			to.innerHTML   = ArrayColor[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function depthSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("depthSlideL"),
            to      = Dom.get("depthSlideR"),
            fromBox = Dom.get("depthknob1"),
			toBox   = Dom.get("depthknob2");

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function tableSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("tableSlideL"),
            to      = Dom.get("tableSlideR"),
            fromBox = Dom.get("tableknob1"),
			toBox   = Dom.get("tableknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = CurrencyFormatted(valLeft);
			toBox.value   = CurrencyFormatted(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = CurrencyFormatted(valLeft);
			to.innerHTML   = CurrencyFormatted(valRight);
			
			fromBox.value = CurrencyFormatted(valLeft);
			toBox.value   = CurrencyFormatted(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function fluoSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("fluoSlideL"),
            to      = Dom.get("fluoSlideR"),
            fromBox = Dom.get("fluoknob1"),
			toBox   = Dom.get("fluoknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = ArrayFluorescence[Math.floor(valLeft)];
			to.innerHTML   = ArrayFluorescence[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = ArrayFluorescence[Math.floor(valLeft)];
			to.innerHTML   = ArrayFluorescence[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function symSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("symSlideL"),
            to      = Dom.get("symSlideR"),
            fromBox = Dom.get("symknob1"),
			toBox   = Dom.get("symknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = ArraySymmetry[Math.floor(valLeft)];
			to.innerHTML   = ArraySymmetry[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = ArraySymmetry[Math.floor(valLeft)];
			to.innerHTML   = ArraySymmetry[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function cutSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;
	
	var     from    = Dom.get("cutSlideL"),
            to      = Dom.get("cutSlideR"),
            fromBox = Dom.get("cutknob1"),
			toBox   = Dom.get("cutknob2");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = ArrayCut[Math.floor(valLeft)];
			to.innerHTML   =  ArrayCut[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = ArrayCut[Math.floor(valLeft)];
			to.innerHTML   = ArrayCut[Math.floor(valRight)];
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}

function polSlider1Response(valLeft, valRight, updtMethod , minVal, maxVal)
	{
	var Dom = YAHOO.util.Dom;  
	
	var     from    = Dom.get("polSlideL"),
            to      = Dom.get("polSlideR"),
            fromBox = Dom.get("polknob1"),
			toBox   = Dom.get("polknob1");
	
		//tores.innerHTML   = "Current range " + valLeft + " - " + valRight;

	if(!updtMethod){ updtMethod = ''}
	switch(updtMethod)
	{
		case 'ready':
		{
			// ----------- execute code block 'ready'
			from.innerHTML = ArrayPolish[Math.floor(valLeft)];
			to.innerHTML   = ArrayPolish[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideStart':
		{
			// ----------- execute code block 'slideStart'
			break;
		}
		case 'change':
		{
			// ----------- execute code block 'change'
			from.innerHTML = ArrayPolish[Math.floor(valLeft)];
			to.innerHTML   = ArrayPolish[Math.floor(valRight)];
			
			fromBox.value = Math.floor(valLeft);
			toBox.value   = Math.floor(valRight);
			break;
		}
		case 'slideEnd':
		{ 
			// ----------- execute code block 'slideEnd'
			theResult();
			break;
		}
		default:
		{
			// ----------- execute default code block
			break;
		}
		
	}
	
}


function mySlider(inputRange, inputThumbWidth, inputTickSize, inputMinThumbDistance,  inputInitValues, inputValStart, inputValEnd, inputLeftThumbId, inputRightThumbId, inputSliderBgrndId, inputHighlightId, inputRespFunction) 
//function mySlider() 
{
	var range = inputRange; 
	var thumbWidth = inputThumbWidth;
	var tickSize = inputTickSize;
	var minThumbDistance = inputMinThumbDistance;
	var initValues = inputInitValues;
	var valStart = inputValStart;
	var valEnd = inputValEnd;
	var leftThumbId = inputLeftThumbId;
	var rightThumbId = inputRightThumbId;
	var sliderBgrndId = inputSliderBgrndId;
	var highlightId = inputHighlightId;
	var respFunction = inputRespFunction;
	
	
	var cf =  (valEnd - valStart)/(range - thumbWidth);
	
	// -----------  main code
	var Dom = YAHOO.util.Dom;

    // Set up a function to convert the min and max values into something useful
    function convert(valConvert) {
        //return val
		//return Math.round(val * cf + valStart);
		return (valConvert * cf + valStart);
    }

	function revertValue2pixel(valIn) {
       //alert(parseFloat(valIn[1]) + parseFloat(convert(thumbWidth)));
		
		posMin = (valIn[0] - valStart) / cf ;
		posMax = ( ( parseFloat(valIn[1]) + parseFloat( convert(thumbWidth) ) ) - valStart) / cf ;
		//posMax = ( ( parseFloat(valIn[1]) - valStart) / cf )  + parseFloat( convert(thumbWidth) );
		
		//alert(posMin+"--------"+posMax+"--------"+cf);
		
		return Array(posMin, posMax);
    }
	
	//var initValues = revertValue2pixel(inputInitValues);
	

    // Slider set up is done when the DOM is ready
    YAHOO.util.Event.onDOMReady(function () {
        var demo_bg = Dom.get(sliderBgrndId);

        // Create the DualSlider
        var slider = YAHOO.widget.Slider.getHorizDualSlider(demo_bg,
            leftThumbId, rightThumbId,
            range, tickSize, initValues);

        slider.minRange = minThumbDistance;
        
        //----------------------------------------------------
		// Decorate the DualSlider instance with some new properties and
        // methods to maintain the highlight element
        YAHOO.lang.augmentObject(slider, {
            _status : 'ok',
            _highlight : Dom.get(highlightId),

            getStatus : function () { return this._status; },

            updateHighlight : function () {
                
				var delta = this.maxVal - this.minVal;
                
                if (this.activeSlider === this.minSlider) {
                    // If the min thumb moved, move the highlight's left edge
                    Dom.setStyle(this._highlight,'left', (this.minVal + thumbWidth) + 'px');
                }
                // Adjust the width of the highlight to match inner boundary
                Dom.setStyle(this._highlight,'width', Math.max(delta - thumbWidth,0) + 'px');
            }
        },true);
		//----------------------------------------------------
		slider.subscribe('ready',slider.updateHighlight);
		slider.subscribe('change',slider.updateHighlight);
		
		
		
		// Custom function to update the text fields, the converted value
        // report and the slider's title attribute
        var updateUI = function (updtMethod) {
            // 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 valLeft = convert(slider.minVal),
                valRight = convert(slider.maxVal - thumbWidth);

			demo_bg.title  = "Current range " + valLeft + " - " + valRight;
			
			respFunction(valLeft, valRight, updtMethod, slider.minVal, slider.maxVal);
        };
		// Subscribe to the dual thumb slider's change and ready events to
        // report the state.
        slider.subscribe('ready', function () { updateUI('ready') });
        slider.subscribe('change', function () { updateUI('change') });
        slider.subscribe('slideEnd', function () { updateUI('slideEnd') });
		
    });
}


