$(document).ready(function(){
	// tab deal
	$('#tabs li a').click(function(){
		var div = this.rel;
		$('#tabs li').attr('className', '');
		$(this).parent().attr('className', 'current');
		
		if(div == 'recent-article'){
			$('#recent-article').fadeIn('fast');
			$('#featured-resources').fadeOut('fast');
		} else {
			$('#featured-resources').removeClass('hidden').fadeIn('fast');
			$('#recent-article').fadeOut('fast');
		}
		return false;
	});
	
	/* SERMON SORTING */		
	// see if there is something in the query string to initially load	
	$('#all-messages').click(function(){
		$('#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-->');
			//$('#primaryContent > h2').html(response[0]);
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('#current').hide();
			$('#all-messages').focus();
		    Logos.ReferenceTagging.lbsBibleVersion = "NIV";
		    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
		    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
		    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
		    Logos.ReferenceTagging.tag();
			
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		if(this.selectedIndex !== 0){
			$('#sermon-content').html('').css({height:'300px', background:'url(/images/ajax-loader.gif) no-repeat center center'});
			$.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]);
					$('#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');
				    Logos.ReferenceTagging.lbsBibleVersion = "NIV";
				    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
				    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
				    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
				    Logos.ReferenceTagging.tag();
					
				}
			);
		}
	});		
	/* END SERMON SORTING */
	
	$('.play').click(function(){
		var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=27&sermonid='+this.id.split('-')[1]+'&useSkin=skin_plain.xml&CMS_LINK=http://my.ekklesia360.com';
		wimpyPopPlayer(url,'wimpyMP3player','width=350,height=140,title=blah');
		return false;		 
	});
	
	$('.external').attr('target', '_blank');
	
	
});