var GameModeToggle = cc.Layer.extend({
	_gameMode:null,
	_hardcoreSptire:null,
	_relaxSptire:null,
	_batch:null,
	
	ctor:function () {
		this._super();
		var winSize = cc.director.getWinSize();
		

		cc.spriteFrameCache.addSpriteFrames(res.game_mode_plist);
		var batch = cc.textureCache.addImage(res.game_mode_png);
		this._batch = new cc.SpriteBatchNode(batch);
		this.addChild(this._batch);
		//-------Buttons Sprites-----------
		this._hardcoreSptire = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("hardcore_unchecked.png"));
		this._relaxSptire = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("relax_checked.png"));
		var manager = GameManager.getInstance();
		this._gameMode = manager.getGameMode();
		if(manager.getGameMode() == SS.GAME_MODE.RELAX){
			this._relaxSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("relax_checked.png"));
			this._hardcoreSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("hardcore_unchecked.png"));
		}
		else{			
			this._hardcoreSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("hardcore_checked.png"));
			this._relaxSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("relax_unchecked.png"));
		}
		
		this._hardcoreSptire.setVisible(true);
		this._relaxSptire.setVisible(true);
		this._batch.addChild(this._hardcoreSptire);
		this._batch.addChild(this._relaxSptire);
		
		this._hardcoreSptire.attr({
			anchorX: 0,
			anchorY: 1,
			x: 325,
			y: 740
		});
		
		this._relaxSptire.attr({
			anchorX: 0,
			anchorY: 1,
			x: 325 + this._hardcoreSptire.getContentSize().width + 20,
			y: 740
		});
		
		cc.eventManager.addListener({
			event: cc.EventListener.TOUCH_ONE_BY_ONE,					
			onTouchBegan: function (touch, event) {	
				var target = event.getCurrentTarget();
				var locationInNode = target.convertToNodeSpace(touch.getLocation());    
				var s = target._hardcoreSptire.getContentSize();
				var rect = cc.rect(325, 740 - s.height, s.width, s.height);

				var s2 = target._relaxSptire.getContentSize();
				var rect2 = cc.rect(325 + target._hardcoreSptire.getContentSize().width, 
						740 - s.height, 
						s2.width, 
						s2.height);
				//Check the click area
				if (cc.rectContainsPoint(rect, locationInNode)) {       
					target.SetHardcoreMode();
				}
				else if(cc.rectContainsPoint(rect2, locationInNode)) {       
					target.SetRelaxMode();
				}
				return true;
			}

		}, this);
	},

	SetHardcoreMode:function(){
		if(this._gameMode == SS.GAME_MODE.RELAX){
			this._gameMode = SS.GAME_MODE.HARDCORE;
			this._hardcoreSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("hardcore_checked.png"));
			this._relaxSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("relax_unchecked.png"));
			this.ChangeGameMode();
		}
	},
	
	SetRelaxMode:function(){
		if(this._gameMode == SS.GAME_MODE.HARDCORE){
			this._gameMode = SS.GAME_MODE.RELAX;
			this._relaxSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("relax_checked.png"));
			this._hardcoreSptire.setSpriteFrame(cc.spriteFrameCache.getSpriteFrame("hardcore_unchecked.png"));
			this.ChangeGameMode();
		}
	},
	
	ChangeGameMode:function() {
		cc.audioEngine.playEffect(res.click_mp3);						
		var manager = GameManager.getInstance();
		if(manager.getGameMode() == SS.GAME_MODE.RELAX){
			manager.setGameMode(SS.GAME_MODE.HARDCORE);
		}
		else 
			manager.setGameMode(SS.GAME_MODE.RELAX);
	},
});


