void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) 
	{
	OpenALSoundManager *soundMgr = (OpenALSoundManager *) inUserData;

	if (interruptionState == kAudioSessionBeginInterruption) 
		{		
		[soundMgr beginInterruption];
		soundMgr.interrupted = YES;
		}
		 
	else if ((interruptionState == kAudioSessionEndInterruption) && soundMgr.interrupted)
		{
		[soundMgr endInterruption];
		soundMgr.interrupted = NO;
		}
	}
	
- (id)init
	{
	self = [super init];		
	
	if (self != nil) 
		{		
		OSStatus status = AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
				
		self.soundDictionary = [NSMutableDictionary dictionary];
		self.soundEffectsVolume = 1.0;
		self.backgroundMusicVolume = 1.0;		
		[self endInterruption];
		}
	
	return self;
	}

-(BOOL)startupOpenAL
	{
	ALCcontext *context = NULL;
	ALCdevice *device = NULL;
	device = alcOpenDevice(NULL);

	if (!device) return NO;
		
	context = alcCreateContext(device, NULL);

	if (!context) return NO;
	
	alcMakeContextCurrent(context);
	debug(@"oal inited ok");
	return YES;	
	}

- (void)shutdownOpenAL
	{
	ALCcontext *context = NULL;
	ALCdevice *device = NULL;
	context = alcGetCurrentContext();
	device = alcGetContextsDevice(context);
	alcDestroyContext(context);
	alcCloseDevice(device);
	}
	

#pragma mark -
#pragma mark Audio Session Management

- (void)beginInterruption
	{
	[self stopBackgroundMusic];
	[self clearAllSoundsFromMemory];
	[self shutdownOpenAL];
	
	if (!self.isiPodAudioPlaying)
		{
		UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
		}
		else
		{
		UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
		}
	
	AudioSessionSetActive(NO);
	}

- (void)endInterruption
	{
	[self setupAudioCategorySilenceIpod:NO];
	[self startupOpenAL];	
	
	AudioSessionSetActive(YES);
	}

- (void)setupAudioCategorySilenceIpod:(BOOL)silenceIpod;
	{
	UInt32 audioIsAlreadyPlaying;
	UInt32 propertySize = sizeof(audioIsAlreadyPlaying);
	
	OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);	
	
	if (audioIsAlreadyPlaying && !silenceIpod)
		{
		self.isiPodAudioPlaying = YES;
		UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);		
		}
		else
		{
		self.isiPodAudioPlaying = NO;
		UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);		
		}		
	}