Measuring Stock Market Contagion with an Application to the Sub-prime Crisis