/// Drag&Drop System , pouzito z Interval.cz

	var dragobj;
	
	function m_down(event, object)
	{
	
		
		dragobj = object;      
		
		dragobj.style.zIndex = "5";	
		if(!dragobj.style.left) dragobj.style.left = "0px";
		if(!dragobj.style.top) dragobj.style.top = "0px";
			
		// Zapamatuj pozici mysi pri klintuti
		dragobj.clickX = event.clientX;  
		dragobj.clickY = event.clientY;
			
		// Zapamatuj pozici objektu pri klintuti
		dragobj.left = parseInt(dragobj.style.left); 
		dragobj.top = parseInt(dragobj.style.top);


	 	// Zacni sledovat pohyb mysi
    if(IE)
		{	
			document.attachEvent('onmousemove', m_move); 
			document.attachEvent('onmouseup', m_up); 		
		}else{
			document.addEventListener('mousemove', m_move, true);
			document.addEventListener('mouseup', m_up, true); 		
		}

return stopEvent(event);
}


function m_move(event)
{
	// Spocti rozdil mezi puvodni pozici mysi pri stisku a nynejsi pozici a zavolej proceduru objektu pro presun 
	dragobj.ondragdrop(event.clientX-dragobj.clickX, event);
	return stopEvent(event);
}

function m_up(event)
{
	// Ukonci sledovani mysi
	if(IE)
	{
		document.detachEvent('onmousemove', m_move); 	
		document.detachEvent('onmouseup', m_up); 
		if(dragobj.ondragend)dragobj.ondragend(event);
	}else{
		document.removeEventListener('mousemove', m_move, true); 
		document.removeEventListener('mouseup', m_up, true); 
		if(dragobj.ondragend)dragobj.ondragend(event);
	}
	return stopEvent(event);	
}


// Prirad objektu moznost presunu
function startDrag(what)
{
	if(what.style.position!="relative" && what.style.position!="absolute") {what.style.position="relative";}
	what.onmousedown = function(e) {if(e) {event=e;} m_down(event,what);}
	what.drag = true;
}

// Odeber objektu moznost presunu 
function stopDrag(what)
{
	what.onmousedown = null;
	what.drag = 0;
}

// Zastav sireni udalosti
function stopEvent(event)
{
	if(IE) {
		event.cancelBubble = true; return false;
	}else{
		event.stopPropagation(); event.preventDefault(); return false;
	}
}

function Init(Format){

	if(nPriceMinResult == 0) nPriceMinResult = nPriceMin;
	if(nPriceMaxResult == 0) nPriceMaxResult = nPriceMax;
	if(nPriceMinResult > nPriceMin){
		$('Min').innerHTML = '' + formatCurrency(nPriceMinResult/fCoef,Format);
		$('SysOd').value = nPriceMinResult/fCoef;
		
		$('draggerMin').style.left = Math.round((nPriceMinResult-nPriceMin)/Krok) + 'px';
	}else{
		$('Min').innerHTML = '' + formatCurrency(nPriceMinResult/fCoef,Format);
		$('SysOd').value = nPriceMinResult/fCoef;
		$('draggerMin').style.left = 0 + 'px';
	}
	if(nPriceMaxResult < nPriceMax && nPriceMaxResult > 0 ){
		//alert(Math.round((nPriceMax-nPriceMaxResult)/Krok));
		//Nastavim minimalni cenu
		$('Max').innerHTML = '' + formatCurrency(nPriceMaxResult/fCoef,Format);
		$('draggerMax').style.left = Math.round((nPriceMaxResult-nPriceMin)/Krok) + 'px';//Math.round(ActualMax - (nKoeficient * Math.round((nPriceMax - nPriceMaxResult)/nItemReal))) + 'px';
		$('SysDo').value = nPriceMaxResult/fCoef;
	}else{
		$('Max').innerHTML = '' + formatCurrency(nPriceMaxResult/fCoef,Format);
		$('draggerMax').style.left = ActualMax + 'px';//Math.round(ActualMax - (nKoeficient * Math.round((nPriceMax - nPriceMaxResult)/nItemReal))) + 'px';
		$('SysDo').value = nPriceMaxResult/fCoef;
	}
	startDrag($('draggerMin'),1);
	startDrag($('draggerMax'),1);
	
	$('draggerMin').ondragdrop = function(posuny){
		this.style.left = (this.left + posuny) + 'px';
		if(parseInt(this.style.left) < ActualMin){this.style.left = ActualMin + "px";}
		if(parseInt(this.style.left) > parseInt($('draggerMax').style.left)){this.style.left = $('draggerMax').style.left;};
		if(this.style.top != this.top){this.top = this.style.top;}
		if(ActualMin == parseInt(this.style.left)){
			$('Min').innerHTML = '' + formatCurrency(parseInt(nPriceMin/fCoef),Format);
			$('SysOd').value = parseInt(nPriceMin/fCoef);
		}else{
			var tmpPriceMin = parseFloat(nPriceMin + (Krok * parseInt(this.style.left)) + (-ActualMin)); 
			if(tmpPriceMin == nPriceMaxResult){
				tmpPriceMin = parseInt(tmpPriceMin) - parseInt(nItem);
			}
			if(tmpPriceMin < 0 || isNaN(tmpPriceMin)){
				tmpPriceMin = 0;
			}
			$('Min').innerHTML = '' + formatCurrency(parseInt(tmpPriceMin / fCoef),Format);
			$('SysOd').value = parseInt(tmpPriceMin/fCoef);
		}
	};
$('draggerMax').ondragdrop = function(posuny){
		this.style.left  = (this.left + posuny) + "px";
		if(parseInt(this.style.left) > ActualMax){this.style.left = ActualMax + "px";};
		if(parseInt(this.style.left) < parseInt($('draggerMin').style.left)){this.style.left = $('draggerMin').style.left;};
		if(this.style.top != this.top){this.top = this.style.top;}
		if(ActualMax == parseInt(this.style.left)){
			$('Max').innerHTML = '' + formatCurrency(parseInt(nPriceMax/fCoef),Format);
			$('SysDo').value = parseInt(nPriceMax/fCoef);
		}else{
			var tmpPriceMax = parseFloat(nPriceMin + (Krok * parseInt(this.style.left))); 
			if(tmpPriceMax == nPriceMinResult || isNaN(tmpPriceMax)){
				tmpPriceMax = parseInt(tmpPriceMax) + parseInt(0);
			}
			$('Max').innerHTML ='' + formatCurrency(parseInt(tmpPriceMax/fCoef),Format);
			$('SysDo').value = parseInt(tmpPriceMax/fCoef);
		}
	};
}

