﻿/* EtcMan.js*/

function _EtcMan() {	
	var EtcMan = Class.create( {
		initialize: function(parent,container) {
			this.container = container;
			this.parent = parent;
			this.EtcLayer = WSpec.getBaseLayer(70, 'EtcLayer');
			this.container.appendChild(this.EtcLayer);
			this.makeDefaultLayers();
			this.setInnerEvent();
			this.setVisible(false);
		},
		setVisible: function(visible) {
			if(visible) {
				this.EtcLayer.show();
			} else {
				this.EtcLayer.hide();
			}
			
		},
		setInnerEvent: function() {			
			this.EtcLayer.observe('mousedown', this.mousedown.bindAsEventListener(this));
			this.EtcLayer.observe('mousemove', this.mousemove.bindAsEventListener(this));
			this.EtcLayer.observe('mouseup', this.mouseup.bindAsEventListener(this));
			this.EtcLayer.observe('mousewheel', this.mousewheel.bindAsEventListener(this));
			this.EtcLayer.observe('dblclick', this.dblclick.bindAsEventListener(this));
			this.EtcLayer.observe('mouseover', this.mouseover.bindAsEventListener(this));	
			this.EtcLayer.observe('click', this.click.bindAsEventListener(this));
			//if (window.addEventListener) window.addEventListener('DOMMouseScroll', this.mousewheel, false); //for Mozilla
			if (this.EtcLayer.addEventListener) this.EtcLayer.observe('DOMMouseScroll', this.mousewheel.bindAsEventListener(this)); //for Mozilla
			
			EventMan.addListener(this.parent, 'resizeWindow', this.setCrossLine.bindAsEventListener(this));
		},
		mousedown: function(event) {
			EventMan.trigger(this, 'mousedown',event);
		},
		mousemove: function(event) {
			EventMan.trigger(this, 'mousemove',event);
		},
		mouseup: function(event) {
			EventMan.trigger(this, 'mouseup',event);
		},
		mousewheel: function(event) {
			EventMan.trigger(this, 'mousewheel',event);
		},
		dblclick: function(event) {
			EventMan.trigger(this, 'dblclick',event);
		},
		mouseover: function(event) {
			WSpec.setCursorMove(this.EtcLayer);
		},
		click: function(event) {
			EventMan.trigger(this, 'click', event);
		},
		setCrossLine: function(){
			this.wLine.style.top = WSpec.viewportheight/2;			
			this.wLine.style.width = WSpec.viewportwidth;			
			this.hLine.style.left = WSpec.viewportwidth/2;
			this.hLine.style.height = WSpec.viewportheight; 

		},
		makeDefaultLayers: function() {
			this.CrossLayer = new Element('div');
			
			this.wLine = new Element('div');
			this.wLine.id = 'wLine';
			this.wLine.setStyle( {
	        	'position' : 'absolute',
	        	'top' : WSpec.viewportheight/2,
	        	'left' : '0px',
	        	'background' : 'url('+WSpec.wcrossline+')',
	        	'overflow' : 'hidden',
	        	'width' : WSpec.viewportwidth,
	        	'height' : '1px',
	        	'zIndex' : 15
			});
			this.hLine = new Element('div');
			this.hLine.id = 'hLine';
			this.hLine.setStyle( {
	        	'position' : 'absolute',
	        	'top' : '0px',
	        	'left' : WSpec.viewportwidth/2,
	        	'background' : 'url('+WSpec.hcrossline+')',
	        	'overflow' : 'hidden',
	        	'width' : '1px',
	        	'height' : WSpec.viewportheight,
	        	'zIndex' : 15
	        	
			});
			this.CrossLayer.appendChild(this.wLine);
			this.CrossLayer.appendChild(this.hLine);
			this.EtcLayer.appendChild(this.CrossLayer);
			/*
			this.EtcLayer.appendChild(this.wLine);	
			this.EtcLayer.appendChild(this.hLine);	
			*/
		}
	});
	window.EtcMan = EtcMan;
};
_EtcMan();	
