Hat matrix with simple linear regression

In these lecture notes:

enter image description here

However I am unable to work this out myself. When I multiply things out I get $\frac{1}{nS_{xx}}(\sum_{j=1}^n x_j^2 -2n\bar{x}x_i+nx_i^2)$. For things to be true, the terms inside the parenthesis can be rearranged to be $S_{xx}+n(x_i-\bar{x})^2$. I tried rearranging the terms so $\sum_{j=1}^n x_j^2 -n\bar{x}x_i+nx_i^2-n\bar{x}x_i$, but I can't seem to get to the answer. There must be some form of $S_{xx}$ that I am not aware of that is buried in their somewhere. Any help would be appreciated.


After multiplying things out, one gets \begin{align} h_{ii}=\frac{1}{nS_{xx}}\left(\sum_{j=1}^{n} x_{j}^{2}-2n\bar{x}x_{i}+nx_{i}^{2}\right)&=\frac{1}{nS_{xx}}\left(\sum_{j=1}^{n} x_{j}^{2}-n\bar{x}^{2}+[n\bar{x}^{2}-2n\bar{x}x_{i}+nx_{i}^{2}]\right)\\ &=\frac{1}{nS_{xx}}\left(\sum_{j=1}^{n} x_{j}^{2}-n\bar{x}^{2}\right)+\frac{1}{nS_{xx}}[n\bar{x}^{2}-2n\bar{x}x_{i}+nx_{i}^{2}]\\ & = \frac{1}{nS_{xx}}\cdot S_{xx} + \frac{1}{nS_{xx}}n[x_{i}-\bar{x}]^{2}=\frac{1}{n}+\frac{1}{S_{xx}}[x_i-x]^{2} \end{align}