function Dragger(dragdrops, liners, bars, limiters, floatedDistances)
{		
	this.draggables = dragdrops;	
	this.liners = liners;
	this.limiters = limiters;	
	this.bars = bars;
	this.linerIndex = -1;	
	this.dragObject = null;
	this.mouseOffset = null;
	this.offset = 0;
	this.minActive = false;
	this.maxActive = false;
	this.start = 0;
	this.end = 0;
	this.states = new Array();
	this.floatedDistances = floatedDistances;
	this.LEFTS = [0,0,0];
	var that = this;
	
	document.onmousemove = function(e){that.mouseMove(e)};
    document.onmouseup   = function(e){that.mouseUp(e)};

	this.init();
}

Dragger.prototype.init = function()
{	
	var that = this;	
	for(var i=0; i<this.draggables.length; i++)
	{		
		for(var j=0; j<this.draggables[i].length; j++)
		{			
			this.makeDraggable($(that.draggables[i][j]));			
		}
		this.states.push([false,false]);
	}	
}

Dragger.prototype.getLinerIndex = function()
{
	for(var i=0; i<this.draggables.length; i++)
	{
		for(var j=0; j<this.draggables[i].length; j++)
		{
			if(this.dragObject.id == this.draggables[i][j])
			{
				this.linerIndex = i;
				return;
			}
		}
	}
}

Dragger.prototype.mouseCoords = function(e)
{	
	e = e || window.event;	
	if(e.pageX || e.pageY)
	{
		return {x:e.pageX, y:e.pageY};
	}
	return {
				x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
				y:e.clientY + document.body.scrollTop  - document.body.clientTop
		   };
}

Dragger.prototype.getMouseOffset = function(target, e)
{
	e = e || window.event;
	var docPos    = this.getPosition(target);	
	var mousePos  = this.mouseCoords(e);		
	return {x:mousePos.x - (docPos.x-this.offset), y:mousePos.y - docPos.y};
}

Dragger.prototype.getPosition = function(e)
{
	e = e || window.event;
	var left = 0;
	var top  = 0;

	while (e.offsetParent)
	{
		left += e.offsetLeft;
		top  += e.offsetTop;
		e = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;
	return {x:left, y:top};
}

Dragger.prototype.makeDraggable = function(item)
{		
	var that = this;	
	item.onmousedown = function(e)
	{					
		that.dragObject  = this;		
		that.dragObject.style.position = 'absolute';
		that.getLinerIndex();		
		that.mouseOffset = that.getMouseOffset(that.dragObject, e);	
		var coords = that.mouseCoords(e);
		var liner = $(that.liners[that.linerIndex]);
		if(that.LEFTS[that.linerIndex] == 0)
			that.LEFTS[that.linerIndex] = parseInt(coords.x + that.mouseOffset.x) - liner.clientWidth;	
		//alert(that.linerIndex)
		return false; 
	};	
}

Dragger.prototype.mouseMove = function(e)
{			
	e = e || window.event;
	var that = this;
	var mousePos = that.mouseCoords(e);	
	if(that.dragObject)
	{				
		for(var i=0; i<that.liners.length; i++)
		{
			that.liners[i].onselectstart = function(){return false;}
		}		
		var liner = $(that.liners[that.linerIndex]);
		var bar = $(that.bars[that.linerIndex]);
		var floatedDistance = that.floatedDistances[that.linerIndex];
		var state = that.states[that.linerIndex];

		var obj = (typeof Utils == 'undefined')? Element : Utils;
		var linerOffset = obj.cumulativeOffset(liner);
		var fullWidth = linerOffset[0] + liner.clientWidth;		
		var width, left;
		
		// kezdő és végpontok megállapítása
		if(state[0])
		{
			this.start = $(that.draggables[that.linerIndex][0]).style.left.replace('px','');
		}
		else
		{
			this.start = linerOffset[0];
		}

		if(state[1])
		{
			this.end = $(that.draggables[that.linerIndex][1]).style.left.replace('px','');			
		}
		else
		{
			this.end = linerOffset[0] + liner.clientWidth;			
		}
		

		if(linerOffset[0] < mousePos.x && linerOffset[0] + liner.clientWidth > mousePos.x) 
		{						
			if(that.dragObject == $(that.draggables[that.linerIndex][0]) && mousePos.x + 5 < that.end)
			{
				that.dragObject.style.left = ((mousePos.x - that.mouseOffset.x)) + 'px';
				that.start = (mousePos.x - that.mouseOffset.x)
			}
			if(that.dragObject == $(that.draggables[that.linerIndex][1]) && mousePos.x - 7 > that.start)
			{
				that.dragObject.style.left = ((mousePos.x - that.mouseOffset.x)) + 'px';
				that.end = (mousePos.x - that.mouseOffset.x)
			}
			// ha a minpushert húzták meg
			if(that.dragObject == $(that.draggables[that.linerIndex][0]))
			{				
				left = $(that.draggables[that.linerIndex][0]).style.left.replace('px','');					
				left = (isNaN(left))? linerOffset[1] : left;					
				width = (parseInt($(that.draggables[that.linerIndex][1]).style.left)) - (parseInt($(that.draggables[that.linerIndex][0]).style.left));				
				width = (isNaN(width))? (fullWidth - left) : width;				
				state[0] = true;
			}

			// ha a maxpushert húzták meg
			if(that.dragObject == $(that.draggables[that.linerIndex][1]))
			{						
				if(state[0])
				{
					left = $(that.draggables[that.linerIndex][0]).style.left.replace('px','');						
				}
				else
				{
					//left = parseInt(floatedDistance) + 5;
					left = that.LEFTS[that.linerIndex];//parseInt(that.dragObject.style.left) - liner.clientWidth;									
				}						
				w = parseInt($(that.draggables[that.linerIndex][1]).style.left);											
				width = (isNaN(width))? (liner.clientWidth - (fullWidth - w)) : width;				
				if(state[0])
				{
					left = $(that.draggables[that.linerIndex][0]).style.left.replace('px','');	
					width = width - (left - linerOffset[0]);					
				}	
				state[1] = true;
			}
			
			bar.style.left = left + 'px';			
			bar.style.width = width + 'px';
			that.moveEnd();
			return false;
		}		
	}
}

Dragger.prototype.mouseUp = function(e)
{	
	e = e || window.event;		
	this.dragEnd(e);
}

Dragger.prototype.dragEnd = function(e)
{	
	try
    {	
		this.afterDrag();
		if(!this.dragObject) return;
		this.dragObject   = null;
		this.limiters[this.linerIndex].setValues();		
		return;				  						
	}
	catch(err)
	{
		alert(err.message + ' dragEnd frame');
	}
}

Dragger.prototype.moveEnd = function()
{	
	try
    {	
		if(!this.dragObject) return;

		var liner = $(this.liners[this.linerIndex]);

		var obj = (typeof Utils == 'undefined')? Element : Utils;
		var linerOffset = obj.cumulativeOffset(liner);
		
		var offset = (parseInt(this.dragObject.style.left.replace('px',''))) - (linerOffset[0]-6);			
		var rate = (offset + this.offset) / liner.clientWidth;		
		var direction = (this.dragObject == $(this.draggables[this.linerIndex][0]))? 'min' : 'max';	
		limiter = this.limiters[this.linerIndex];
		limiter.getValue(rate, direction);					
	}
	catch(err)
	{
		//alert(err.message + ' Moveend');
	}
}

Dragger.prototype.getStartPosition = function(liner)
{		
	var obj = (typeof Utils == 'undefined')? Element : Utils;
	var linerOffset = obj.cumulativeOffset(liner);	
	return {min:linerOffset[0] , max:liner.clientWidth + linerOffset[0]};
}

Dragger.prototype.afterDrag = function()
{		
}

function setOpacity(obj,opacity)
{
    obj.style.opacity = (opacity / 100);
    obj.style.MozOpacity = (opacity / 100);
    obj.style.KhtmlOpacity = (opacity / 100);
}    