Writing javascript for displaying gallery view