document.write('<div id="traildiv"></div>');

function actions(){
	$('.play, #mb_jukebox a').click(function(){
		var id = $(this).attr('id').split('-')[1];
		var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2313&sermonid='+id+'&useSkin=skin_plain.xml&CMS_LINK=http://my.ekklesia360.com';
		window.open(url, 'wimpyMP3player','width=350,height=140,title=blah')
		return false;
	});	
}

$(document).ready(function(){
	actions();
	
	$('#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-->');
			//$('#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();
			actions();
			
			// put the focus on the sidebar image
			$('#sidebar a img').focus();
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		window.location.hash = this.id+'_'+this.value;
		$('#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-->');
					//$('#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');					
					$('#sidebar a img').focus();					
				    Logos.ReferenceTagging.lbsBibleVersion = "NIV";
				    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
				    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
				    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
				    Logos.ReferenceTagging.tag();
					actions();
				}
			);
		}
	});		
	


	
	$('#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';	
	});	
	
	$('.external').attr('target', '_blank');
	
	$('#tabs li a').click(function(){
		// remove active from both tabs
		$('#tabs li').removeClass('active');
		
		// add active to active tab
		$(this).parent().addClass('active');
		
		// get div based on links rel attribute
		var div = '#'+$(this).attr('rel')+'-tab';
		
		// slide toggle the tabs
		$('.tabbed').slideToggle('slow');
		return false;
	});
	
	navHover();
});

function navHover(){		
	var lis = document.getElementById('nav').getElementsByTagName('LI');
	
	for(var i=0; i<lis.length; i++){
		lis[i].onmouseover = function(){		
			if(this == lis[0]) this.firstChild.style.background = 'url(/images/nav_first_current.jpg) no-repeat left top';		
			this.className = 'current';
			
			if(this.getElementsByTagName('UL')[0]){
				var ul = this.getElementsByTagName('UL')[0];
				ul.style.left = '18px';
				ul.style.top = '33px';
			}
			
			for(var a=0; a<lis.length; a++){				
				if(lis[a] != this) { 
					lis[a].className = '';
					if(lis[a].getElementsByTagName('UL')[0]){
						lis[a].getElementsByTagName('UL')[0].style.left = '-999em';
					}
				}
			}
		}
		
		lis[i].onmouseout = function(){
			lis[0].firstChild.style.background = 'url(/images/nav_first_bg.jpg) no-repeat left top';
			lis[0].className ='';
		}		
	}
}

