var HUDLayer = cc.Layer.extend({
	_HUDSprite:null,
	_menu:null,
	_medallionBatch:null,
	_medallion:null,
	_menuItem:null,
		
	ctor:function () {
		this._super();
		this.init();
	},

	init:function () {
		var winSize = cc.director.getWinSize();
		//------HUD Sprite---------
		this._HUDSprite =  new cc.Sprite(res.hud_png);
		
		this.addChild(this._HUDSprite);
		this._HUDSprite.attr({
			anchorY:0,
			anchorX:0,
			x:0,
			y:0
		})	
		
		//--------------DELETE IN A FINAL VERSION - invisible return button located in the left-buttom corner---
		var menuSpriteNormal =  new cc.Sprite(res.hud_exit_png);
		
		var menuSpriteSelected =  new cc.Sprite(res.hud_exit_push_png);
	
		this._menuItem = new cc.MenuItemSprite(menuSpriteNormal,
											 menuSpriteSelected,
											 this.onMenuCallback,
										     this );

		this._menuItem.setPosition(10, 10);
		
		this._menuItem.setAnchorPoint(0, 0);

		this._menu = new cc.Menu(this._menuItem);
		this._menu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0,
		});
		this.addChild(this._menu);
		//--------------DELETE IN A FINAL VERSION---------------
		//=====Mouse Event============
		if ('mouse' in cc.sys.capabilities){
			cc.eventManager.addListener({
				event: cc.EventListener.MOUSE,
				onMouseMove: function(event){
					var target = event.getCurrentTarget();
					var parent = target.getParent()
									
						var locationInNode = target.convertToNodeSpace(event.getLocation());	
						var item =  target._menuItem;
						var s2 = item.getContentSize();
						var rect2 = cc.rect(10,
											10, 
											s2.width, 
											s2.height);					
						if (cc.rectContainsPoint(rect2, locationInNode)) {  
							item.setNormalImage(new cc.Sprite(res.hud_exit_over_png));			
						}
						else{
							item.setNormalImage(new cc.Sprite(res.hud_exit_png));
						}
					
				}						
			}, this);
		}
	},
	
	onMenuCallback:function(){
	
		
		if(GameManager.getInstance().getGameMode() == SS.GAME_MODE.RELAX){
			var scene = SelectLevelMenu.scene();
			cc.director.pushScene(new cc.TransitionFade(1, scene));
		}else{
			GameManager.getInstance().setGameState(SS.GAME_STATE.GAME_OVER);
			var parent = this.getParent();
			parent.showResults();
		}
		
	},
	

});
