function Animal(type, index, x, y) {
	this.animalType = type;
	this.animalIndex = index;

	this.species = Animal.SPECIES_DATA[index];

	this.sprite = null;
	this.posX = x;
	this.posY = y;

	this.sprite = game.add.sprite(this.posX, this.posY, "animals");
	this.sprite.anchor.set(0.5);

	// for(var i = 0; i < Animal.SPECIES_DATA.length; i++) {
	// for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
	// 	var animalName = this.getSpeciesName(i);

	// 	var standAnimationName = animalName + "_stand";
	// 	this.sprite.animations.add(standAnimationName, i * 2);

	// 	var runAnimationName = animalName + "_run";
	// 	this.sprite.animations.add(runAnimationName, i * 2, i * 2 + 1);
	// }

	this.sprite.frame = this.animalIndex * 2;

	// game.time.events.add(Phaser.Timer.SECOND * 5, this.showStandAnimation, this);

	// var standAnimationName = this.getSpeciesName(this.animalIndex) + "_stand";
	// console.log(standAnimationName);
	// this.sprite.animations.play(standAnimationName);
	// this.sprite.animations.play("cheetah_stand");

	this.sprite.animations.add("stand", [index * 2]);
	// this.sprite.animations.play("stand");
	this.sprite.animations.add("run", [index * 2, index * 2 + 1]);
}

/*
Animal.prototype.showStandAnimation = function() {
	var standAnimationName = this.getSpeciesName(this.animalIndex) + "_stand";
	console.log(standAnimationName);
	this.sprite.animations.play(standAnimationName);
}
*/

Animal.prototype.getSpeciesName = function(animalIndex) {
	return Animal.SPECIES_DATA[animalIndex].species;
}

Animal.prototype.chagneStandAnimation = function(animalIndex) {
	// this.sprite.animations.play(this.getSpeciesName(this.animalIndex) + "stand");
	this.animalIndex = animalIndex;
	this.sprite.frame = this.animalIndex * 2;
}

Animal.prototype.changeRunAnimation = function(animalIndex) {
	this.sprite.animations.play(this.getSpeciesName(this.animalIndex) + "run");
}

Animal.prototype.setScale = function(value) {
	this.sprite.scale.set(value);
}

Animal.prototype.setSpecies = function(species) {
	console.log(species);
	this.species = species;
}

Animal.prototype.setAlpha = function(value) {
	this.sprite.alpha = value;
}


Animal.prototype.tweenAnimation = function(animationType) {
	switch(animationType) {
		case Animal.ANIMATION_TYPE_CHANGE:
		this.sprite.width = Animal.SPRITE_WIDTH;
		this.sprite.height = Animal.SPRITE_HEIGHT;
		game.add.tween(this.sprite).to( { width: 50, height: 50 }, 500, Phaser.Easing.Bounce.Out, true);
		break;

		case Animal.ANIMATION_TYPE_DAMAGE:
		this.sprite.width = Animal.SPRITE_WIDTH;
		this.sprite.height = Animal.SPRITE_DAMAGE_HEIGHT;
		game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Bounce.In, true);
		// game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Elastic.Out, true);
		break;
	}
}

Animal.prototype.startAnimation = function(species) {
	// var runAnimationName = this.getSpeciesName(this.animalIn) + "_run";
	// this.sprite.animations.play(runAnimationName, this.species.fps, true);
	this.sprite.animations.play("run", this.species.fps, true);
}

Animal.prototype.stopAnimation = function() {
	// var runAnimationName = this.getSpeciesName(this.animalIn) + "_run";
	// this.sprite.animations.stop(runAnimationName);
	this.sprite.animations.stop("run");
}

Animal.prototype.show = function() {
	this.sprite.y = this.posY;
}

Animal.prototype.hide = function() {
	this.sprite.y = Animal.HIDE_POS_Y;
}


Animal.animalIndexByRecord = function(record, gameType) {
	for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
		if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
			return i;
	}

	return 0;
}

Animal.animalLevelIDByRecord = function(record, gameType) {
	for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
		if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
			return i;
	}

	return 0;
}

Animal.getAnimalTypingPracticeCount = function(animalIndex) {
	return Animal.SPECIES_DATA[animalIndex].typingPracticeCount;
}

Animal.getAnimalTypingTestCount = function(animalIndex) {
	return Animal.SPECIES_DATA[animalIndex].typingTestCount;
}

Animal.typingCount = function(speciesData, gameType) {
	if(gameType === Animal.TYPE_PRACTICE)
		return speciesData.typingPracticeCount;
	else
		return speciesData.typingTestCount;
}

Animal.getOffsetY = function(animalIndex) {
	return Animal.SPECIES_DATA[animalIndex].offsetY;
}

Animal.loadResources = function() {
	game.load.spritesheet('animals', '../../../resources/image/character/animal/animals.png', 50, 50);
}


Animal.TYPE_ANIMATION			= 0;
Animal.TYPE_ICON				= 1;

Animal.TYPE_PRACTICE			= 0;
Animal.TYPE_TEST				= 1;
Animal.TYPE_EXAM				= 1;

Animal.ANIMATION_TYPE_CHANGE	= 0;
Animal.ANIMATION_TYPE_DAMAGE	= 1;

Animal.SPRITE_WIDTH				= 100;
Animal.SPRITE_DAMAGE_WIDTH		= 50;
Animal.SPRITE_HEIGHT			= 100;
Animal.SPRITE_DAMAGE_HEIGHT		= 50;

Animal.HIDE_POS_Y				= 1000;

Animal.SPECIES_DATA = [
	{ "species" : "snail",		"fps" : 1,	"offsetY" : 15,	"typingPracticeCount" : 0,			"typingTestCount" : 0 },
	{ "species" : "turtle",		"fps" : 2,	"offsetY" : 13,	"typingPracticeCount" : 5,			"typingTestCount" : 20 },
	{ "species" : "chick",		"fps" : 5,	"offsetY" : 14,	"typingPracticeCount" : 10,			"typingTestCount" : 40 },
	{ "species" : "mouse",		"fps" : 12,	"offsetY" : 15,	"typingPracticeCount" : 15,			"typingTestCount" : 70 },
	{ "species" : "chicken",	"fps" : 11,	"offsetY" : 8,	"typingPracticeCount" : 20,			"typingTestCount" : 100 },
	{ "species" : "pig",		"fps" : 5,	"offsetY" : 12,	"typingPracticeCount" : 25,			"typingTestCount" : 150 },
	{ "species" : "cat",		"fps" : 10,	"offsetY" : 12,	"typingPracticeCount" : 30,			"typingTestCount" : 200 },
	{ "species" : "deer",		"fps" : 9,	"offsetY" : 6,	"typingPracticeCount" : 40,			"typingTestCount" : 250 },
	{ "species" : "kangaroo",	"fps" : 4,	"offsetY" : 6,	"typingPracticeCount" : 50,			"typingTestCount" : 300 },
	{ "species" : "rabbit",		"fps" : 12,	"offsetY" : 13,	"typingPracticeCount" : 60,			"typingTestCount" : 350 },
	{ "species" : "dog",		"fps" : 9,	"offsetY" : 10,	"typingPracticeCount" : 70,			"typingTestCount" : 400 },
	{ "species" : "zebra",		"fps" : 12,	"offsetY" : 4,	"typingPracticeCount" : 80,			"typingTestCount" : 450 },
	{ "species" : "ostrich",	"fps" : 15,	"offsetY" : 0,	"typingPracticeCount" : 90,			"typingTestCount" : 500 },
	{ "species" : "lion",		"fps" : 10,	"offsetY" : 8,	"typingPracticeCount" : 100,		"typingTestCount" : 600 },
	{ "species" : "cheetah",	"fps" : 15,	"offsetY" : 8,	"typingPracticeCount" : 110,		"typingTestCount" : 700 }
];