$(function() {

$('#sortfacts_select').change(function(e) {
	var category = $(this).val();
	var tracking_label = category;
	if (tracking_label != 'All') {
		tracking_label = 'The_' + tracking_label;
	}
	pageTracker._trackEvent('Facts', 'Sort', tracking_label);
	location.hash = category;	
	$(window).trigger('hashchange'); // not working in IE7 so manually trigger :<
});

$('#facts_list li span.icon_plus').live('click', function() {
	if ($(this).hasClass('active')) {
		$(this).removeClass('active').parent().next('p.fact_details').slideUp('fast').dequeue();
		pageTracker._trackEvent('Facts', 'Sources', 'Hide');
	}
	else {
		$(this).addClass('active').parent().next('p.fact_details').slideDown('fast').dequeue();
		pageTracker._trackEvent('Facts', 'Sources', 'View');
	}
});
/*
$('#facts_list li span.icon_minus').live('click', function() {
	$(this).prev('span.icon_plus').removeClass('active').parent().next('p.fact_details').slideUp('fast').dequeue();
	pageTracker._trackEvent('Facts', 'Sources', 'Hide');
});
*/

function resizeFactsList() {
	var flh = $('#facts_list').height();
	var fc = $('#facts_container');
	if (flh < 400) {
		fc.height(flh);
	}
	else {
		fc.height(400);
	}
}

$(window).bind('hashchange', function(e) {
	var hash = location.hash.slice(1);
	if ($('#sortfacts_select').val() !== hash) {
		$('#sortfacts_select option').removeAttr('selected');
		$('#sortfacts_select option[value=' + hash + ']').attr('selected', 'selected');
	}
	$('#facts_body').load('facts_list.cfm', { category: hash }, resizeFactsList);
	document.title = 'truth\'s FACTory'; // strange bug
});
$(window).trigger('hashchange');

$('#facts_buttons a.button_print').live('click', function(e) {
	e.preventDefault();
	pageTracker._trackEvent('Facts', 'Print', $(this).attr('rel'));
	window.open(this.href, 'pdf', 'width=800,height=600,resizable=1,scrollbars=1');
});

});