(function($) { $(function() { $('#comments').mmsComments('Perspective Roundtable Election'); $.ajax({ url: 'counts.aspx?set=Perspective Roundtable Election&field=Country', success: locationChart, dataType: 'jsonp' }); $.ajax({ url: 'counts.aspx?set=Perspective Roundtable Election&field=Position', success: positionChart, dataType: 'jsonp' }); $('.videoLink').click(function() { var top = Math.floor((window.screen.height - 426) / 2); var left = Math.floor((window.screen.width - 716) / 2); var url = this.href; window.open(url, '', 'left=' + left + ',top=' + top + ',width=716,height=426,' + 'scrollbars=no,toolbar=no,menubar=no,status=no'); return false; }); }); var locationChart = function(data) { var us = 0, other = 0; $.each(data, function(key, value) { if(key == 'United States') us = parseInt(value) || 0; else if (key != 'error') other += parseInt(value) || 0; }); var location = $('.chart:eq(1)'); location.attr('src', location.attr('srcHolder') + us + ',' + other); $('.whoIsContributing .location em') .eq(0).text(us).end() .eq(1).text(other); }; var positionChart = function(data) { var values = ''; var counts = $('.whoIsContributing .position em'); $.each(['Physician', 'Student', 'Resident or Trainee', 'Other' ], function(i, n) { if(data[n]) counts.eq(i).text(data[n]); values += (data[n] || 0) + ','; }); var position = $('.chart:eq(0)'); position.attr('src', position.attr('srcHolder') + values); }; })(jQuery);