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

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

function playVideo(){
	waspPopup($(this).attr('href'), 320, 240);
	return false;
}

$(document).ready(function(){
	actions();
	
	/*
	$('#nav li a').each(function(){
		if($(this).parent().parent().attr('id') == 'nav'){
			$(this).wrap('<div></div>');
		}
	});	
	*/
	
	$('#footer form').attr('target', '_blank');
	
	$('.external').attr('target', '_blank');
		
	$('#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-->');
			$('#sermon-content').html(response[1]);			
			$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
			$('.sorter').attr({selectedIndex:0});		
			$('#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();		
		}
		);
		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-->');
					$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
					$('.sorter').attr({selectedIndex:0});		
					$('#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();
				}
			);
		}
	});		
	
	$('#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';
	});	
	
	// Video Embedding
   var vid = 1;
   $('.video').each(function(){
   	var vurl = $(this).attr('href');
   	console.log(vurl);
   	$(this).before('<div id="video'+vid+'">'+vurl+'</div>');		
   	$(this).remove();

   	var flashvars = { 
   		file: vurl,
   		autostart:'false',
   		frontcolor: 'ffffff',
   		lightcolor: 'cc9900',
   		skin: 'http://www.longtailvideo.com/jw/upload/overlay.swf',
   		controlbar: 'over'
   	};

   	var params = { wmode:'transparent' };
   	var attributes = {  };

   	if($(this).find('img').attr('src')){
   		flashvars.image = $(this).find('img').attr('src');
   	}
   	swfobject.embedSWF("/js/player.swf", "video"+vid, "620", "440", "9.0.0", "/_js/expressInstall.swf", flashvars, params, attributes);		
   	$(this).remove();								
   	vid++;			
   });
   
});