function actions(){
	$('.sl_listen a, #mb_jukebox a, .play').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=1926&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;		 
};

function playVideo(){
	window.open('/video.php?video='+$(this).attr('href'), 'videoPlayer', 'width=640,height=480,scrollbars=0,statusbar=0,address=0');
	return false;
}

$(document).ready(function(){
	actions();
	
// subnav deal
	if(id('snav')){
		var curs = getElementsByClassName(document.getElementById('snav'), 'li', 'current');
		var ULS = id('snav').getElementsByTagName('UL');
		var LIS = id('snav').getElementsByTagName('LI');		
		for(var i=0; i<LIS.length; i++){
			if(curs.length > 2) { // if there are more than 2 current items, the 2nd current item should also be an active item if it has children
				if(LIS[i] !== curs[0] && LIS[i].getElementsByTagName('UL')[0]) {
					LIS[i].className += ' active';
				}
			} else if(LIS[i].getElementsByTagName('UL')[0]) {
				if(LIS[i].className !== 'current') LIS[i].className = 'active';				
			}			
		}
	}

$('#all-messages').click(function(){
		$('#sermon-content').html('').css({height:'100px', 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();
			if($.browser.msie) $('#contact').css({position:'relative'});
			actions();
			
		}
		);
		return false;
	});
	
	$('.sorter').change(function(){
		if(this.selectedIndex != 0){
			$('#sermon-content').html('').css({height:'100px', background:'url(/images/ajax-loader.gif) no-repeat center center'});
			
			$.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();
					
					if($.browser.msie) $('#contact').css({position:'relative'});
					
					// reset sorter selects to first value
					$('.sorter').attr({selectedIndex:0});		
					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');
});



function id() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com

*/

function getElementsByClassName(oElm, strTagName, strClassName){	
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");	
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }	
    return (arrReturnElements)
}