﻿/* RMenuMan.js */

function _RMenuMan() {	
	var RMenuMan = Class.create( {  //InfoBox레이어 만들기.
		initialize: function(parent, container) {
			this.parent = parent;
			this.container = container;	
			this.RMenuLayer = this.makeLayer();//WSpec.getBaseLayer(85, 'RMenuLayer');
			this.container.appendChild(this.RMenuLayer);
			this.RMenuLayer.hide();
			this.RMenuArray = new Array();
			this.setInnerEvent();
			
			
		},	
		makeLayer: function() {
			var layer = WSpec.getBaseLayer(85, 'RMenuLayer');

			layer.setStyle( { 
	        	'position' : 'absolute',
	        	'width' : '100px', 
	        	'height' : '0px',
	        	//'minHeight' : '100px', //firefox 문제..
				'border' : '2px solid #7DA03A',
				'backgroundColor' : '#ffffff',
				'padding':5,
				//'fontWeight' : 'bold',
				//'fontColor' : 'red',
				//'overflow' : 'hidden',
				'float' : 'left',
				'opacity' : 0.9

			});
			//Element.setOpacity(layer, 0.7);
			return layer;
		},
		makeMenuLayer: function(id, title) {
				var newEle = new Element('div');
				newEle.id = id;
				newEle.style.height = '15px';
				newEle.className='info_route_txt';
				//newEle.style.border = '1px solid red';
				newEle.align='left';
				newEle.update(title);
				
				this.RMenuLayer.style.height = WSpec.stripPx(this.RMenuLayer.style.height) + WSpec.stripPx(newEle.style.height);
				this.RMenuLayer.appendChild(newEle);			
				return newEle;				
		},
			
		addMenuItem: function(id, title, func) { //메뉴등록
			if (this.RMenuArray[id] == null) {		
				this.ItemLayer = this.makeMenuLayer(id, title);
				this.RMenuArray[id] = this.ItemLayer;
				
				Event.observe(this.ItemLayer,'click',eval(func).bindAsEventListener(this));
				Event.observe(this.ItemLayer,'mouseover',this.menuMouseOver.bindAsEventListener(this));
				Event.observe(this.ItemLayer,'mouseout',this.menuMouseOut.bindAsEventListener(this));
			}
			else {
				alert('다른 id를 선택하여 주십시오');
			}
		},
		removeMenuItem: function(id) { //메뉴삭제
			if (this.RMenuArray[id] != null) {
				this.RMenuLayer.removeChild(this.RMenuArray[id]);
				this.RMenuArray[id] = null;
			}
			else {
				alert('다른 id를 선택하여 주십시오');
			}
		},

		menuMouseOver: function(event) {
			var menuItem =  Event.element(event).id;
			//this.RMenuArray[menuItem].style.textDecoration="underline";
			this.RMenuArray[menuItem].setStyle( { 
				'backgroundColor' : '#c9ed84'
			});
		},
		menuMouseOut: function(event) {
			var menuItem =  Event.element(event).id;
			this.RMenuArray[menuItem].setStyle( { 
				'backgroundColor' : ''
			});
		},
		
		setInnerEvent: function() {
			Event.observe(this.RMenuLayer,'mouseover',this.mouseOver.bindAsEventListener(this));		
			EventMan.addListener(this.parent,'clickRMenu',this.clickRMenu.bindAsEventListener(this));
			EventMan.addListener(this.parent,'clickTileLayer',this.hide.bindAsEventListener(this));
			EventMan.addListener(this.parent,'moveTileLayer',this.hide.bindAsEventListener(this));
			
		},
		mouseOver: function() {
			WSpec.setCursorHand(this.RMenuLayer);
		},
		
		clickRMenu: function(val) {
			var point = val["point"];
			this.coord = val["coord"];
			if (this.RMenuArray.length > 0) {
				this.RMenuLayer.show();
			}
			this.setPos(point.x, point.y);		
		},
		getRMenuCoord: function() {
			return this.coord;
		},
		setPos: function(x,y) {
			this.RMenuLayer.style.left = x;
			this.RMenuLayer.style.top = y;			
		},
		hide: function() {
			this.RMenuLayer.hide();
		}
	
	});
	window.RMenuMan = RMenuMan;
};
_RMenuMan();	
