
$(document).ready(function(){
/*
	if(document.getElementById('home')){
		var curs = $('#snav li.current');
		var ULS = ('snav').getElementsByTagName('UL');
		var LIS = id('snav').getElementsByTagName('LI');		
		for(var i=0; i<LIS.length; i++){
			if(curs.length > 2) { 
				if(LIS[i] == curs[1] && LIS[i].getElementsByTagName('UL')[0]) {
					LIS[i].className += ' active';
				}
			} else if(LIS[i].getElementsByTagName('UL')[0]) {
				if(LIS[i].className !== 'current') LIS[i].className = 'active';				
				LIS[i].firstChild.onclick = function(){
					var self = this;
					if(this.parentNode == curs[0]){ 
						window.location = this.href;
					} else {
						this.style.backgroundImage = 'url(/images/down_arrow.gif)';
					}
					
					this.parentNode.getElementsByTagName('UL')[0].style.display = 'block';
					self.onclick = function(){
						window.location = self.href;
					}
					return false;
				}
			}
		}
	}
	*/

	$('.external').click(function(){
		window.location = this.href;
		return false;
	});
	
	$('a.play').click(function(){
		var id = this.id.split('-')[1];
		var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=1497&sermonid='+id+'&useSkin=skin_plain.xml&CMS_LINK=http://my.ekklesia360.com';
		window.open(url, 'wimpyMP3player','width=350,height=140,title=blah')
		return false;
	});
		
	$('#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-->');
			$('#mainContent > h2').html(response[0]);
			$('#sermon-content').html(response[1]);			
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('#current').hide();
			$('.sorter').attr({selectedIndex:0});		
			$('#all-messages').focus();
		    Logos.ReferenceTagging.lbsBibleVersion = "ESV";
		    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
		    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
		    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
		    Logos.ReferenceTagging.tag();
		}
		);
		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-->');
					$('#mainContent > h2').html(response[0]);
					$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
					$('#current').hide();
					$('.sorter').attr({selectedIndex:0});		
					$('#all-messages').focus();
				    Logos.ReferenceTagging.lbsBibleVersion = "ESV";
				    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
				    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
				    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
				    Logos.ReferenceTagging.tag();					
				}
			);
		}
	});		
	
	$('#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';
	});
	
});