Move most of the logic outside jQuery and encapsulate FusionCharts rendering in a function