Why does the definition of orthogonality use a weighting function? I've been reading about the Fourier series and was looking over the Wolfram MathWorld page on orthogonality, which provides this definition:

Two functions $f(x)$ and $g(x)$ are orthogonal over the interval $a\leq x\leq b$ with weighting function $w(x)$ if
$$\left<\,f\left(x\right)|\,g\left(x\right)\right>\equiv \int_a^bf\left(x\right)g\left(x\right)w\left(x\right)\,dx=0.$$

Why is a weighting function used here? Surely $\int_a^bf\left(x\right)g\left(x\right)\,dx$ has to equal $0$ on its own for the two functions to be considered orthogonal.
 A: If $f(x) = \sum a_i e_i(x)$ and the $e_i(x)$ are orthonormal, within the appropriate restrictions, then, for all $i$, $a_i = \langle f, e_i \rangle$.
In that sense, weighting functions allow you to more fully abstract the concept of orthogonality, making it possible to exploit the above property more often.
A: Why? For each weighting function we have a different inner product. For instance, if you are studying periodic functions whose period is $2\pi$, it is natural to define $w(x)=\frac1{2\pi}$; in other words,$$\bigl\langle f(x),g(x)\bigr\rangle=\frac1{2\pi}\int_0^{2\pi}f(x)g(x)\,\mathrm dx.$$And in other contexts it may be appropriate to use non-constant functions as weighting functions.
A: 
Surely $\int_a^b f(x) \, g(x) \, dx$ has to equal $0$ on its own for the two functions to be considered orthogonal.

This is not true. 
Take $[a,b]=[-1,1]$, $f(x) = 1$ for all $x$, and $g(x) = +1$ for $x>0$ and $g(x)
 = -1$ for $x<0$. Then
$$\int_{-1}^{1} f(x) \, g(x) \, dx = 0$$
but for $w(x) = 1$ for $x<0$ and $w(x) = 2$ for $x>0$ we get
$$\int_{-1}^{1} f(x) \, g(x) \, w(x) dx = 1$$
so the functions are not orthogonal when we have this weight.
A: The definition of orthogonality makes sense only if you specify to which scalar product it refers. In the definiton you quoted the scalar product is:
$$\langle f,g \rangle = \int_a^b f(x)g(x)w(x)dx $$
So the definition of orthogonality is:
$$0 = \langle f,g \rangle = \int_a^b f(x)g(x)w(x)dx$$.
A: But why include the weight function in the definition if it's basically extraneous? That would just be extra words for no gain.
There must be an actual application of an inner product with such a non-constant weight function, right?
One need look no farther than theory, in fact.
The best reason I've found for this particular definition is that by suitable choices in weight function, all the classical orthogonal polynomials are subsumed under one definition, that is, Jacobi, Hermite, Laguerre, and indeed even more types.
