Porting code for preview + moving code

Moving some code into their own files for better modularity.
Ported some of the functions I used in the php to js in preparation for
the preview function.
Merge remote-tracking branch 'origin/master'

Conflicts:
	php/testplayer.php