function actions(){
	$('.sl_listen a').bind('click', playAudio);
	$('.sl_video a').bind('click', playVideo);
	$('.passage').bind('click', getPassage);
}

function getPassage(){
	var path = $(this).attr('href');
	window.open(path, 'ESV', 'width=500,height=500');
	return false;
}

function playAudio(){
	var id = $(this).attr('id').split('sermon')[1];
	var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2414&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(){
	waspPopup($(this).attr('href'), 330, 220);
	return false;
}

$(document).ready(function(){
	actions();
	
	// add children class to nav items with kids
	$('#nav li ul').parent().addClass('more');
	
	$('.external').attr('target','_blank');
	
	/* SERMON SORTING */		
	// see if there is something in the query string to initially load
	var sort = window.location.hash.replace('#', '');	
	
	if(sort){
		if(sort == 'all'){
			var group = 'all';
			var key = 'current';
			var val = 'current';
		} else {
			var group = sort.split('_')[0];
			var key = sort.split('_')[0];
			var val = sort.split('_')[1];
		}
		$('#sermon-content').html('').css({height:'300px', background:'url(/images/ajax-loader.gif) no-repeat center center'});
		$.get('/ajax-sermons.php', {
			'groupby':group,
			'key':key,
			'val':val
		},
		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 = "ESV";
		    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
		    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
		    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
		    Logos.ReferenceTagging.tag();
			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-->');
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('#current').hide();
			$('#all-messages').focus();
		    Logos.ReferenceTagging.lbsBibleVersion = "ESV";
		    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
		    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
		    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
		    Logos.ReferenceTagging.tag();
			actions();			
		}
		);
		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-->');
					$('#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();
					actions();	
				}
			);
		}
	});		
	/* END SERMON SORTING */
	
	$('.play').click(function(){
		var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2414&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;		 
	});
	
	$('#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';
	});
	
});