function actions(){
	$('.sl_listen a, #mb_jukebox a').bind('click', playAudio);
	$('.sl_video a, #mb_video a').bind('click', playVideo);	
}

function playAudio(){
   var id = $(this).attr('id').split('-')[1];
	var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2206&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(){
	window.open('/video.php?video='+$(this).attr('href'), 'videoPlayer', 'width=640,height=480,scrollbars=0,statusbar=0,address=0');
	return false;
}


document.write('<div id="traildiv"></div>');
function navHover(){		
	var lis = document.getElementById('nav').getElementsByTagName('LI');
	
	for(var i=0; i<lis.length; i++){
		lis[i].onmouseover = function(){		
			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].className ='';
		}		
	}
}
$(document).ready(function(){
	navHover();
	actions();
	
	// Video Embedding
	if($('.embed')){
		var vid = 1;
		$('.embed').each(function(){
			
			$(this).before('<div id="video'+vid+'"></div>');
			var url = $(this).attr('onClick').split(',')[0].replace('waspPopup(\'', '').replace('\'','');			
			$(this).remove();			
			var the_video = 's'+vid;					
			var the_video = new SWFObject('/js/player.swf','player','480','240','9');						
			the_video.addParam('allowfullscreen','true');
			the_video.addParam('allowscriptaccess','always');
			the_video.addParam('flashvars','file='+url+'&autostart=false&frontcolor=ffffff&lightcolor=cc9900&skin=http://www.longtailvideo.com/jw/upload/overlay.swf&controlbar=over');
			the_video.write('video'+vid);			
			vid++;			
		});
	}
	
	
	$('.external').attr('target', '_blank');
	
	$('a.play').click(function(){
		var id = this.id.split('-')[1];
		var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2206&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').css({height:'300px', background:'url(/images/ajax_loader.gif) no-repeat center center'}).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({background:'none', height:'auto'});			
			$('#current').hide();
			$('#loading').hide();
			$('.sorter').attr({selectedIndex:0});		
    		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(){
		if(this.selectedIndex != 0){
			$('#sermon-content').css({height:'300px', background:'url(/images/ajax_loader.gif) no-repeat center center'}).html('');
			$.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();
					$('#loading').hide();
					$('.sorter').attr({selectedIndex:0});		
				    Logos.ReferenceTagging.lbsBibleVersion = "ESV";
				    Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;
				    Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";
				    Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ];
				    Logos.ReferenceTagging.tag();
					
				}
			);
		}
	});		

	$('#articleLists').onchange = 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';
	}

});

	

