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

function playAudio(){
	var url = 'http://my.ekklesia360.com/Clients/sermonaudioplayer.php?CMSCODE=EKK&siteid=2962&sermonid='+this.id.split('sermon')[1]+'&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?sermonslug='+$(this).attr('rel'), 'videoPlayer', 'width=587,height=330,scrollbars=0,statusbar=0,address=0');
	return false;
}

function embedVideo(){
	
	
	// Video Embedding
	var vid = 1;
	$('.video').each(function(){
		var vurl = $(this).attr('onclick').toString();
		vurl = vurl.split('waspPopup')[1];
		vurl = vurl.split('\',')[0].replace('\'', '').replace('(', '');
		$(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 = {};
		var attributes = {};
		swfobject.embedSWF("/_js/player.swf", "video"+vid, "640", "480", "9.0.0", "/_js/expressInstall.swf", flashvars, params, attributes);		
		$(this).remove();								
		vid++;			
	});
	

}

$(document).ready(function() {
	actions();
	embedVideo();
	
	$('.external').click(function(){
		window.location = this.href;
		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();
		    actions();
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		$('#sermon-content').html('').css({height:'300px', background:'url(/_img/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-->');
					$('#content > h2').html(response[0]);
					$('#sermon-content').html(response[1]).css({height:'auto', background:'none'});			
					$('#current').hide();
					$('.sorter').attr({selectedIndex:0});		
					$('#all-messages').focus();
	    			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';
	});
	
});