﻿/* StaticMan.js*/

function _StaticMan() {
    var StaticMan = Class.create({
        initialize: function(parent, container) {
            this.container = container;
            this.parent = parent;
            this.StaticLayer = WSpec.getBaseLayer(80, 'StaticLayer'); //new Element('DIV');
            this.scaleArray = new Array();
            this.container.appendChild(this.StaticLayer);
            this.setScaleValue();
            this.makeDefaultLayers();


            this.setInnerEvent();

            if (Prototype.Browser.IE) {
                this.StaticLayer.unselectable = "on";
                this.StaticLayer.onselectstart = function() { return false; }
            } else {
                this.StaticLayer.style.MozUserSelect = "none";
            }


        },
        setScaleValue: function() {
            var fscale = 49.4;
            var depoint = 100;
            for (i = 0; i < 12; i++) {
                this.scaleArray[i] = fscale / (Math.pow(2, i));
                if (i < 6) {
                    this.scaleArray[i] = Math.round(this.scaleArray[i] * depoint) / depoint + 'km';
                }
                else {
                    this.scaleArray[i] = Math.round((this.scaleArray[i] * 1000) * depoint) / depoint + 'm';
                }
            }
        },
        setInnerEvent: function() {
            EventMan.addListener(this.parent, 'resizeWindow', this.setLogoPosition.bindAsEventListener(this));
            EventMan.addListener(this.parent, 'zoomTileLayer', this.setScaleText.bindAsEventListener(this));

            this.LogoLayer.observe('click', this.click.bindAsEventListener(this));
            this.LogoLayer.observe('mouseover', this.mouseover.bindAsEventListener(this));
            this.LogoLayer.observe('mouseout', this.mouseout.bindAsEventListener(this));
        },
        setLogoPosition: function() {
            this.LogoLayer.style.top = WSpec.logotop;
            this.CopyrightLayer.style.top = WSpec.copyrighttop;
            this.CopyrightLayer.style.left = WSpec.copyrightleft;

            if (WSpec.Options.useScale && !WSpec.Options.useCopyright) {
                this.ScaleLayer.style.top = WSpec.copyrighttop - 10;
            } else {
                this.ScaleLayer.style.top = WSpec.scaletop;
            }
            this.ScaleLayer.style.left = WSpec.scaleleft;

        },
        makeDefaultLayers: function() {
            this.LogoLayer = new Element('div');
            this.LogoLayer.id = 'LogoLayer';
            var img = new Element('img');
            img.src = WSpec.logourl;

            if (Prototype.Browser.IE) {
                img.unselectable = "on";
                img.onselectstart = function() { return false; }
            } else {
                img.style.MozUserSelect = "none"
            }

            if (Prototype.Browser.IE) {
                this.LogoLayer.unselectable = "on";
                this.LogoLayer.onselectstart = function() { return false; }
            } else {
                this.LogoLayer.style.MozUserSelect = "none"
            }

            this.LogoLayer.appendChild(img);
            this.LogoLayer.setStyle({
                'position': 'absolute',
                'left': WSpec.logoleft,
                'top': WSpec.logotop
                //'top' : 0	
                //'zIndex' : 20
            });


            this.CopyrightLayer = new Element('div');
            this.CopyrightLayer.id = 'CopyrightLayer';
            var img = new Element('img');
            img.src = WSpec.copyrighturl;
            this.CopyrightLayer.appendChild(img);
            this.CopyrightLayer.setStyle({
                'position': 'absolute',
                'top': WSpec.copyrighttop,
                'left': WSpec.copyrightleft
                //'zIndex' : 16
            });

            this.ScaleLayer = new Element('div');
            this.ScaleLayer.id = 'ScaleLayer';

            this.scale = new Element('div');
            this.scale.setStyle({
                'color': 'red',
                'fontWeight': 'bold',
                'fontSize': '9px'

                //'textDecoration' : 'bold'
                //'border':'1px solid red'
                //'zIndex' : 16
            });
            this.setScaleText(WSpec.initlevel);

            var img = new Element('img');
            img.src = WSpec.scaleurl;

            this.ScaleLayer.appendChild(this.scale);
            this.ScaleLayer.appendChild(img);
            this.ScaleLayer.setStyle({
                'position': 'absolute',
                'top': WSpec.scaletop,
                'left': WSpec.scaleleft,
                'width': WSpec.scalew
                //'border':'1px solid red'
                //'zIndex' : 16
            });


            if (WSpec.Options.useLogo) this.StaticLayer.appendChild(this.LogoLayer);
            if (WSpec.Options.useCopyright) this.StaticLayer.appendChild(this.CopyrightLayer);
            if (WSpec.Options.useScale) this.StaticLayer.appendChild(this.ScaleLayer);

            if (WSpec.Options.useScale && !WSpec.Options.useCopyright) {
                this.ScaleLayer.style.top = WSpec.copyrighttop - 10;
            }
        },
        setScaleText: function(level) {
            this.scale.update(this.scaleArray[12 - level]);
        },
        mouseover: function() {
            WSpec.setCursorHand(this.StaticLayer);

        },
        mouseout: function() {
            WSpec.setCursorNormal(this.StaticLayer);

        },
        click: function() {
            window.open("http://www.whereis.co.kr");
            //location.href("http://www.whereis.co.kr");

        },
        getScale: function(level) {
            var fscale = 49.4; //km
            var scale = (fscale / (Math.pow(2, 12 - level))) * 1000;
            return scale;
        }

    });
	window.StaticMan = StaticMan;
};
_StaticMan();	
