Your DOM-generation Javascript is a bit of a mess ... but it's easy to get lost writing that kind of code. I'd strongly recommend using some kind of micro-templating engine to handle the data-to-HTML conversion stuff.