// JavaScript Document
    
    var mouseX;
    var mouseY;
    
    var daysStart = 0;
    var daysMax  = 0;
    var daysInterval = 20;
    var daysNames = new Array("dowolna", "do 3", "do 7", "do 14", "do 21", "powyżej 21");
    var daysValues = new Array("", "3", "7", "14", "21", "100");
    
    var priceStart = 0;
    var priceMax  = 0;
    var priceInterval = 20;
    var priceNames = new Array("dowolna", "do 1000", "do 2000", "do 3000", "do 4000", "powyżej 4000");
    var priceValues = new Array("", "0,1000", "1000,2000", "2000,3000", "3000,4000", "4000,50000");
    
    
    //absolutna pozycja myszki
    function getMouseCords(e){
				mouseX = Event.pointerX(e);
				mouseY = Event.pointerY(e);
		}
			
		
    function calcDays() {
      
      containerPos = $('dragDaysContainer').cumulativeOffset();
      mouseDayX = mouseX - containerPos[0];
      index = Math.round(mouseDayX / daysInterval);
      moveToX = index * daysInterval;
      setDaysValue(index);
      $
      new Effect.Move('dragDays', { x: moveToX, y: 0, mode: 'absolute'  });
      
    }
    
    
    function calcPrice() {
      
      containerPos = $('dragPriceContainer').cumulativeOffset();
      mousePriceX = mouseX - containerPos[0];
      index = Math.round(mousePriceX / daysInterval);
      moveToX = index * priceInterval;
      setPriceValue(index);
      new Effect.Move('dragPrice', { x: moveToX, y: 0, mode: 'absolute'  });
      
    }
    
    
    function checkDays() {
      
      x = $('dragDays').positionedOffset();
      x_container = $('dragDaysContainer').positionedOffset();
      position = x[0] - x_container[0];
      
      if (position > daysMax) {
        moveDaysToMax();
        setDaysValue(daysMax / daysInterval);
      } else if (position < daysStart) {
        moveDaysToMin();
        setDaysValue(0);
      } else {
        setDaysValue(position / daysInterval);
        
      }
//      timeoutId = setTimeout("checkResult()", 3000); 
      
    }
    
    function checkPrice() {
      
      x = $('dragPrice').positionedOffset();
      x_container = $('dragPriceContainer').positionedOffset();
      position = x[0] - x_container[0];
      
      if (position > priceMax) {
        movePriceToMax();
        setPriceValue(priceMax / priceInterval);
      } else if (position < priceStart) {
        movePriceToMin();
        setPriceValue(0);
      } else {
        setPriceValue(position / priceInterval);
      }
//      timeoutId = setTimeout("checkResult()", 3000); 
    }
    
    
    function setFirstPosition() {
      x = $('dragDaysContainer').positionedOffset();
      daysStart =  0;
      daysMax = daysStart + $('dragDaysContainer').getWidth() - 10; 
      
      x = $('dragPriceContainer').positionedOffset();
      priceStart =  0;
      // priceStart =  x[0];
      priceMax = priceStart + $('dragPriceContainer').getWidth() - 10;
      
//      x = $('dragHotelContainer').positionedOffset();
//      hotelStart =  x[0];
//      hotelMax = hotelStart + $('dragHotelContainer').getWidth() - 10; 
      
      //alert('daysStart: ' + daysStart + ' daysMin: ' + daysMax); 
    }
    function moveDaysToMax() {
      new Effect.Move('dragDays', { x: daysMax, y: 0, mode: 'absolute'  });
    }
    function moveDaysToMin() {
      new Effect.Move('dragDays', { x: daysStart, y: 0, mode: 'absolute'  });
    }
    function movePriceToMax() {
      new Effect.Move('dragPrice', { x: priceMax, y: 0, mode: 'absolute'  });
    }
    function movePriceToMin() {
      new Effect.Move('dragPrice', { x: priceStart, y: 0, mode: 'absolute'  });
    }
    
    function setDaysValue(index) {
      $('daysView').value = daysNames[index];
      $('NoLength').value = daysValues[index];
    }
    function setPriceValue(index) {
      $('priceView').value = priceNames[index];
      $('price_select').value = priceValues[index];
    }
    
    Event.observe(document, 'mousemove', getMouseCords); 
    
    window.onload = function () {
      new Draggable('dragDays', { constraint: 'horizontal', handle: 'dragDays', snap: [daysInterval, 20], onEnd: checkDays});
      new Draggable('dragPrice', { constraint: 'horizontal', handle: 'dragPrice', snap: [priceInterval, 20], onEnd: checkPrice});
      setFirstPosition();
    } 
