moved javascript bits to existing document.ready function