$(document).ready(function(){
	$('#nav_home').hover(
		function(){
			$('#nav-top').css({background:'url(/images/home_hover.png) no-repeat'});
		},
		function(){
			$('#nav-top').css({background:'url(/images/nav_top_bg.png) no-repeat'});		
		}
	);

	$('#articleLists').change(function(){
		if(this.selectedIndex == 1) window.location = '/mcms_page_articlelist_sort.php?groupby=series';
		if(this.selectedIndex == 2) window.location = '/mcms_page_articlelist_sort.php?groupby=category';
		if(this.selectedIndex == 3) window.location = '/mcms_page_articlelist_sort.php?groupby=month';
		if(this.selectedIndex == 4) window.location = '/mcms_page_articlelist_sort.php?groupby=author';		
	});
	
	$('#all-messages').click(function(){
		$('#sermon-content').css({
			background:'url(/images/ajax-loader.gif) no-repeat center center',
			height:'200px'
		}).html('');
		
		$.get('/ajax-sermons.php', {
			'groupby':'all',
			'key':'current',
			'val':'current'
		},
		function(o){
			var response = o.split('<!--split-->');
			$('#primaryContent > h2').html(response[0]);
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('#current').hide();
			$('.sorter').attr({selectedIndex:0});		
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		$('#sermon-content').css({
			background:'url(/images/ajax-loader.gif) no-repeat center center',
			height:'200px'
		}).html('');
		if(this.selectedIndex != 0){
			$.get('/ajax-sermons.php', { 
				'groupby':this.id,
				'key':this.id,
				'val':this.value			
				}, 
				function(o){
					var response = o.split('<!--split-->');
					$('#primaryContent > h2').html(response[0]);
					if(response[1] == '') {
						$('#sermon-content').html('<p>No sermons could be found for the selected filtering option.</p>')
						.css({
							height:'auto',
							background:'none'
						}).focus();
					} else {
						$('#sermon-content').html(response[1])
						.css({
							height:'auto',
							background:'none'
						});			
					}
					$('#current').addClass('hidden');					
					$('.sorter').attr({ selectedIndex:0});
					$('#all-messages').focus().css({outline:'none'});					
				}
			);
		}
	});	
});

$(document).ready(function(){
	$('.external').click(function(){
		window.open(this.href);
		return false;
	});
});