/// <summary>
        /// Create various events that tie the functionality of the spreadsheet
        /// </summary>
        /// <param name="input">Input element to attach events to</param>
        private void AttachEvents(InputElement input)
        {
            input.AddEventListener("blur", delegate(ElementEvent @event)
            {
                GetRowHeader(@event.SrcElement).ClassList.Remove("selected");
                GetColumnHeader(@event.SrcElement).ClassList.Remove("selected");

                ProcessCell((InputElement)@event.SrcElement);
            }, false);

            input.AddEventListener("focus", delegate(ElementEvent @event)
            {
                GetRowHeader(@event.SrcElement).ClassList.Add("selected");
                GetColumnHeader(@event.SrcElement).ClassList.Add("selected");

                object formula = @event.SrcElement.GetAttribute("data-formula");

                if (formula != null && formula.ToString().Length > 1)
                {
                    input.Value = formula.ToString();
                }
            }, false);

            input.AddEventListener("keydown", delegate(ElementEvent @event)
            {
                if (@event.KeyCode == 27) //Escape
                {
                    input.Value = "";
                    input.Blur();
                }
                else if (@event.KeyCode == 38) // up arrow
                {
                    SetFocusFromCellTo(@event.SrcElement.ID, 0, -1);
                    @event.PreventDefault();
                }
                else if (@event.KeyCode == 40) // down arrow
                {
                    SetFocusFromCellTo(@event.SrcElement.ID, 0, 1);
                    @event.PreventDefault();
                }
                else if (@event.KeyCode == 37) // left arrow
                {
                    SetFocusFromCellTo(@event.SrcElement.ID, -1, 0);
                    @event.PreventDefault();
                }
                else if (@event.KeyCode == 39) // right arrow
                {
                    SetFocusFromCellTo(@event.SrcElement.ID, 1, 0);
                    @event.PreventDefault();
                }
            }, true);

            input.AddEventListener("keypress", delegate(ElementEvent @event)
            {
                if (@event.KeyCode == 13) // Enter Key
                {
                    input.Blur();

                    SetFocusFromCellTo(@event.SrcElement.ID, 0, 1);
                    @event.PreventDefault();
                }
            }, false);
        }