Updated Javascript navigation code from Rock Hammer.