function CPlayer(iX,iY,oParentContainer){
    var _bUpdate = false;
    var _bJumping;
    var _bLeft = false;
    var _bRight = false;
    var _iCurAnim;
    var _iTotAnimFrame;
    var _iCurFrameIndex;
    var _iStartX;
    var _iStartY;
    var _iCurAcceleration;
    var _iCurMaxSpeed;
    var _iXMove;
    var _iWidthSprite;
    var _iHeightSprite;
    var _aAnim;
    var _aAnimNumFrames;
    var _aCbCompleted;
    var _aCbOwner;
    
    var _oContainer;
    var _oParentContainer;
    
    this._init = function(iX,iY){
        _bJumping = false;
        _iStartX = iX;
        _iStartY = iY;
        _iXMove = 0;
        _iCurAcceleration = HERO_ACCELERATION;
        _iCurMaxSpeed = MAX_HERO_SPEED;
        _aCbCompleted=new Array();
        _aCbOwner =new Array();
        
        _oContainer = new createjs.Container();
        _oContainer.x = iX;
        _oContainer.y = iY;
        _oParentContainer.addChild(_oContainer);
        
        _aAnimNumFrames = new Array();
        _aAnimNumFrames[PLAYER_ANIM_RUN] = 18;
        _aAnimNumFrames[PLAYER_ANIM_FALL] = 9;
        _aAnimNumFrames[PLAYER_ANIM_TOUCHDOWN] = 50;
        _aAnimNumFrames[PLAYER_ANIM_JUMP] = 26;
        
        _aAnim = new Array();
        _aAnim[PLAYER_ANIM_RUN] = new Array();
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_RUN];i++){
            var oSprite = s_oSpriteLibrary.getSprite('player_running_'+i);
            var oBmp = createBitmap(oSprite);
            oBmp.visible = false;
            oBmp.regX = oSprite.width/2;
            oBmp.regY = oSprite.height;
            _oContainer.addChild(oBmp);
            
            _aAnim[PLAYER_ANIM_RUN].push(oBmp);
        }
        
        
        _aAnim[PLAYER_ANIM_FALL] = new Array();
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_FALL];i++){
            var oSprite = s_oSpriteLibrary.getSprite('player_falling_'+i);
            var oBmp = createBitmap(oSprite);
            oBmp.visible = false;
            oBmp.regX = oSprite.width/2;
            oBmp.regY = oSprite.height;
            _oContainer.addChild(oBmp);
            
            _aAnim[PLAYER_ANIM_FALL].push(oBmp);
        }
        
        
        _aAnim[PLAYER_ANIM_TOUCHDOWN] = new Array();
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_TOUCHDOWN];i++){
            var oSprite = s_oSpriteLibrary.getSprite('player_touchdown_'+i);
            var oBmp = createBitmap(oSprite);
            oBmp.visible = false;
            oBmp.regX = oSprite.width/2;
            oBmp.regY = oSprite.height;
            _oContainer.addChild(oBmp);
            
            _aAnim[PLAYER_ANIM_TOUCHDOWN].push(oBmp);
        }
        
        _aAnim[PLAYER_ANIM_JUMP] = new Array();
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_JUMP];i++){
            var oSprite = s_oSpriteLibrary.getSprite('player_jump_'+i);
            var oBmp = createBitmap(oSprite);
            oBmp.visible = false;
            oBmp.regX = oSprite.width/2;
            oBmp.regY = oSprite.height;
            _oContainer.addChild(oBmp);
            
            _aAnim[PLAYER_ANIM_JUMP].push(oBmp);
        }
        
        _iCurAnim = PLAYER_ANIM_RUN;
    };
    
    this.addEventListener = function( iEvent,cbCompleted, cbOwner ){
        _aCbCompleted[iEvent]=cbCompleted;
        _aCbOwner[iEvent] = cbOwner; 
    };
    
    this.show = function(){
        _iTotAnimFrame = _aAnimNumFrames[_iCurAnim];

        _aAnim[_iCurAnim][0].visible = true;
        _iCurFrameIndex = 0;
        _oContainer.visible = true;
        
        _iWidthSprite = _oContainer.getBounds().width-400;
        _iHeightSprite = _oContainer.getBounds().height;
        /*
        var oShapeRect = new createjs.Shape();
        oShapeRect.graphics.beginFill("blue").drawRect(-_iWidthSprite/2, -_iHeightSprite, _iWidthSprite,_iHeightSprite);
        oShapeRect.alpha = 0.5;
        _oContainer.addChild(oShapeRect);
        */
        _bUpdate = true;
    };
    
    this.hide = function(){
        _bUpdate = false;
        _oContainer.visible = false;
    };
    
    this.reset = function(){
        _bUpdate = false;
        _bJumping = false;
        _bLeft = false;
        _bRight = false;
        _iXMove = 0;
        _iCurAcceleration = HERO_ACCELERATION;
        _iCurMaxSpeed = MAX_HERO_SPEED;
        
        _oContainer.alpha = 1;
        _oContainer.x = _iStartX;
        _oContainer.y = _iStartY;
        
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_RUN];i++){
            _aAnim[PLAYER_ANIM_RUN][i].visible = false
        }

        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_FALL];i++){
            _aAnim[PLAYER_ANIM_FALL][i].visible = false;
        }
        
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_TOUCHDOWN];i++){
            _aAnim[PLAYER_ANIM_TOUCHDOWN][i].visible = false;
        }
        
        for(var i=0;i<_aAnimNumFrames[PLAYER_ANIM_JUMP];i++){
            _aAnim[PLAYER_ANIM_JUMP][i].visible = false;
        }
        
        _iCurAnim = PLAYER_ANIM_RUN;
    };
    
    this.changeAnim = function(iAnim){
        _bUpdate = false;
        _aAnim[_iCurAnim][_iCurFrameIndex].visible = false;
        
        _iCurAnim = iAnim;
        _aAnim[_iCurAnim][0].visible = true;
        _iCurFrameIndex = 0;
        _iTotAnimFrame = _aAnimNumFrames[_iCurAnim];
        _bUpdate = true;
    };
    
    this.jump = function(){
        _bJumping = true;
        this.changeAnim(PLAYER_ANIM_JUMP);
    };
    
    this.playToFrame = function(iFrame){
        _aAnim[_iCurAnim][_iCurFrameIndex].visible = false;
        _iCurFrameIndex = iFrame;
        _aAnim[_iCurAnim][_iCurFrameIndex].visible= true;
    };
    
    this.nextFrame = function(){
        _aAnim[_iCurAnim][_iCurFrameIndex].visible = false;
        _iCurFrameIndex++;

        _aAnim[_iCurAnim][_iCurFrameIndex].visible= true;
    };
    
    this.moveLeft = function(bLeft){
        _bLeft = bLeft;
    };

    this.moveRight = function(bRight){
        _bRight = bRight;
    };
    
    this.setAcceleration = function(iAcceleration,iMax){
        _iCurAcceleration = iAcceleration;
        _iCurMaxSpeed = iMax;
    };
    
    this.setY = function(iY){
        _oContainer.y = iY;
    };
    
    this.getRect = function(){
        return new createjs.Rectangle(_oContainer.x-_iWidthSprite/2,_oContainer.y -_iHeightSprite,_iWidthSprite,_iHeightSprite);
    };
    
    this.isJumping = function(){
        return _bJumping;
    };
    
    this.getCurAnim = function(){
        return _iCurAnim;
    };
    
    this.getX = function(){
        return _oContainer.x;
    };
    
    this._updateMove = function(){
        if(_iCurAnim !== PLAYER_ANIM_RUN){
            return;
        }

        if(_bLeft){
            _iXMove -= _iCurAcceleration;
        }
        if(_bRight){
            _iXMove += _iCurAcceleration;
        }

        _oContainer.x += _iXMove;

        _iXMove *= HERO_FRICTION;
        if (_iXMove > _iCurMaxSpeed) {
                _iXMove = _iCurMaxSpeed;
        }
        
        if (_iXMove < -_iCurMaxSpeed) {
                _iXMove = -_iCurMaxSpeed;
        }

        if ( Math.abs(_iXMove) < 0.1 ) {
                _iXMove = 0;
        }
		
	if( ((_oContainer.x  + _iXMove) > CANVAS_WIDTH)){  
            _oContainer.x = CANVAS_WIDTH  - _iXMove;
        }
        
        if((_oContainer.x -  _iXMove)<0) {
            _oContainer.x = _iXMove;
        }
    };
            
    this.update = function(){
        if(_bUpdate === false){
            return;
        }
        
        if (_iCurFrameIndex === _iTotAnimFrame-1) {
            switch(_iCurAnim){
                case PLAYER_ANIM_RUN:{
                    this.playToFrame(0);
                    break;
                }
                case PLAYER_ANIM_FALL:{
                    this.hide();
                    if(_aCbCompleted[ON_PLAYER_TACKLED]){
                         _aCbCompleted[ON_PLAYER_TACKLED].call(_aCbOwner[ON_PLAYER_TACKLED]);
                    }
                    break;
                }
                case PLAYER_ANIM_TOUCHDOWN:{
                    _bUpdate = false;
                    new createjs.Tween.get(_oContainer).to({alpha:0},500);
                    if(_aCbCompleted[ON_PLAYER_TOUCHDOWN]){
                         _aCbCompleted[ON_PLAYER_TOUCHDOWN].call(_aCbOwner[ON_PLAYER_TOUCHDOWN]);
                    }
                    break;
                }
                case PLAYER_ANIM_JUMP:{
                    _bJumping = false;
                    this.changeAnim(PLAYER_ANIM_RUN);
                    break;
                }
            }
            
                
        }else{
            this.nextFrame();
        }   
        
        
        this._updateMove();
    };
    
    _oParentContainer = oParentContainer;
    this._init(iX,iY);
}