added index.php needed to make /images viewable through ajax
added preload function and abstracted a bit of the code