/*-------------------------------------------------------------------------------------------------*
 *  Berean Baptist by AM Design
 *
 *  JavaScript functions for the "Berean Baptist" theme by AM Design, built for the AM Design Content Management 
 *	System
 *
 *  Last Updated:  5/2011
 *  Updated By:  Jake Thompson
 *-------------------------------------------------------------------------------------------------*/

/* Global Variables */
var timeouts = [];

function init_site(){
	clearClick();
	css_tweaks();
	setBrowserClass();
	init_search();
	init_map();
	
	$("#sidebar_popups a:eq(0)").addClass("red_sidebar_btn");
	$("#sidebar_popups a:eq(1)").addClass("gold_sidebar_btn");
	$("#sidebar_popups a:eq(2)").addClass("teal_sidebar_btn");
	
	$("#sidebar_popups a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'hideOnOverlayClick'	: false,
		'hideOnContentClick'	: false,
		'type'			: 'iframe',
		'titleShow'		: false,
		'width'			: 940,
		'height'		: 450,
		'overlayColor'	: '#191614',
		'overlayOpacity': 0.85,
		'onComplete'	: function(){Cufon.replace('#popup_content .title', { fontFamily:'HelveticaNeueHeavy', hover:true });}
	});
	
	if(!hasFlash) {
		var nav = $("#flash_nav").html();
		$("#navigation").append( nav );
	}
	
	
	// dropdown menus
	$('#nav li').mouseenter(function() {
		showingMenu = true;
		$(this).children('ul').show();	
	}).mouseleave(function(){
		showingMenu = false;
		$(this).children('ul').hide();
		
	});
	
	
	

	
}

var showingMenu = false;

// from flash dropdown menus
// pass the y coordinate and <li> id
function showDropdownMenu(y, id) {
	$("#flash_nav").css( {"top":(y + 10)+"px"} );
	$('#flash_nav #'+id+' > ul').show();
}
function hideDropdownMenu(id) {
	if(!showingMenu) {
		$('#flash_nav #'+id+' > ul').hide();
	}
}

function css_tweaks(){
	$('#logo_divider').css("opacity", .5);
	$('#nav li ul li:last-child a').css('line-height', '35px');
}

function init_search(){
	$("#search_button").click(function(event){
		event.preventDefault();
		$('#search_popout').show();
		$('#map_popup').hide();
	});
	
	$("#search_form #keywords_label").click(function(){
		$(this).hide();
	});
	
	$("#search_form #keywords").blur(function(){
		if($(this).val() == "") $("#search_form #keywords_label").show();
	});
	
	$('#search_popout #search_close').click(function(event) {
		event.preventDefault();
		$('#search_popout').hide();
	});
}

function init_map(){
	$("#map_button").toggle(
	function(event){
		event.preventDefault();
		$('#map_popup').show();
		$('#search_popout').hide();
	},
	function(event){
		event.preventDefault();
		$('#map_popup').hide();
	});
	
	$("#direction_search label").click(function(){
		$(this).hide();
	});
	
	$("#direction_search #maps_keywords").blur(function(){
		if($(this).val() == "") $("#direction_search label").show();
	});
}



function showCTA() {
	$.fancybox({
		//'orig'			: $(this),
		'padding'		: 0,
		'href'			: 'http://berean.amdesign.com/am-site/media/home-gallery-test-image-1.jpg',
		'title'   		: 'Lorem ipsum dolor sit amet',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});	
}

function showPopup(slug) {
	$("#"+slug+"").trigger("click");
}





