$(document).ready(function(){
	// 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 = { wmode:'transparent' };
		var attributes = {  };
		
		if($(this).find('img').attr('src')){
			flashvars.image = $(this).find('img').attr('src');
		}
		swfobject.embedSWF("/js/player.swf", "video"+vid, "480", "340", "9.0.0", "/js/expressInstall.swf", flashvars, params, attributes);		
		$(this).remove();								
		vid++;			
	});
	
	$('.external').attr('target', '_blank');
	
	$('#sermonLists').change(function(){
		if(this.selectedIndex == 1) window.location = '/mcms_page_sermonlist_sort.php?groupby=series';
		if(this.selectedIndex == 2) window.location = '/mcms_page_sermonlist_sort.php?groupby=category';
		if(this.selectedIndex == 3) window.location = '/mcms_page_sermonlist_sort.php?groupby=month';
		if(this.selectedIndex == 4) window.location = '/mcms_page_sermonlist_sort.php?groupby=preacher';	
	});
	
	navHover();
});



function navHover(){		
	var lis = $('#nav 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 = '0px';
				ul.style.top = '50px';
				//this.className = 'current';
			}
			
			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';
					}
				}
			}
		}
		
	}
}