//Based on FLIR script by Gachopin

FLIROFF = 
{
	//hint "FLIR mode OFF";
	setaperture -1;
	ppEffectDestroy ppColor;
	ppEffectDestroy ppBlur;
	ppEffectDestroy ppInversion;
	ppEffectDestroy ppGrain;
};

FLIRON = 
{
	//hint "FLIR mode ON";
	ppEffectDestroy ppColor;
	ppEffectDestroy ppBlur;
	ppEffectDestroy ppInversion;
	ppEffectDestroy ppGrain;

	ppGrain = ppEffectCreate ["filmGrain", 2005];
	ppGrain ppEffectEnable true;
	ppGrain ppEffectAdjust [0.02, 1, 1, 0, 1];
	ppGrain ppEffectCommit 0;

	ppInversion = ppEffectCreate ["colorInversion", 2555];
	ppInversion ppEffectEnable true;
	ppInversion ppEffectAdjust [0.1,0.1,0.1];
	ppInversion ppEffectCommit 0;

	ppColor = ppEffectCreate ["ColorCorrections", 1999];
	ppColor ppEffectEnable true;
	ppColor ppEffectAdjust [1, 1, 0, [1, 1, 1, 0], [1, 1, 1, 0.0], [1, 1, 1, 1.0]];
	ppColor ppEffectCommit 0;
	ppBlur = ppEffectCreate ["dynamicBlur", 505];
	ppBlur ppEffectEnable true;  
	ppBlur ppEffectAdjust [.5];
	ppBlur ppEffectCommit 0;
};

FLIRBLACK = 
{
	ppEffectDestroy ppColor;
	ppEffectDestroy ppBlur;
	ppEffectDestroy ppInversion;
	ppEffectDestroy ppGrain;

	ppInversion = ppEffectCreate ['colorInversion', 2555];
	ppInversion ppEffectEnable true;
	ppInversion ppEffectAdjust [1,1,1];
	ppInversion ppEffectCommit 0;

	ppGrain = ppEffectCreate ["filmGrain", 2005];
	ppGrain ppEffectEnable true;
	ppGrain ppEffectAdjust [0.02, 1, 1, 0, 1];
	ppGrain ppEffectCommit 0;

	ppColor = ppEffectCreate ["ColorCorrections", 1999];
	ppColor ppEffectEnable true;
	ppColor ppEffectAdjust [1, 1, 0, [1, 1, 1, 0], [1, 1, 1, 0.0], [1, 1, 1, 1.0]];
	ppColor ppEffectCommit 0;
	ppBlur = ppEffectCreate ["dynamicBlur", 505];
	ppBlur ppEffectEnable true;  
	ppBlur ppEffectAdjust [.5];
	ppBlur ppEffectCommit 0;
};

FLIRREVERSE = 
{
	_vehicle = vehicle(player);
	_FLIR = _vehicle getvariable "FLIR";
	_aperture = _FLIR select 0;
	_color = _FLIR select 1;

	if (_color == "white") then
	{
		call FLIRBLACK;

		_color = "black";
		_vehicle setvariable ["FLIR",[_aperture,_color]];

	} else {

		call FLIRON;

		_color = "white";
		_vehicle setvariable ["FLIR",[_aperture,_color]];
	};
};

FLIRBRIGHTUP =
{
	//hint "UP";
	_vehicle = vehicle(player);
	_FLIR = _vehicle getvariable "FLIR";
	_aperture = _FLIR select 0;
	_color = _FLIR select 1;

		   _zChange = -1;
		   _oldAperture = _FLIR select 0;
		   _zChangeFinal = _zChange / 2;
		   if (_oldAperture <= 1.0) then {_zChangeFinal = _zChange / 10};
		   if (_oldAperture <= 0.1) then {_zChangeFinal = _zChange / 1000};
		   _aperture = _oldAperture + _zChangeFinal;
		   if (_oldAperture > 1.0 && _aperture < 1.0) then {_aperture = 1.0};
		   if (_oldAperture > 0.1 && _aperture < 0.1) then {_aperture = 0.1};
		   if (_aperture < 0.001) then {_aperture = 0.001};
		   _vehicle setvariable ["FLIR",[_aperture,_color]];
		   setaperture _aperture;
};

FLIRBRIGHTDOWN =
{
	//hint "DOWN";
	_vehicle = vehicle(player);
	_FLIR = _vehicle getvariable "FLIR";
	_aperture = _FLIR select 0;
	_color = _FLIR select 1;

		   _zChange = +1;
		   _oldAperture = _FLIR select 0;
		   _zChangeFinal = _zChange / 2;
		   if (_oldAperture <= 1.0) then {_zChangeFinal = _zChange / 10};
		   if (_oldAperture <= 0.1) then {_zChangeFinal = _zChange / 1000};
		   _aperture = _oldAperture + _zChangeFinal;
		   if (_oldAperture > 1.0 && _aperture < 1.0) then {_aperture = 1.0};
		   if (_oldAperture > 0.1 && _aperture < 0.1) then {_aperture = 0.1};
		   if (_aperture < 0.001) then {_aperture = 0.001};
		   _vehicle setvariable ["FLIR",[_aperture,_color]];
		   setaperture _aperture;
};