// JavaScript Document

function initTopNav(){
	var opennav = false;
	var navHeight = $('#glbnav').height();
	$('#glbnav').height(27);
	$('#glbnav_wrapper').css('overflow','visible');
	$('#glbnav_wrapper').css('height','auto');
	$("#site_map").click(function(){
		if(opennav){
			$(this).css({'background-image' : 'url(/images/arrow_down.gif)'});
			$("#glbnav").animate({height:27}, 700);
			opennav = false;
		}else{
			$(this).css({'background-image' : 'url(/images/arrow_up.gif)'});
			$("#glbnav").animate({height:navHeight}, 700);
			opennav = true;
		}
	});
}

function initSideNav(){
	$('#subnav').children('li').each(function(i,elem){
		if($(elem).find('ul').length > 0){
			$(elem).attr('class', $(elem).attr('class') + ' parent');
		}
	});
}

function doSearch(e){
	if(isEnterKey(e)) $('#searchForm').submit();
}

function findAChurch(state){
	$('#fac_state').val(state);
	$('#findachurch').submit();
}

function initFindAChurchNav(){
	$('#fnav').children('li').hover(
		function(){
			$(this).attr('class', $(this).attr('class')+' sfhover');
		},
		function(){
			$(this).attr('class', $(this).attr('class').replace(' sfhover',''));
		}
	);
}

function initLightBox(){
	$(function(){
		$("a[rel='lightbox']").lightBox({
			imageLoading: '/images/lightbox-ico-loading.gif',
			imageBtnClose: '/images/lightbox-btn-close.gif',
			imageBtnPrev: '/images/lightbox-btn-prev.gif',
			imageBtnNext: '/images/lightbox-btn-next.gif',
			fixedNavigation: true
		});
	});
}

function initThickboxContent(){
	var contentBlocks = $('#text .thickbox_content');
	if(contentBlocks.length > 0){
		$('#text a.thickbox').each(function(i,elem){
			if(contentBlocks[i] != null){
				$(contentBlocks[i]).wrap('<div id="myTB'+i+'" class="thickbox_content"></div>');
				$(contentBlocks[i]).attr('class','');
				$(elem).attr('href','#TB_inline?height=300&width=450&inlineId=myTB'+i);
			}else{
				$(elem).attr('class','');
			}
		});
	}
}

function initPopupVideos(){
	$('a.popup_video').each(function(i,elem){
		var url = $(elem).attr('href');
		if(url.search('youtube.com')){
			url  = url.replace("watch?v=", "v/");
			url  = url.replace("&feature=player_embedded", "");
			url += '&autoplay=1';
			var embed = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
			embed += 'width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">';
			embed += '<param name="src" value="'+url+'" />';
			embed += '<embed type="application/x-shockwave-flash" width="425" height="350" src="'+url+'"></embed></object>';
			$(elem).fancybox({
				width				: 425,
				height				: 350,
				hideOnOverlayClick	: false,
				titleShow			: false,
				enableEscapeButton	: false,
				content				: embed
			});
		}
	});
}







