define([
    "jquery",
    "./key.code"
],
function(
    jq,
    KeyCode
){

    /**
     * @constructor
     */
    return function ( accessibilityKey, accessibilityLocation, accessibilityPositionX, accessibilityPositionY ) {

        var accessibilityTooltip,
            keyOptions = KeyCode.getKeyOptions( accessibilityKey );

        function createAccessibilityTooltip() {
            var accessibilityPositionCss = getAccessibilityPosition( accessibilityLocation, accessibilityPositionX, accessibilityPositionY );

            accessibilityTooltip = jq( document.createElement( "div" ) )
                .css( {
                    "position": "absolute",
                    "z-index": "99",
                    "border": "0 solid white",
                    "padding": "0 5px",
                    "width": "auto",
                    "height": "18px",
                    "font-size": "12px",
                    "font-family": "arial, helvetica, sans-serif",
                    "background-color": "#FFFFAA",
                    "vertical-align": "middle",
                    "text-align": "center"
                } )
                .hide();
            accessibilityTooltip.css( accessibilityPositionCss );
            accessibilityTooltip.html( keyOptions["label"] );

            function getAccessibilityPosition( accessibilityLocation, accessibilityPositionX, accessibilityPositionY ) {
                var accessibilityPositions = [
                    //top-left
                    {
                        "top": "0px",
                        "left": "0px",
                        "margin-left": "-6px",
                        "margin-top": "-6px"
                    },
                    //top-right
                    {
                        "top": "0px",
                        "right": "0px",
                        "margin-right": "-6px",
                        "margin-top": "-6px"
                    },
                    //bottom-left
                    {
                        "bottom": "0px",
                        "left": "0px",
                        "margin-left": "-6px",
                        "margin-bottom": "-6px"
                    },
                    //bottom-right
                    {
                        "bottom": "0px",
                        "right": "0px",
                        "margin-right": "-6px",
                        "margin-bottom": "-6px"
                    }
                ];

                if ( accessibilityLocation != 4 ) {
                    return accessibilityPositions[accessibilityLocation];
                } else {
                    return {
                        "top": "0px",
                        "left": "0px",
                        "margin-left": accessibilityPositionX + "px",
                        "margin-top": accessibilityPositionY + "px"
                    };
                }
            }
            return {
                getElement: function () {
                    return accessibilityTooltip.get( 0 );
                },
                show: function () {
                    accessibilityTooltip.show();
                },
                hide: function () {
                    accessibilityTooltip.hide();
                },
                getKeyCode: function () {
                    return keyOptions["keyCode"];
                },
                getKeyLabel: function () {
                    return keyOptions["label"];
                }
            }
        }

        return {
            build: createAccessibilityTooltip
        };
    };
});
