// Functions
function loadResourceStyles() {
	$('#resourcesTable tbody > tr:not(.extended, .type-headline):even').addClass('odd').next(':not(.type-headline)').addClass('odd');
	$('#resourcesTable tr.type-headline:first').addClass('first');
	$('#resourcesTable tbody > tr.extended').each(function(){
		$(this)
			.find('td:first').addClass('first').end()
			.find('td:last').addClass('last');
	});
	// Load Shadowbox Live for AJAX 
	var shadowboxElements = $('a[rel*="shadowbox"]');
	if(shadowboxElements.length) {
		Shadowbox.setup(shadowboxElements,{
			language: 'en',
			players: ["qt", "wmp", "swf", "flv"],
			flashBgColor: "#FFFFFF",
			initialHeight: 974,
			initialWidth: 612
		});
	}
}

// Podcast Audio Player
AudioPlayer.setup("/swf/mp3player-resources.swf", {  
	width: 712,  
	initialvolume: 100,  
	transparentpagebg: "yes",  
	left: "FFFFFF", 
	leftbg: "FFFFFF",
	rightbg: "f0882c",
	rightbghover: "FFFFFF",
	lefticon: "f0882c",
	righticon: "FFFFFF",
	righticonhover: "f0882c",
	voltrack: "F0F5F8",
	volslider: "f0882c",
	bg: "FFFFFF"
});

// Shadowbox Video Player
Shadowbox.init({
	language: 'en',
	players: ["qt", "wmp", "swf", "flv"],
	flashBgColor: "#FFFFFF",
	initialHeight: 974,
	initialWidth: 612,
	skipSetup: true 
});

$(function(){
	
	loadResourceStyles();
	
	// Table Events
	$('table.resultsTable tr.extended').hide();
	$('a.toggle-extended').live('click',function(){
		$(this).toggleClass('open');
		var $extendedRow = $(this).parent().parent().next();
		//$extendedRow.animate({opacity:'toggle'},'slow');
		$extendedRow.toggle();
		return false;
	});
	
	// Sidebar CSS
	$('body.resources .callout *.middle dd.expandable:last').addClass('last');
	$('body.resources .callout *.middle dd.expandable:first').addClass('first');
	$('body.resources .callout *.middle dt.expandable:last').addClass('last');
	$('body.resources .callout *.middle dt.expandable:first').addClass('first');
	$('*.filter-subbox:last').addClass('last');
	
	// Expandable Sidebar Events
	$('a.toggle-subbox').live('click',function(){
		$(this).toggleClass('open').parent().next().toggle();
		return false;
	});
	$('dt.expandable input:checkbox').live('click',function(){
		var $childCheckboxes = $(this).parent().next().next().find('input:checkbox');
		if($(this).is(':checked')) {
			$childCheckboxes.each(function(){
				$(this).attr('checked','checked');
			});
		} else {
			$childCheckboxes.removeAttr('checked');
		}
	});
	$('input:checkbox[name="filter_all"]').live('click',function(){
		var $childCheckboxes = $(this).parent().parent().find('input:checkbox');
		if($(this).is(':checked')) {
			$childCheckboxes.each(function(){
				$(this).attr('checked','checked');
			});
		} else {
			$childCheckboxes.removeAttr('checked');
			//$(this).parent().next().find('strong').text('Select All');
		}
	});
});
