var goMureena = function (game, options, api) {
    var self = {};
    self.name = "mureena";
	var enemy = null;
	var startPos = null;
	var enemySpeed = null;
	var eatTime = null;
	var eated = null;
	var waitTime = null;
	var waited = null;
	var start = false;
	var laughSfx = null;
	var snapSfxarray = [];

	self.COLLISION_WIDTH = 150;

    self.getObject = function () {
        return enemy;
    }

    self.moveObject = function (relX, worldX) {
        enemy.x += relX;
        /*if (startPos.x < worldX + 500) {
            start = true;
        }
        */
    }

    self.preload = function () {
        
    }

	self.setInitialPosition = function (point) {
        startPos = point;
	}

    self.create = function () {
        enemy = game.add.sprite(startPos.x, startPos.y, self.name);
        enemy.y = game.height - enemy.height;
        //game.physics.enable(enemy, Phaser.Physics.ARCADE);
        enemy.animations.add("attack");
        enemy.animations.play('attack', 10, false, true);
        enemy.anchor.setTo(0, 0);

		enemySpeed = 0;
		eatTime = 30;
		eated = false
		waitTime = 50;
		waited = false;
		//sounds
		laughSfx = game.add.audio('mureena_laugh');
		snapSfxarray.push(game.add.audio('mureena_snap1'));
		snapSfxarray.push(game.add.audio('mureena_snap2'));

		//timeout here
		laughSfx.play();
		snapSfxarray[game.rnd.between(0, 1)].play();
    }

    self.update = function () {
        if (start === false)
            return;

		enemy.y+=enemySpeed;

		if(enemy.y>=400 && eated == false){
			enemySpeed=-1,2
			//kill enemy when eaten and out of the screen
		}else if(enemy.y>=game.height){
			enemy.kill();
		}else{
			//wait for some time then attack&eat
			if(waitTime<=0){
				waited=true;
				if(eated==false){
				enemySpeed = -8;
				}
				//Moving up n' down after waiting
				if (enemy.y <= 50) {
					eatTime=-1;
					enemySpeed=0;
					if (eatTime<=0){
						eated=true;
						enemySpeed=2;
					}
				}
			}else{
				waitTime--;
				enemySpeed = 0;
			}

		}

    }

    return self;
}