/**
 * NAVIGATION TAB CONTROLS
 *		Controls the slide down/slide up effect of the navigation tabs.
 *		Also controls the appearance and hiding of the sub-navigation.
 */
$('.nav_item').hover(function() {
	$(this).animate({paddingTop: 10}, 250, function() {
		$(this).find('ul').fadeToggle('fast');
	});
}, function() {
	$(this).find('ul').fadeToggle('fast');
	$(this).animate({paddingTop: 0}, 250);
});

$('#footer_tab1 p a').hover(function() {
	$(this).animate({height: 255}, 250);
}, function() {
	$(this).animate({height: 245}, 250);
});

$('#footer_tab2 p a').hover(function() {
	$(this).animate({height: 255}, 250);
}, function() {
	$(this).animate({height: 245}, 250);
});



/**
 * HOME SLIDING PANE CONTROLS
 *		Controls the sliding of content when side buttons are pressed.
 */




/**
 * HOME AUTO SLIDING PANE CONTROLS
 *		Controls the sliding of content when side buttons are pressed.
 */
 
$(function(){
    $("#home_slides").slides({
    	generatePagination: false,
    	next: 'home_slider_r',
    	prev: 'home_slider_l',
    	play: 5000,
    	pause: 5000,
    	hoverPause: true
    });
  });




/**
 *	HOME ROTATING CONTENT BOX
 *		Controls the change of content in the home "Stay Connected" box.
 */
$('#tab1_link').click(function() {
	$('.details').css({'display': 'none'});
	$('#content_box_details').css({'background-color': '#858850', 'color': '#f9fdce'});
	$('#details1').css({'display': 'inline'});
	
	return false;
});

$('#tab2_link').click(function() {
	$('.details').css({'display': 'none'});
	$('#content_box_details').css({'background-color': '#999c69', 'color': '#f9fdce'});
	$('#details2').css({'display': 'inline'});
	
	return false;
});

$('#tab3_link').click(function() {
	$('.details').css({'display': 'none'});
	$('#content_box_details').css({'background-color': '#b8ba8f', 'color': '#565a24'});
	$('#details3').css({'display': 'inline'});
	
	return false;
});




/**
 * MEMBERS SLIDING PANE CONTROLS
 *		Controls the sliding of content when side buttons are pressed.
 */
$(function(){
    $("#member_slides").slides({
    	generatePagination: false,
    	paginationClass: 'members_slider_nav',
    	play: 5000,
    	pause: 5000,
    	hoverPause: true
    });
  });   




/**
 * FORM FIELD CLEARING
 *		Clears the form fields when that field has been focused on.
 */
$('#search_input').focus(function() {
	$(this).val('');
});

$('#sign_up_email').focus(function() {
	$(this).val('');
});

$('#sign_up_zip').focus(function() {
	$(this).val('');
});

$('.input').focus(function() {
	$(this).val('');
});








/**
 *	LIGHTBOX FUNCTION
 *		Function to control when a lightbox is called.
 */
function startOverlay(overlayLink) {
	// Add the lightbox containers to the page
	$("body")
		.append('<div class="overlay"></div><div class="container"></div>');
		//.css({"overflow-y":"hidden"});
	$(".overlay")
		.animate({"opacity":"0.6"}, 200, "linear")
		.css({
			"cursor":        "pointer"
		});
	
	// Place what html you want into the lightbox and style the container
	$(".container").html('<div id="popup_body"><div id="popup_close"><p>X</p></div><div id="popup_content"><form id="pu_form" method="post" action="/sign-up"><input type="hidden" name="data[DynamicFormSubmission][dynamic_form_id]" value="465" id="DynamicFormSubmissionDynamicFormId" /><input name="data[DynamicFormSubmission][email]" type="text" options="" legend="" separator="" value="EMAIL" id="pu_email" /><br /><input name="data[DynamicFormSubmission][postal_code]" type="text" options="" legend="" separator="" maxlength="5" value="ZIP Code" id="pu_zip" /><input id="pu_join" type="submit" name="submit" value="Submit"/></form></div></div>');
		
	$(".container")
				.css({
					"top":        "50%",
					"left":        "50%",
					"width":      "600px",
					"height":     "400px",
					"margin-top": -(480/2),
					"margin-left":-(640/2) //to position it in the middle
				})
				.animate({"opacity":"1"}, 200, "linear");
				
	// Remove the lightbox when the "x" or outside the box is clicked
	$(".overlay").click(function(){
		$(".container, .overlay")
		.animate({"opacity":"0"}, 200, "linear", function(){
			$(".container, .overlay").remove();
		})
	});
	
	$("#popup_close").click(function(){
		$(".container, .overlay")
		.animate({"opacity":"0"}, 200, "linear", function(){
			$(".container, .overlay").remove();
		})
	});
	
	
	
	
	// Clears the form fields when that field has been focused on
	$('#pu_email').focus(function() {
		$(this).val('');
	});
	
	$('#pu_zip').focus(function() {
		$(this).val('');
	});
	
	/*///////////////////////////////////////////////////////////////////////
	Ported to jquery from prototype by Joel Lisenby (joel.lisenby@gmail.com)
	http://joellisenby.com
	
	original prototype code by Aarron Walter (aarron@buildingfindablewebsites.com)
	http://buildingfindablewebsites.com
	
	Distrbuted under Creative Commons license
	http://creativecommons.org/licenses/by-sa/3.0/us/
	///////////////////////////////////////////////////////////////////////*/
	// Control what happens when the lightbox form is submitted
//	$('#pu_form').submit(function() {
		/**
		 *****************************************************************
		 * THIS CODE HAS NOT BEEN EDITED FOR THIS TEMPLATE, CUSTOM CODE MUST BE ADDED TO CONTROL FORM SUBMISSION!!!!!!!
		 *****************************************************************
		 */
	
//		var nwsltr_email = escape($('#newsletter_email').val());
	
		// update user interface
//		$('#popup_form_wrapper').css('color', '#0a5185');
//		$('#popup_form_wrapper').html('Adding email address...');
		
//		// Prepare query string and send AJAX request
//		$.ajax({
///			url: 'inc/store-address.php',
///			data: 'ajax=true&email=' + nwsltr_email,
///			success: function(msg) {
//				if (msg == 'Success! Check your email to confirm sign up.') {
///					$('#popup_form_wrapper').css('color', 'green');
//				} else {
//					$('#popup_form_wrapper').css('color', 'red');
//				}
//				$('#popup_form_wrapper').html(msg);
///			}
//		});
	
//		return false;
//	});
}

/**
 * LIGHTBOX CALL
 */
$(".lightbox").click(function(){
	overlayLink = $(this).attr("href");
	window.startOverlay(overlayLink);
	return false;
});





/**
 * SHARE BUTTON
 */
$(document).ready(function(){
    $().jshare({
    	jsharedir:	'/js/hcf.engagedev.com/jshare/',
    	iconsdir:	'/js/hcf.engagedev.com/jshare/images/icons/'
    });
});




/**
 * FIX WIDTH OF FACEBOOK BUTTONS
 */
$('.FB_UI_Hidden').css('width', '150px');

