function enemy_showerhead_ai()
{
	facing_x = sign(global.player.x - x);
	image_xscale = facing_x;
	
	var _margin = 320;

	if abs(global.player.x - x) <= _margin
		awake = true;

	var _sink_wait = global.player.x < _margin || global.player.x > room_width - _margin ||
	global.player.y < y - 15 * sprite_get_number(sEnemyShowerheadEmerge) / animation_spd
	
	switch(state)
	{		
		case "WAIT":
			if _sink_wait
				wake_timer = irandom(60);
			else if --wake_timer <= 0 && awake
			{
				x = global.player.x + choose(-1, 1) * irandom_range(192, 256);
				state = "EMERGE";
				y_spd = -15;
				set_sprite(sEnemyShowerheadEmerge);
			}
			break;
		
		case "IDLE":
			if --idle_timer <= 0
			{
				state = nxt_state;
				if state == "RETREAT"
				{
					x_spd = -facing_x * 10;
					set_sprite(sEnemyShowerheadRetreat);
				}
				else if state == "SINK"
				{
					y_spd = 15;
					set_sprite(sEnemyShowerheadSink);
				}
				else if state == "CHARGE"
				{
					x_spd = facing_x * 25;
					set_sprite(sEnemyShowerheadCharge);
				}				
			}
			break;
				
		case "SINK":
			if animation_end()
			{
				state = "WAIT";
				y_spd = 0;
			}
			break;
		
		case "EMERGE":
			if animation_end()
			{
				y_spd = 0;
				set_sprite(sEnemyShowerheadIdle);
				idle_timer = 30;
				state = "IDLE";
				nxt_state = "RETREAT";
			}
			break;
				
		case "RETREAT":
			if animation_end()
			{
				x_spd = 0;
				idle_timer = 10;
				state = "IDLE";
				nxt_state = "CHARGE";
			}
			break;
			
		case "CHARGE":
			x_spd -= sign(x_spd) * 0.5;
			if animation_end()
			{
				x_spd = 0;
				idle_timer = 30;
				state = "IDLE";
				nxt_state = "SINK";
				set_sprite(sEnemyShowerheadIdle);
			}
	}
}