/*
 * Korrekturen zum Verhalten des Sliders
 */

Slider.implement({
	clickedElement: function(event){
		/*
		 * Wenn man auf den Klotz klickt, sollte dieser nicht mit der Mitte unter
		 * die Maus springen.
		 */
		var knPos = this.knob.getPosition()[this.axis];
		var knSize = this.knob.getSize()[this.axis];
		if(
			event.page[this.axis] < knPos ||
			event.page[this.axis] > (knPos+knSize)
		) {
			var dir = this.range < 0 ? -1 : 1;
			position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;
			position = position.limit(-this.options.offset, this.full -this.options.offset);

			this.step = Math.round(this.min + dir * this.toStep(position));
			this.checkStep();
			this.end();
			this.fireEvent('tick', position);
			/*
			 * Hier muss das Dragging explizit gestartet werden!
			 * @url http://n2.nabble.com/Bug-in-Slider-%28jumping-knob%29-td1340440.html
			 */
			this.drag.start(event);
		};
	}
});

/*
 * Replacing Scrollbars with CSS styled scrollbars (patched for use with mooTools 1.11 and removed the mouseleave-event on the body)
 * @link http://solutoire.com/2008/03/10/mootools-css-styled-scrollbar/
 * @param content object DOM-element which the scrollbar should be related too
 * @param scrollbar object DOM-element of the scrollbar
 * @param handle object DOM-element for the handle inside the scrollbar
 * @param horizontal boolean horizontal scrollbar?
 * @param ignoreMouse boolean should the mouse-wheel be ignored?
 * @version $Id: styledscrollbars.js 497 2008-10-16 12:33:52Z jelner $
 */
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse,handleStart){
	var size = content.getSize();
	var scroll = content.getScrollSize();
	var steps = (horizontal?(scroll.x-size.x):(scroll.y-size.y));
	/*
	 * Fix für aktuelle Opera-Browser. In die Berechnung des scrollbaren Bereichs
	 * fließt scheinbar das padding oben und unten nicht mit ein.
	 */
	if(Browser.Engine.presto && !horizontal) {
		steps += content.getStyle('padding-top').toInt()+content.getStyle('padding-bottom').toInt();
	};
	var slider = new Slider(scrollbar, handle, {
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			//Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(handleStart);
	if(!(ignoreMouse)){
		//Scroll the content element when the mousewheel is used within the
		//content or the scrollbar element.
		$$(content,scrollbar).addEvent('mousewheel', function(e){
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;
			slider.set(step);
		});
	};
};