var mod_query2_f = function()
{
	this.trace_list = null;
	this.trace_speedup = 100;
	this.trace_timestamp = null;
	this.device_route_list = null;
	this.trace_array = null;
	this.trace_timeoffset = null;
	this.trace_buffer_length = null;
	this.tracing_device_id = 0;
	this.time_offset1 = 0;
	this.time_offset_end1 = 0;
	this.trace_xmin= null;
	this.trace_ymin = null;
	this.trace_xmax = null;
	this.trace_ymax = null;
	this.trace_xmin_last= null;
	this.trace_ymin_last = null;
	this.trace_xmax_last = null;
	this.trace_ymax_last = null;
	this.follow_trace_timer = 0;
	this.device_route_time_from = null;
	this.device_route_time_to = null;
	this.device_route_counter = null;
	this.device_route_xmin = null;
	this.device_route_xmax = null;
	this.device_route_ymin = null;
	this.device_route_ymax = null;	
	this.device_route_markers = new Array();
	this.device_partial_route_data = null;
  this.device_partial_route_index = null;
  this.device_trace_index = null;
  this.end_trace = 0; 
  this.timer_count = 0;
  
  this.routes = new Array();
}

mod_query2_f.prototype.pauseGPSTrace = function()
{
	if (this.follow_trace_timer)
	{
		window.clearTimeout(this.follow_trace_timer);
		this.follow_trace_timer = 0;
	}
	else
	{
		this.timer_count = 0;
		this.traceTimer();
	}
}

mod_query2_f.prototype.stopGPSTrace = function()
{
	if (tracing)
	{
		this.device_trace_index = 0;
		window.clearTimeout(this.follow_trace_timer);
		this.follow_trace_timer = 0;
		
		var p;
		while (p = this.routes.pop()) 
		canvas.remove(p);
		
		if (this.last_point1)
		{
			var p = follow_moving_marker_map["c"+this.last_point1.device_id];
			p.traceMode = false;
 	 		marker.move2(p.marker_id,p.x,p.y,0,0);
 	 		//if (p.marker_info)
 	 		//marker.move2(p.marker_info,p.x,p.y,0,0);
 	 		fn.setLocation(p.x,p.y); 
 	 		follow_moving_marker_map["c"+this.last_point1.device_id] = p;
 		}
 		
 		this.trace_list.each(function(el)
		{
				if (follow_moving_marker_map["c"+el])
				{
					follow_moving_marker_map["c"+el].traceData = 0;										
					loadPoi(follow_moving_marker_map["c"+el]);
				}

		});
	
 	 	this.last_point1 = null;
		this.tracing_device_id = null;
		
		geotrag.setFollowMode();
		
		var d = new Date();
		
		global_timestamp = Math.round(d.getTime()/1000);
		$('globalTime').innerHTML = formatTimeInfo(global_timestamp);
	}
}

mod_query2_f.prototype.followGPSTrace = function()
{ 
	this.trace_list = getCheckedList();
	
	this.trace_xmin = 100000000000000;
	this.trace_ymin = 100000000000000;	
	this.trace_xmax = -100000000000000;
	this.trace_ymax = -100000000000000;
		this.timer_count = 0;
	
	this.end_trace = 0;
		
	//fn.setQuality("LOW"); 
	
	this.trace_array = new Array();
	
	var p;
	while (p = this.routes.pop()) 
		canvas.remove(p);
	
	this.traceDevice();
		
  this.trace_timestamp =followSetTimeOffset('followDate','followTime','geotrag_followdate','geotrag_followtime');     
  global_timestamp = this.trace_timestamp;
}

mod_query2_f.prototype.traceTimer = function ()
{		
	var f = 10.0;
	$('globalTime').innerHTML = formatTimeInfo(global_timestamp);	
	
	global_timestamp = this.trace_timestamp;
		
	this.trace_timestamp += (1/f)*this.trace_speedup;
	
		this.timer_count += 1000/f;
	this.follow_trace_timer = window.setTimeout(function() { mod_query2.traceTimer() },1000/f);
	
	this.getGPSTracePoint();

	//getGPSTracePoint(getCheckedList());
}

mod_query2_f.prototype.onTraceDeviceLoad = function(d)
{	
	if (d && d.newnch)
   {
  	 reloadGeotrag();
  	 return;
   }
  
	if (!d) 
	{ 
		//$("info").innerHTML = lang['numberofpoint']+": 0"; 
		this.end_trace = 1;
	}
	else
	{ 
		 //follow_array1 = follow_array1.concat(d);
		 //console.log(d);
		 //follow_array1 = d;
		//$("info").innerHTML = lang['numberofpoint']+": "+d.length; 
						
		if (tracing)
		{
			this.trace_array = d;						
			this.trace_buffer_length = parseInt(this.trace_array.length*0.5);						
			fn.setQuality("LOW"); 
		}
		
		/*
		var m = follow_moving_marker_map["c"+d[0].device_id];
		
		alert(m+" "+d[0].device_id);
		
		if (!m.traceData) m.traceData = new Object();
		
		m.traceData.tracePointCount = d.length;				
		m.traceData.followArray = d;
		m.traceData.traceMode = true;
		m.traceData.last_kut = 0;
		m.traceData.time_offset = time_offset_end1;
		*/
		
		//getGPSTracePoint(d[0].device_id);	
		
		
		
	}							
	om.hideLoader();		
	
	if (!this.follow_trace_timer)
	this.traceTimer();
}


mod_query2_f.prototype.traceDevice = function(device)
{
	var lst = new Array();
	if (this.trace_list.length > 25)
	this.trace_list.length = 25;
	this.trace_list.each(function(el)
	{
			lst.push(el);
			if (follow_moving_marker_map["c"+el])
			{
				follow_moving_marker_map["c"+el].traceData = 0;							
				loadPoi(follow_moving_marker_map["c"+el],true);
			}
	});
	
	this.tracing_device_id = device;
	
	geotrag.setTraceMode();
	
	$('prati_button1').innerHTML = "Stani"; 
	
	this.last_point1 = null;
				
	this.time_offset1 = followSetTimeOffset('followDate','followTime','geotrag_followdate','geotrag_followtime'); 
	this.time_offset_end1 = followSetTimeOffset('followDateEnd','followTimeEnd','geotrag_followdate_end','geotrag_followtime_end');
		
	this.time_offset_end1 = this.time_offset1+1000;
	this.trace_timeoffset = this.time_offset_end1;

	//$("info").innerHTML = "Ucitavam...";
	
	om.showLoader("Učitavam...");
	
console.log("trejsam");
	var jsonRequest = new Request.JSON({url: "/modules/query2/db/data.php", onComplete: function(d)
	{					
			this.obj.onTraceDeviceLoad(d);
							
	}});
	jsonRequest.obj = this;
	jsonRequest.get({'follow': 1, 'list': lst, 'timeoffset':this.time_offset1,  'timeoffset_end':this.time_offset_end1 });
}

mod_query2_f.prototype.traceSpeedChange = function()
{	
	var speedup = $('followSpeedUp1'); 
 	this.trace_speedup = speedup.options[speedup.selectedIndex].value*1;
}

mod_query2_f.prototype.onGPSPointLoad = function(d)
{
	if (d && d.newnch)
   {
  	 reloadGeotrag();
  	 return;
   }
  				
	if (!d) 
	{ 
		//$("info").innerHTML = lang['numberofpoint']+": 0"; 
		//alert("nema");
	}
	else
	{ 
		 //follow_array1 = follow_array1.concat(d);
		 //console.log(d);
		 //follow_array1 = d;
		//$("info").innerHTML = lang['numberofpoint']+": "+d.length; 
		this.trace_array = this.trace_array.concat(d);
		this.trace_buffer_length = parseInt(this.trace_array.length*0.3);
		/*
		fn.setQuality("LOW"); 
		var m = follow_moving_marker_map["c"+d[0].device_id];
		var t = m.traceData;
		t.tracePointCount = d.length;		
		
		if (t.followArray && t.followArray.length > 0)
		{
			t.followArray = t.followArray.concat(d);	
		}
		else
		{
			t.followArray = d;						  
			t.traceMode = true;
			t.last_kut = 0;						
		  getGPSTracePoint(m.device_id);	
	  }
	  */
	}							
		$('map_loader').setStyle("display","none");	
}

mod_query2_f.prototype.getGPSTracePoint = function(did)
{		
  if (this.trace_array.length == 0) 
  {
  	//if (this.end_trace)
  	//alert("nema");
  	
  	console.log("ide1",this.time_offset1,this.time_offset_end1);
  		this.time_offset1 = this.trace_timeoffset*1;
  		if (this.time_offset1 < this.trace_timestamp) this.time_offset1 = this.trace_timestamp;
  		this.time_offset_end1 = this.time_offset1*1+100000;
  		
  		this.trace_timeoffset = this.time_offset_end1;
  		
  			$('map_loader').setStyle("display","block");
	  	var jsonRequest = new Request.JSON({url: "/modules/query2/db/data.php", onComplete: function(d)
			{							
				  this.obj.onGPSPointLoad(d);								
			}});
			console.log("ide2",this.time_offset1,this.time_offset_end1);
			jsonRequest.obj = this;
			jsonRequest.get({'follow': 1, 'list': this.trace_list, 'timeoffset':this.time_offset1,  'timeoffset_end':this.time_offset_end1, 'persist':1 });
  	
  	return;
  }
    
  var pdata = this.trace_array[0];

  if (!pdata || pdata.timestamp > this.trace_timestamp){
  	
  	return;
}
  
  var dev_to_move = new Array();
  var dev_to_move_map = new Array();
  
  while (pdata = this.trace_array.shift())
  {
  	var devid = "c"+pdata.device_id;
  	if (dev_to_move_map[devid])
  	{
  		pdata.last_data = dev_to_move_map[devid].dev;
  		dev_to_move_map[devid].dev = pdata;
  	}
  	else
  	{
  		var o = new Object();  	
  		o.dev = pdata;  		  	  		
  		dev_to_move.push(o);
  		dev_to_move_map[devid] = o;  		
  	}	
  	//console.log(trace_array.length);
  	if (this.trace_array.length == this.trace_buffer_length)
  	{  	
    	console.log("ide1",this.time_offset1,this.time_offset_end1);
  		this.time_offset1 = this.trace_timeoffset*1;
  		if (this.time_offset1 < this.trace_timestamp) this.time_offset1 = this.trace_timestamp;
  		this.time_offset_end1 = this.time_offset1*1+1000;
  		
  		this.trace_timeoffset = this.time_offset_end1;
  		
  			$('map_loader').setStyle("display","block");
	  	var jsonRequest = new Request.JSON({url: "/modules/query2/db/data.php", onComplete: function(d)
			{							
				  this.obj.onGPSPointLoad(d);								
			}});
			console.log("ide2",this.time_offset1,this.time_offset_end1);
			jsonRequest.obj = this;
			jsonRequest.get({'follow': 1, 'list': this.trace_list, 'timeoffset':this.time_offset1,  'timeoffset_end':this.time_offset_end1, 'persist':1 });
	 }
  	//console.log(pdata.timestamp+" "+trace_timestamp);
  	if (pdata.timestamp >= this.trace_timestamp) break;
  }
  /*
  this.trace_xmin = 10000000000000;
	this.trace_xmax = -100000000000000;
	this.trace_ymin = 100000000000000;
  this.trace_ymax = -100000000000000;
  */
  var setBound = 0;
  //   
  while (pdata = dev_to_move.pop())
  {
   pdata = pdata.dev;
    	p = pdata;
 	
         
   did = pdata.device_id;     
      
   var d = follow_moving_marker_map["c"+did]; 
  
   if (!d) return;
   
 		if (!d.traceData) 
 		{
 			d.traceData = new Object();			
			d.traceData.tracePointCount = d.length;				
			d.traceData.followArray = d;
			d.traceData.traceMode = true;
			d.traceData.last_kut = 0;				
			if (!onlyicon )
			{
				d.traceData.traceShape = canvas.newShape({color:d.tragColor,alpha:85,width:3});
				this.routes.push(d.traceData.traceShape);
				canvas.moveTo(d.traceData.traceShape,p.x,p.y);	
			}	
			d.traceData.time_offset = this.time_offset_end1;
		}
	  
   var t = d.traceData;
     
          
  if (!tracing || !pdata) 
 	{
 	 if (t.last_point1)
 	 {
 	 	t.traceMode = false; 	 	
 	 	marker.move2(d.marker_id,d.x,d.y,0,0);
 	 	//if (d.marker_info)
 	 	//	marker.move(d.marker_info,d.x,d.y,0,0);
 	 }
 	 t.last_point1 = null;
 	 this.tracing_device_id = null;
 	 fn.setQuality("HIGH"); 
 	 alert("kraj"); 	 
 	 return;
 	}


 		//var speedupItem = $('followSpeedUp1'); 
 		//speedup = speedup.value*1;
 		speedup= 100;

		if (d)
    { 						
    	//if (d.last_point1)
    	kut = 0;
    	{
    		p2 = d.last_point2;
    		
    		var dist = 0;
    		if (p2)
    		{
    			var dx = p2.x*1-p.x*1;
    			var dy = p2.y*1-p.y*1;
    			dist = Math.sqrt(dx*dx+dy*dy);
    		}
    	
    		if (dist > 10 || !p2)
    		{
    			
					kut = Math.atan2(dy,dx)*180/Math.PI+180;				
					if (kut < 0) kut += 360;
					d.last_point2 = p;
				}
				else
					kut = d.last_kut;	
			}
			//else
			//	kut = 0;
			d.curs = kut;
			marker.move2(d.marker_id,p.x,p.y,-kut,0); 	
			treeData["c"+p.device_id].timestamp = parseInt(p.timestamp);
			treeData["c"+p.device_id].covered_dist = parseFloat(p.covered_dist);			
			//console.log("p",p);			
			//console.log("d",d);
			//if (d.marker_info)
 	 		//marker.move(d.marker_info,p.x,p.y,0,0);
			d.last_kut = kut;	
			//if (d.device_id == '7005')
			//console.log(d.device_id,kut);
			
			if (p.speed*1 == 0)
	  	{
	  		//console.log("set speed "+m.last_data);
	  		
	  		if (d.last_data1 && d.last_data1.device_id == p.device_id)
	  		{	  			
	  			if (p.timestamp > d.last_data1.timestamp)
	  				p.speed = Math.round((Math.sqrt(Math.pow(d.last_data1.x-p.x,2)+Math.pow(d.last_data1.y-p.y,2))/(p.timestamp-d.last_data1.timestamp))*3.6);
	  			else
	  			if (d.last_data1.speed > 0)
	  				p.speed = d.last_data1.speed;	  				  			
	  	  }    		 
	  	}
			
			if (!onlyicon && follow_leave_mark && d.last_data1 && regata && dist < 2000)
		  {		  				  		
		  		canvas.lineTo(d.traceData.traceShape,p.x,p.y);		  				  
		  }
		}    
		
		d.last_data1 = p;
				
		d.last_point1 = p;  	
		
			/*
  	if (d && d.hasVariableData)
		{
			//populateMarkerInfoWindow(p);
		}   
		*/ 		
		/*
		if (d.device_id == current_info_id)
		{
		 if (d.speed*1 == 0)
    	{
    		if (d.last_point && d.last_point.device_id == d.device_id)
    		{
    			if (d.timestamp > d.last_point.timestamp)
    			d.speed = Math.round((Math.sqrt(Math.pow(d.last_point.x-p.x,2)+Math.pow(d.last_point.y-p.y,2))/(d.timestamp-d.last_point.timestamp))*3.6);
    	  }    		 
    	}
    	
    	d.last_point = p;  
    	
    	if (!d.traceData || !d.traceData.timestampRec || p.timestamp*1-d.traceData.timestampRec > 300)
    	{
    		if (d.traceData)
    		d.traceData.timestampRec = p.timestamp*1;
  			updateInfo(p,true,speedup);
  				
  		//	var m = follow_moving_marker_map["c"+p.device_id];
  		
  	//		console.log(m);
			//	if (m && m.hasVariableData)
		//		{				
		//			populateMarkerInfoWindow(m);
		//		}
				
  		}
  	} 
   */
  
   if ($('followOnMap1').checked)
   {
   	if (p.device_id == current_info_id)
			fn.setLocation(p.x,p.y); 
	 }
	 else
	 if ($('followOnMap').checked) 
	 {	 	
	 	var f = 1;
	 	var xx = Math.round(p.x/f)*f;
	 	var yy = Math.round(p.y/f)*f;
	 	if (xx < this.trace_xmin) { this.trace_xmin = xx; setBound = 1; }
	 	if (xx > this.trace_xmax) { this.trace_xmax = xx; setBound = 1; }
	 	if (yy < this.trace_ymin) { this.trace_ymin = yy; setBound = 1; }
	 	if (yy > this.trace_ymax) { this.trace_ymax = yy; setBound = 1; }
	 	
	 	
		 //fn.setLocation(p.x,p.y); 		 		
  	}
  }	
  	
	 if (setBound /*&& (this.trace_xmin_last > this.trace_xmin || this.trace_ymin_last > this.trace_ymin
		 
		 || this.trace_xmax_last < this.trace_xmax || this.trace_ymax_last < this.trace_ymax)*/ )
		 
		 {
		  var f = 1.0001; 	
		  //console.log(this.trace_xmax-this.trace_xmin);
		  var dx = (this.trace_xmax-this.trace_xmin)*0.35;
		  var dy = (this.trace_ymax-this.trace_ymin)*0.35;
		  //dx = dy = 0;	
		  
		  //var f = 10000;
		  
		  var bmax = this.trace_xmax;
		  /*
		  this.trace_xmin = Math.round(this.trace_xmin/f)*f;
		  this.trace_ymin = Math.round(this.trace_ymin/f)*f;
		  this.trace_xmax = (Math.round(this.trace_xmax/f)+1)*f;
		  this.trace_ymax = (Math.round(this.trace_ymax/f)+1)*f;
		  */
		  /*
		 	this.trace_xmin_last = this.trace_xmin-dx;
		 	this.trace_ymin_last = this.trace_ymin-dy;
		 	this.trace_xmax_last = this.trace_xmax*1+dx;
		 	this.trace_ymax_last = this.trace_ymax*1+dy;
		 	*/
		 	this.trace_xmin_last = this.trace_xmin/f;
		 	this.trace_ymin_last = this.trace_ymin/f;
		 	this.trace_xmax_last = this.trace_xmax*f;
		 	this.trace_ymax_last = this.trace_ymax*f;
		 	//console.log(this.trace_xmin_last,this.trace_ymin_last,this.trace_xmax_last,this.trace_ymax_last,bmax);
		 	fn.setViewBound(this.trace_xmin_last,this.trace_ymin_last,this.trace_xmax_last,this.trace_ymax_last);		
		 	
		 }		
	 //console.log(time_delay*1000/speedup);
	 if (t.followArray.length) 
	 {
		//follow_trace_timer = window.setTimeout(getGPSTracePoint,time_delay*1000/speedup,did); 
		//follow_trace_timer = window.setTimeout(getGPSTracePoint,0,did); 
	 }
}

mod_query2_f.prototype.showRoute = function()
{				
	
	this.device_route_counter = 0;
	this.device_route_time_from = followSetTimeOffset('followDate','followTime','geotrag_followdate','geotrag_followtime'); 
	this.device_route_time_to = followSetTimeOffset('followDateEnd','followTimeEnd','geotrag_followdate_end','geotrag_followtime_end'); 
	this.device_route_list = getCheckedList();
	//alert(this.device_route_list.length);

	this.showDeviceRoute();
}

mod_query2_f.prototype.showPartialRoute = function()
{

	var i = this.device_partial_route_index;
	
	if (i >= this.device_partial_route_data.total) return;
	
	//alert("test "+i+" "+this.device_partial_route_data.total);

	this.device_route_time_from = this.device_partial_route_data.data[i].start1*1; 
	this.device_route_time_to = this.device_partial_route_data.data[i].stop1*1; 
	this.device_route_list = new Array();
	this.device_route_list.push(this.device_partial_route_data.data[i].id);

	//console.log(device_route_time_from+" "+device_route_time_to+" "+i);
	this.showDeviceRoute1(); 
	
	this.device_partial_route_index++;   
}

mod_query2_f.prototype.onDeviceRouteLoad = function(d)
{	  
		if (d && d.newnch)
		{
		 reloadGeotrag();
		 return;
		}
		
		if (!d || !d[0]) 
	  {
	  	this.showDeviceRoute();
	  	return;
	  }
		
		var n = d.length;	   
	  var plen = pallete.length;
			 	  
	  if (d && this.device_route_counter == 0)
	  {	   
		  this.device_route_xmin= d[0].xmin;
		  this.device_route_ymin = d[0].ymin;
		  this.device_route_xmax = d[0].xmax;
		  this.device_route_ymax = d[0].ymax;
		}
	 
  	d[0].color = follow_moving_marker_map["c"+d[0].device_id].tragColor;
  	//d[i].color = c;
 		d[0].alpha = 85; 
 		d[0].width = 3; 
 		
 		//alert(follow_moving_marker_map["c"+d[i].device_id]);
 		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setStyle("display","block");  
 		
 		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox.setStyle("backgroundColor",d[i].color);   		   		
 		//alert(follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox.style);
 		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setColor("#"+d[i].color.toString(16));   		   		
 		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setStyle("backgroundColor","#"+d[i].color.toString(16));   		   		
 			   		
		var m = canvas.deserializeGeometryOpenGISSimple(d[0]);
		this.routes.push(m);
		
		if (d.xmin < this.device_route_xmin) this.device_route_xmin = d[0].xmin;
		if (d.ymin < this.device_route_ymin) this.device_route_ymin = d[0].ymin;
		if (d.xmax > this.device_route_xmax) this.device_route_xmax = d[0].xmax;
		if (d.ymax > this.device_route_ymax) this.device_route_ymax = d[0].ymax;
			
		//if (device_route_list.length == 0)
		if (!regata)
		fn.setViewBound(this.device_route_xmin,this.device_route_ymin,this.device_route_xmax,this.device_route_ymax);		
		
		this.device_route_counter++;
		
		this.showDeviceRoute();
}

mod_query2_f.prototype.showDeviceRoute = function()
{ 
	var d = this.device_route_list.pop();

	if (!d) return;
	
	var jsonRequest = new Request.JSON({url: "/modules/query2/db/data.php", onComplete: function(d)
	{	        			
		this.obj.onDeviceRouteLoad(d);
			
	}});
	jsonRequest.obj = this;
	jsonRequest.get({'timeoffset':this.device_route_time_from, 'timeoffset_end':this.device_route_time_to, 'd': d, 'route':1});

}

mod_query2_f.prototype.onShowDeviceRoute1 = function(d,recurse)
{
	if (d && d.newnch)
	{
	 reloadGeotrag();
	 return;
	}
	
	if (d && d[0])
	{
	  var n = d.length;	   
	  var plen = pallete.length;
	   	  	  
	  if (d && this.device_route_counter == 0)
	  {	   
		  this.device_route_xmin= d[0].xmin;
		  this.device_route_ymin = d[0].ymin;
		  this.device_route_xmax = d[0].xmax;
		  this.device_route_ymax = d[0].ymax;
		}
	 
		d[0].color = follow_moving_marker_map["c"+d[0].device_id].tragColor;
		d[0].color = 0x00ff00;
		//d[i].color = c;
		d[0].alpha = 85; 
		d[0].width = 3; 
		
		//alert(follow_moving_marker_map["c"+d[i].device_id]);
		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setStyle("display","block");  
		
		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox.setStyle("backgroundColor",d[i].color);   		   		
		//alert(follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox.style);
		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setColor("#"+d[i].color.toString(16));   		   		
		//follow_moving_marker_map["c"+d[i].device_id].treeNode.div.checkbox2.setStyle("backgroundColor","#"+d[i].color.toString(16));   		   		
			   		
		var m = canvas.deserializeGeometryOpenGISSimple(d[0]);
		this.routes.push(m);
		
		if (d.xmin < this.device_route_xmin) this.device_route_xmin = d[0].xmin;
		if (d.ymin < this.device_route_ymin) this.device_route_ymin = d[0].ymin;
		if (d.xmax > this.device_route_xmax) this.device_route_xmax = d[0].xmax;
		if (d.ymax > this.device_route_ymax) this.device_route_ymax = d[0].ymax;
			
		//if (device_route_list.length == 0)
		var f = 1.0001;
		//fn.setViewBoundAnim(device_route_xmin/f,device_route_ymin/f,device_route_xmax*f,device_route_ymax*f);		
		
		if (this.device_route_counter == 0)
		this.device_route_markers.push( marker.loadPoi(d[0].xstart,d[0].ystart,"/images/icons/stopsign.png","",true) );
		
		//this.device_route_markers.push( marker.loadPoi(d[0].xend,d[0].yend,"/images/icons/stopsign.png","",true) );
	}
	
	this.device_route_counter++;
	
	if (recurse)
	{
		this.showDeviceRoute1();
	}
	
	this.showPartialRoute();
}

mod_query2_f.prototype.showDeviceRoute1 = function(dontrecurse)
{ 
	/*
	if (!current_info_id) 
	{
		alert("Morate odabrati jedno vozilo!");
		return;
	}
	
	var time_offset1 = followSetTimeOffset('followDate','followTime','geotrag_followdate','geotrag_followtime'); 
	var time_offset_end1 = followSetTimeOffset('followDateEnd','followTimeEnd','geotrag_followdate_end','geotrag_followtime_end'); 
	
	var lst = new Array();
	
	
	//lst.push(current_info_id);
	
	lista = getCheckedList();
		
	lista.each(function(el)
	{
		if (el != tracing_device_id)
		lst.push(el);
	});
	//lista = lista1;
	
	//fn.setQuality("LOW"); 
	*/	
	
	var d = this.device_route_list.pop();

	
	if (!d) return;
	
	var jsonRequest = new Request.JSON({url: "/modules/query2/db/data.php", onComplete: function(d)
	{	        
		this.obj.onShowDeviceRoute1(d,this.dontrecurse);								
	}});
	jsonRequest.obj = this;
	jsonRequest.dontrecurse = dontrecurse;
	jsonRequest.get({'timeoffset':this.device_route_time_from, 'timeoffset_end':this.device_route_time_to, 'd': d, 'route':1});

}

mod_query2_f.prototype.clearRoute = function()
{	
	var p;
	
	while (p = this.routes.pop()) 
		canvas.remove(p);
	
	while (p = this.device_route_markers.pop())	
		marker.removePoi(p);
	
		/*
	if (follow_moving_marker)
	{
		for (var i in follow_moving_marker)
		{
		if (follow_moving_marker[i].treeNode)
			follow_moving_marker[i].treeNode.div.checkbox2.setStyle("display","none");  
		}
	}
	*/

}

	
var mod_query2 = new mod_query2_f();

