function actions(){
	$('.sl_listen a, #mb_jukebox a').bind('click', playAudio);
	$('.sl_video a, #mb_video a').bind('click', playVideo);
}

function playAudio(){
	var id = $(this).attr('id').split('sermon')[1];
	var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=23&sermonid='+id+'&useSkin=skin_plain.xml&CMS_LINK=http://my.ekklesia360.com';
	wimpyPopPlayer(url,'wimpyMP3player','width=350,height=140,title=blah');
	return false;		 
}

function playVideo(){
	var url = $(this).attr('href');
	waspPopup(url, 330, 220);
	return false;
}

$(document).ready(function(){
	actions();
	
	/* SERMON SORTING */		
	// see if there is something in the query string to initially load
	
	$('#all-messages').click(function(){
		window.location.hash = 'all';
		$('#sermon-content').html('').css({height:'300px', background:'url(/images/ajax-loader.gif) no-repeat center center'});
		$.get('/ajax-sermons.php', {
			'groupby':'all',
			'key':'current',
			'val':'current'
		},
		function(o){
			var response = o.split('<!--split-->');
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('#current').hide();
			$('#all-messages').focus();
			actions();
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		$('#sermon-content').html('').css({height:'300px', background:'url(/images/ajax-loader.gif) no-repeat center center'});
		if(this.selectedIndex !== 0){
			$.get('/ajax-sermons.php', { 
				'groupby':this.id,
				'key':this.id,
				'val':this.value			
				}, 
				function(o){
					var response = o.split('<!--split-->');
					$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
					$('#current').hide();					
					
					// reset sorter selects to first value
					$('.sorter').attr({ selectedIndex:0 })		
					$('#all-messages').focus().css('outline', 'none');
					actions();
				}
			);
		}
	});			
});