jQuery(document).ready(function() {
	
	var url = location.href;
	var pos = location.href.lastIndexOf('#');

	jQuery('.statstab').tabs();

	if(pos == -1) {
		jQuery('.statstab').tabs('select', 0); 
	} else {
		var tabIdToSelect = url.substring(pos+1, url.length);	
		jQuery('.statstab').each(function () {
			if(jQuery(this).find('#' + tabIdToSelect).length > 0) {
				jQuery(this).tabs('select', url.substring(pos+1, url.length));
			}
		});
  }

	jQuery('.accordion').accordion({
		collapsible: true,
		icons: {
			'header': 'ui-icon-triangle-1-s',
			'headerSelected': 'ui-icon-triangle-1-n'
		},
		change: function(event, ui) {
			if(jQuery(ui.newContent).html() != null) {
				var imagePath = ui.newContent.find('div.hidden').text();
				
				jQuery(this).siblings('.statstabImageContainer').children('img').fadeOut(200, function() {
					jQuery(this).attr('src', imagePath).load(function() {
						jQuery(this).fadeIn(200);
					});
				});
			}
		},
		autoHeight: false,
		active: false,
	});
	
	jQuery('.accordion').accordion('activate', 0);
	
	jQuery('a').focus(function() {
		jQuery(this).blur();
	});
});

