currentUser->userType == 'inhouse') # { # echo '
';			print_r($url);			exit;
		#	}
		if($url[1] == 'amp')
		{
			
			
			$this->amp = true;
			$url[1] = $url[2];
			$url[2] = $url[3];
			$this->view->ampcss = 'flightdurations.php';
			$this->view->ampadsense = 1;
		}
		

		$this->location = new \Location;
		$this->duration = new \Duration;
		$this->view->facebooklike = 1;
		$countryarray = $this->location->loadFlightdurations($url[2]);
		$this->view->flightdurationorigins = $this->location->loadFlightDurationOrigins();
		
		#print_r($countryarray);
		#exit;
		
		
		$this->view->canonical = 'flight-durations/'.$countryarray->url;
		$this->view->country = $url[2];
		$this->view->corecss = 'duration.css';
		$this->view->ampurl = 'https://www.flight-durations.com/amp/flight-durations/'.$countryarray->url;
		
		$this->view->title = $countryarray->title." Flight Durations";
		$this->view->name = $countryarray->title;
		$this->view->keywords = $countryarray->keywords.",flight,duration,list,how far";
		$view = 'flightduration';
		$this->view->description = $countryarray->description;
		$this->view->h1 = $countryarray->h1;
		$this->view->main_text = $countryarray->main_text;
		$this->view->lat = $countryarray->lat;
		$this->view->lng = $countryarray->lng;
		$this->view->origin = $countryarray->origin;
		$this->view->url = $countryarray->url;
		$this->view->zoom = $countryarray->zoom;
		
		#$this->view->flightdurationsjs = 1;
		
		
		if($countryarray)
		{
			
			#header("Location: /flight-durations/uk");
			#exit;
		
		
			$durations = $this->location->getDurations();
			
			$data = $this->location->loadFlightdurationsData($countryarray->id);
			
			foreach($data as $d)
			{
				$durations[$d->durationID]->locations[] = $d;
			}
			
			foreach($durations as $key => $dur)
			{
				$countries = array();
				foreach($dur->locations as $loc)
				{
					if(isset($countries[$loc->destination_country]))
					{
						$countries[$loc->destination_country][] = $loc->destination;
					}
					else
					{
						$countries[$loc->destination_country] = array();
						$countries[$loc->destination_country][] = $loc->destination;
					}
				}
				unset($durations[$key]->locations);
				$durations[$key]->countries = $countries;
			}
			
			foreach($durations as $key => $dur)
			{
				foreach($dur->countries as $k2 => $du)
				{
					sort($durations[$key]->countries[$k2]);
				}
			}
			
			if($this->currentUser->userType == 'inhouse')
			{
				#echo '
';			print_r($durations);			exit;
			}
			$this->view->durations = $durations;
			
		}
		else
		{
			
			$origin = $this->location->getLocationNotGiven(str_replace('-',' ',$url[2]),'origin');
			if(empty($origin))
			{
				
				header("Location: /flight-durations/uk");
				exit;
			}
			
			
			$this->view->canonical = 'flight-durations/'.strtolower($url[2]);
			$this->view->ampurl = 'https://www.flight-durations.com/amp/flight-durations/'.strtolower($url[2]);
			$this->view->lat = $origin->lat;
			$this->view->lng = $origin->lng;
			$this->view->origin = $origin->location;
			$this->view->url = strtolower($url[2]);
			$this->view->zoom = 4;
			$this->view->title = $origin->location." Flight Durations";
			$this->view->name = $origin->location;
			
			$this->view->description = $this->view->name." flight durations to destinations worldwide ordered by duration based on direct 
			flights leaving from ".$origin->location.", ".$origin->country.". Holiday destinations from ".$origin->location." ordered by 
			duration. All durations are based on direct flights leaving from ".$origin->location.".";
			
			$durations = $this->location->getDurations();
			
			
			
			$destinations = $this->duration->flightdurationDestinations($origin);
			
			foreach($destinations as $key => $destination)
			{
				$durationData = $this->duration->getDuration($origin,$destination,true);
				
				if($durationData->duration_raw <= 120)
				{
					$destinations[$key]->tz = 1;
				}
				elseif($durationData->duration_raw <= 180)
				{
					$destinations[$key]->tz = 2;
				}
				elseif($durationData->duration_raw <= 240)
				{
					$destinations[$key]->tz = 3;
				}
				elseif($durationData->duration_raw <= 300)
				{
					$destinations[$key]->tz = 4;
				}
				elseif($durationData->duration_raw <= 360)
				{
					$destinations[$key]->tz = 5;
				}
				elseif($durationData->duration_raw <= 480)
				{
					$destinations[$key]->tz = 6;
				}
				elseif($durationData->duration_raw <= 720)
				{
					$destinations[$key]->tz = 7;
				}
				else
				{
					$destinations[$key]->tz = 8;
				}
				
				
			}
			
			
			foreach($destinations as $key => $d)
			{
				$durations[$d->tz]->locations[] = $d;
				
			}
			
			
			foreach($durations as $key => $dur)
			{
				$countries = array();
				foreach($dur->locations as $loc)
				{
					if(isset($countries[$loc->country]))
					{
						if(count($countries[$loc->country]) < 4)
						{
							$countries[$loc->country][] = $loc->location;
						}
					}
					else
					{
						if(count($countries) < 6)
						{
							$countries[$loc->country] = array();
							$countries[$loc->country][] = $loc->location;
						}
					}
				}
				unset($durations[$key]->locations);
				$durations[$key]->countries = $countries;
			}
			
			foreach($durations as $key => $dur)
			{
				foreach($dur->countries as $k2 => $du)
				{
					sort($durations[$key]->countries[$k2]);
				}
			}
			
			
			#echo '
';
			#print_r($durations);
			#exit;
			
			$this->view->durations = $durations;
		}	
		
		########### COMMENTS #############
		$comments = new \Comment();
		#$this->view->comments = $comments->loadComments($origin->citycode,$destination->citycode);
		if($res123 = $comments->loadComments('https://www.flight-durations.com/flightduration/'.$url[2]))
		{
			$this->view->comments = $res123;
		}
		
		
		$this->view->jsloader = 'lazyload/floatadsense/load.js';
		
		$this->view->render('pages', 'flightduration');
		
		
    }
	

    
}