function getMapSun()
{
	%count = missionGroup.getCount();
	
	for ( %i = 0 ; %i < %count ; %i++ )
	{
		%obj = missionGroup.getObject( %i );
		
		if ( %obj.getClassName() $= "Sun" )
		{
			return %obj;
		}
	}
	
	return -1;
}

function setSunColor( %value )
{
	if ( !isObject( %sun = getMapSun() ) )
	{
		return false;
	}
	
	%sun.setName( "_tempSunCopy" );
	
	%obj = new Sun( "" : _tempSunCopy )
	{
		color = %value;
	};
	
	%sun.setName( "" );
	missionGroup.add( %obj );
	
	if ( !isObject( %obj ) )
	{
		return false;
	}
	
	%sun.schedule( 32, "delete" );
	
	return true;
}

function setSunAmbient( %value )
{
	if ( !isObject( %sun = getMapSun() ) )
	{
		return false;
	}
	
	%sun.setName( "_tempSunCopy" );
	
	%obj = new Sun( "" : _tempSunCopy )
	{
		ambient = %value;
	};
	
	%sun.setName( "" );
	missionGroup.add( %obj );
	
	if ( !isObject( %obj ) )
	{
		return false;
	}
	
	%sun.schedule( 32, "delete" );
	
	return true;
}

function setSunElevation( %value )
{
	if ( !isObject( %sun = getMapSun() ) )
	{
		return false;
	}
	
	%sun.setName( "_tempSunCopy" );
	
	%obj = new Sun( "" : _tempSunCopy )
	{
		elevation = %value;
	};
	
	%sun.setName( "" );
	missionGroup.add( %obj );
	
	if ( !isObject( %obj ) )
	{
		return false;
	}
	
	%sun.delete();
	
	return true;
}

function sunElevationTick( %elev )
{
	cancel( $sunElevationTick );
	
	if ( !strLen( %elev ) )
	{
		%elev = -20;
	}
	
	if ( %elev < -4 )
	{
		%elev = -4;
	}
	
	if ( %elev >= 184 )
	{
		%elev = -4;
	}
	
	setSunElevation( %elev );
	
	%elev += 0.1;
	$sunElevationTick = schedule( 1000, 0, "sunElevationTick", %elev );
}