function AmapLite(_sViewportId, _iViewportWidth, _iViewportHeight)
{
    var Bslib = new BsLib130206();
    this.sViewportId = _sViewportId;
    this.iViewportWidth = _iViewportWidth;
    this.iViewportHeight = _iViewportHeight;

    this.iMapWidth = '';
    this.iMapHeight = '';

    this.fNorth = '';
    this.fSouth = '';
    this.fEast  = '';
    this.fWest  = '';

    this.fDppLat = '';
    this.fDppLng = '';
    this.fOriDppLat = '';
    this.fOriDppLng = '';

    this.fZoomFactor = 1.0;
    this.sRequestUri = '';

    this.sPath = '';
    this.sFileName = '';

    this.oMapEntity;


    this.setRequestUri = function(_sRequestUri)
    {
        this.sRequestUri = _sRequestUri;
    }

    this.buildInterface = function()
    {
        this.buildElement();
        this.initElement();
        this.attachElementEvent();
    }

    this.addMapEntity = function(_oMapEntity)
    {
        this.oMapEntity = _oMapEntity;
    }

    //set value to initialize
    this.setMap = function(_sMapRid)
    {
        var _oXmlHttp = Bslib.getXmlHttp();
        var _sUriParam = "maprid=" + _sMapRid + "&";
        _sUriParam += "iehack" + Math.random().toFixed(3) + "&";

        _oXmlHttp.open("GET", this.sRequestUri + _sUriParam, true);
        _oXmlHttp.onreadystatechange = Bslib.bind(this, 'initMap', [_oXmlHttp]);
        _oXmlHttp.send(null);
    }

    this.initMap = function(_oXmlHttp)
    {
        if (_oXmlHttp.readyState == 4) {

            this.setMapValue(_oXmlHttp);
            this.buildDynamicElement();
            this.initDynamicElement();
            this.onMapRedraw();
            this.zoomBestFit();
        }
    }

    this.buildElement = function()
    {
        this.eViewport = document.getElementById(this.sViewportId);

        this.eContainer = document.createElement('div');
        this.eContainer.id = "map-container";
        this.eViewport.appendChild(this.eContainer);

        this.eLoadingImg = document.createElement('img');
        this.eLoadingImg.id = "loading_img";
        this.eLoadingImg.src = 'http://bsmart-platform.com/Bmcv2/images/progress/slantmove.gif';

        this.eStatus = document.createElement('div');
        this.eStatus.id = "map-status";
        this.eStatus.appendChild(this.eLoadingImg);
        this.eViewport.appendChild(this.eStatus);

        this.eDragger = document.createElement('div');
        this.eDragger.id = "map-dragger";
        this.eViewport.appendChild(this.eDragger);

        this.eSubstrate = document.createElement('div');
        this.eSubstrate.id = "map-substrate";
        this.eViewport.appendChild(this.eSubstrate);

        this.eZoomPanel = document.createElement('div');
        this.eZoomPanel.id = "map-zoompanel";
        this.eViewport.appendChild(this.eZoomPanel);

        this.eZoomIn = document.createElement('div');
        this.eZoomIn.id = "map-zoomin";
        this.eZoomIn.title = "Zoom in";
        this.eZoomIn.appendChild( document.createTextNode( String.fromCharCode(43) ) );
        this.eZoomPanel.appendChild(this.eZoomIn);

        this.eZoomOut = document.createElement('div');
        this.eZoomOut.id = "map-zoomout";
        this.eZoomOut.title = "Zoom out";
        this.eZoomOut.appendChild( document.createTextNode( String.fromCharCode(45) ) );
        this.eZoomPanel.appendChild(this.eZoomOut);

        this.eZoomBestFit = document.createElement('div');
        this.eZoomBestFit.id = "map-zoombestfit";
        this.eZoomBestFit.title = "Zoom best fit";
        this.eZoomBestFit.appendChild( document.createTextNode("Fit") );
        this.eZoomPanel.appendChild(this.eZoomBestFit);

        this.eZoomOriginal = document.createElement('div');
        this.eZoomOriginal.id = "map-zoomoriginal";
        this.eZoomOriginal.title = "Zoom original map size";
        this.eZoomOriginal.appendChild( document.createTextNode("100%") );
        this.eZoomPanel.appendChild(this.eZoomOriginal);
    }

    this.initElement = function()
    {
        this.eViewport.style.width = this.iViewportWidth;
        this.eViewport.style.height = this.iViewportHeight;

        this.eStatus.style.visibility = "hidden";

        this.eContainer.style.width = 1;
        this.eContainer.style.height = 1;

        this.eDragger.style.width = this.iViewportWidth;
        this.eDragger.style.height = this.iViewportHeight;
        this.eDragger.style.top = 0;
        this.eDragger.style.left = 0;

        this.eSubstrate.style.width = 1;
        this.eSubstrate.style.height = 1;
        this.eSubstrate.style.top = 0;
        this.eSubstrate.style.left = 0;

        this.eZoomPanel.style.top = this.iViewportHeight - 30;
        this.eZoomPanel.style.left = this.iViewportWidth - 130;
    }

    this.attachElementEvent = function()
    {
        this.eZoomIn.onclick = Bslib.bind(this, 'zoomIn', []);
        this.eZoomOut.onclick = Bslib.bind(this, 'zoomOut', []);
        this.eZoomBestFit.onclick = Bslib.bind(this, 'zoomBestFit', []);
        this.eZoomOriginal.onclick = Bslib.bind(this, 'zoomOriginal', []);
        this.eDragger.onmousedown = Bslib.bindEvent(this, 'setDragBegin', []);
    }

    this.onMapRedraw = function()
    {
        this.showStatusLoading();
        if(this.oMapEntity != null){
            if (this.oMapEntity.getReadyState() == 4) {
                this.oMapEntity.showPoints(this.fDppLat, this.fDppLng, this.fNorth, this.fSouth, this.fEast, this.fWest);
            }
        }
    }

    this.showStatusLoading = function()
    {
        var fnHideStatus = Bslib.bind(this, 'hideStatusLoading', []);
        this.eStatus.style.visibility = "visible";

        setTimeout(fnHideStatus, 2000);
    }

    this.hideStatusLoading = function()
    {
        this.eStatus.style.visibility = "hidden";
    }

    this.zoomIn = function()
    {
        var _fZoomFactor = this.getZoomFactor();
        _fZoomFactor += 0.1;

        //reposition image

        var iXToMove= (this.iViewportWidth/2) - ( ( ( (this.iViewportWidth/2) - this.eSubstrate.offsetLeft ) / (_fZoomFactor - 0.1) ) * _fZoomFactor );
        var iYToMove= (this.iViewportHeight/2) - ( ( ( (this.iViewportHeight/2) - this.eSubstrate.offsetTop ) / (_fZoomFactor - 0.1) ) * _fZoomFactor );

        this.onMove(Math.round(iYToMove), Math.round(iXToMove));
        this.setZoomFactor(_fZoomFactor);
        this.initDynamicElement();
        this.onMapRedraw();
    }

    this.zoomOut = function()
    {
        var _fZoomFactor = this.getZoomFactor();
        _fZoomFactor -= 0.1;

        //repostion image
        var iXToMove= (this.iViewportWidth/2) - ( ( ( (this.iViewportWidth/2) - this.eSubstrate.offsetLeft ) / (_fZoomFactor + 0.1) ) * _fZoomFactor );
        var iYToMove= (this.iViewportHeight/2) - ( ( ( (this.iViewportHeight/2) - this.eSubstrate.offsetTop ) / (_fZoomFactor + 0.1) ) * _fZoomFactor );

        this.onMove(Math.round(iYToMove), Math.round(iXToMove));
        this.setZoomFactor(_fZoomFactor);
        this.initDynamicElement();
        this.onMapRedraw();
    }

    this.zoomOriginal = function()
    {
        this.eSubstrate.style.top = 300 - (this.iMapHeight/2);
        this.eSubstrate.style.left = 400 - (this.iMapWidth/2);
        this.eContainer.style.top = 300 - (this.iMapHeight/2);
        this.eContainer.style.left = 400 - (this.iMapWidth/2);
        this.setZoomFactor(1.0);
        this.initDynamicElement();
        this.onMapRedraw();
    }

    this.zoomBestFit = function()
    {
        var _fHeight = (this.iViewportWidth / this.iMapWidth) * this.iMapHeight;
        var iTop = '';
        var iLeft = '';
        var _fZoomFactor = '';

        if (_fHeight < this.iViewportHeight ) {
            _fZoomFactor = this.iViewportWidth / this.iMapWidth;
            iTop = (this.iViewportHeight - (this.iMapHeight * _fZoomFactor) ) / 2;
            iLeft = 0;

        } else if (_fHeight > this.iViewportHeight) {
            _fZoomFactor = this.iViewportHeight / this.iMapHeight;
            iTop = 0;
            iLeft = (this.iViewportWidth - (this.iMapWidth * _fZoomFactor) ) / 2;
        }

        this.onMove(iTop, iLeft);
        this.setZoomFactor(_fZoomFactor);
        this.initDynamicElement();
        this.onMapRedraw();
    }

    this.setMapValue = function(_oXmlHttp)
    {
            var _oMap = eval('(' + _oXmlHttp.responseText + ')');

            this.iMapWidth = _oMap.imapwidth;
            this.iMapHeight = _oMap.imapheight;

            this.fNorth = _oMap.fnorth;
            this.fSouth = _oMap.fsouth;
            this.fEast  = _oMap.feast;
            this.fWest  = _oMap.fwest;

            this.sFileName = _oMap.sfilename;

            this.fOriDppLat = (this.fNorth - this.fSouth) / this.iMapHeight;
            this.fOriDppLng = (this.fEast - this.fWest) / this.iMapWidth;
    }

    this.goToPosition = function(_fLat, _fLng)
    {
        (_fLat - this.fNorth)
    }

    this.buildDynamicElement = function()
    {
		if (this.eSubstrate.firstChild) {
			this.eSubstrate.removeChild(this.eSubstrate.firstChild);
		}
        this.eImg = document.createElement('img');
        this.eImg.id = 'map-image';
        this.eImg.src = this.sPath + this.sFileName;
        this.eImg.style.zindex = 0;
        this.eSubstrate.appendChild(this.eImg);
    }

    this.setZoomFactor = function(_fZoomFactor)
    {
        this.fZoomFactor = _fZoomFactor;
    }

    this.getZoomFactor = function()
    {
        return this.fZoomFactor;
    }

    this.initDynamicElement = function()
    {
        this.eImg.style.width = this.iMapWidth * this.fZoomFactor;
        this.eImg.style.height = this.iMapHeight * this.fZoomFactor;

        this.fDppLat = this.fOriDppLat / this.fZoomFactor;
        this.fDppLng = this.fOriDppLng / this.fZoomFactor;
    }

    //Drag functions
    this.setDragBegin = function(_event)
	{
		//Change cursor
		this.eDragger.style.cursor = "move";

		//calculate original point
		var _iOriClientX = _event.clientX;
		var _iOriClientY = _event.clientY;
		var _iOriSubstrateOffsetLeft = this.eSubstrate.offsetLeft;
		var _iOriSubstrateOffsetTop = this.eSubstrate.offsetTop;

		this.eDragger.onmousemove 	= Bslib.bindEvent(this,"setDragMove",[_iOriClientX, _iOriClientY, _iOriSubstrateOffsetLeft,  _iOriSubstrateOffsetTop]); //attach event handler
		this.eDragger.onmouseup		= Bslib.bind(this,"setDragEnd", []);
		this.eDragger.onmouseout 	= Bslib.bind(this,"setDragEnd", []);
	}

	this.setDragMove = function(_iOriClientX, _iOriClientY, _iOriSubstrateOffsetLeft, _iOriSubstrateOffsetTop, _event)
	{
        var _iTop  = (_event.clientY - _iOriClientY) + _iOriSubstrateOffsetTop;
        var _iLeft  = (_event.clientX - _iOriClientX) + _iOriSubstrateOffsetLeft;

        this.onMove(_iTop, _iLeft);
	}

    this.onMove = function(_iTop, _iLeft)
    {
        this.eSubstrate.style.top = _iTop;
        this.eSubstrate.style.left = _iLeft;
        this.eContainer.style.top = _iTop;
        this.eContainer.style.left = _iLeft;
    }

    this.setPath = function(_sPath)
    {
        this.sPath = _sPath;
    }

	this.setDragEnd = function()
	{
		//change cursor
		this.eDragger.style.cursor = "auto";

		//detach event handler
		this.eDragger.onmousemove = null;
		this.eDragger.onmouseup = null;
		this.eDragger.onmouseout = null;
	}
}