$(document).ready(function() {
	/* Check Some Form Checkboxes by Default */
	$("input#c_16400_505729, input#c_15795_505116, input#c_15942_505208").attr('checked', true);
	
	/* Home Page Expandable Promotion and Cookie */
	$(function() {
		if ($.cookie("agpromotion")) {
			$("#home-promotion").hide();
		} else {
			$("#home-promotion").show();
		}
	});
	$("#home-promotion a#promotion-close").click(function() {
		$("#home-promotion").slideToggle("fast");
		$.cookie("agpromotion", "agpromotion", { expires: 1, path:'/'});
		return false;
	});
     
  /* Text Resizing */
	$(function() {
  	cookieResize('#text-resize a', 'normal');
  });
  
  /* Overview Slideshow */
  $('#content #main-column #overview-video #slideshow').cycle('fade');
      
  /*Adds target blank attr to external links*/
	$("a[class=external-link]").attr('target','_blank');
	$("a[class=button-external]").attr('target','_blank');
	$("a[class=buttonleft-external]").attr('target','_blank');
	
	/* Remove Nav Elements */
	$("ul#navigation li#navigation_customer-care--contact").remove();
	$("ul#navigation li#navigation_about").remove();
	
	/* Home Page Navigation Slide Down */
	$("ul#navigation li ul").hover(function() {
		$(this).parent().addClass("hoverstate"); 
			}, function() {
		$(this).parent().removeClass("hoverstate"); 
	});

	/*$("#navigation li ul").css({"height" : "0px"});
	$("#navigation li#navigation_connect").hover(function() {
		$("#navigation li#navigation_connect ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_investments").hover(function() {
		$("#navigation li#navigation_investments ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_church-loans").hover(function() {
		$("#navigation li#navigation_church-loans ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_retirement-planning").hover(function() {
		$("#navigation li#navigation_retirement-planning ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_stewardship-campaigns").hover(function() {
		$("#navigation li#navigation_stewardship-campaigns ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_planned-giving").hover(function() {
		$("#navigation li#navigation_planned-giving ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});
	$("#navigation li#navigation_insurance").hover(function() {
		$("#navigation li#navigation_insurance ul").animate({"height": "30px"}, "normal"); 
			}, function() {
		$("#navigation li ul").css({"height" : "0px", "display" : "none"});
	});*/

	/* Subnav Remove Last Divider */
	$("ul#sub-navigation li:last").css({'background' : 'none'});
	$("ul#navigation li ul li:last-child").css({'background' : 'none'});
	
	/* Show/Hide Side Navigation Nested Lists */
	//$("ul#side-navigation li ul").hide();
	//$("ul#side-navigation li.current ul").show();
	
	/* Hide Last Module Border */
	$("#sidebar .module:last").css({'border' : 'none'});
	$("#main-column .module:last-child").css({'border' : 'none'});
	
	/* Forms Right Column Float */
	$("form#loan-inquiry-form .text:odd").css({'float' : 'right', 'margin-right' : '2px'});
	$("form#loan-inquiry-form #w8545.text").css({'margin-left' : '22px', 'margin-right' : '2px'});
	$("form#loan-inquiry-form #w8546.text").css({'float' : 'left', 'margin-right' : '2px'});
	$("form#retirement-packets .text:odd").css({'float' : 'right', 'margin-right' : '2px'});
	$("form#schedule-educational-staff-workshop .text:odd").css({'float' : 'right', 'margin-right' : '2px'});
	$("form#webinar-signup .text:odd").css({'float' : 'right', 'margin-right' : '2px'});
	$("form#request-a-quote .text:odd").css({'float' : 'right', 'margin-right' : '2px'});
	$("#content #main-column form#application .radio legend").wrapInner("<span></span>");
	
	/* Search Show and Hide */
	$("a#search").addClass("inactive");
	$("form#searchForm").hide();
	$("a#search-close").hide();
	$("a#search").click(function() {
		$("a#search").toggleClass("inactive");
		$("form#searchForm").toggle("fast");
		$("a#search-close").toggle("fast");
		return false;
	});
	$("a#search-close").click(function() {
		$("a#search").toggleClass("inactive");
		$("form#searchForm").toggle("fast");
		$("a#search-close").toggle("fast");
		return false;
	});
	/*Adds current class to blogs and secondary nav*/
	if (window.location.toString().match(new RegExp('/investments-blog/'))) {
      $('#navigation li#navigation_investments').addClass('current');}
      if (window.location.toString().match(new RegExp('/insurance-blog/'))) {
      $('#navigation li#navigation_insurance').addClass('current');}
  if (window.location.toString().match(new RegExp('/connect-blog/'))) {
      $('#navigation li#navigation_connect').addClass('current');}
  if (window.location.toString().match(new RegExp('/church-loans-blog/'))) {
      $('#navigation li#navigation_church-loans').addClass('current');}
  if (window.location.toString().match(new RegExp('/stewardship-campaigns-blog/'))) {
      $('#navigation li#navigation_stewardship-campaigns').addClass('current');}	
  if (window.location.toString().match(new RegExp('/customer-care--contact/'))) {
      $('#secondary-navigation li:first').addClass('current');}	
  if (window.location.toString().match(new RegExp('/about/'))) {
      $('#secondary-navigation li:last').addClass('current');}	
	
	/* Search Default Value */
	$("#search_term").val('');
	$("#search_term").defaultValue('Keyword Search');
	
	/* Tabs */
	$("#tabs").tabs({ fx: { opacity: 'toggle', duration: 150 } });
	var $tabs = $('#tabs').tabs(); // first tab selected
	$('.tab1').click(function() { // bind click event to link
    $tabs.tabs('select', 0); // switch to third tab
    return false;
	});
	$('.tab2').click(function() { // bind click event to link
    $tabs.tabs('select', 1); // switch to third tab
    return false;
	});
	$('.tab3').click(function() { // bind click event to link
    $tabs.tabs('select', 2); // switch to third tab
    return false;
	});
	$('.tab4').click(function() { // bind click event to link
    $tabs.tabs('select', 3); // switch to third tab
    return false;
	});
	$('.tab5').click(function() { // bind click event to link
    $tabs.tabs('select', 4); // switch to third tab
    return false;
	});
	
	/* Show Blog Slider */
	$("#content #main-column h3#blog-list-header").css({'display' : 'block'});
	$("#content #main-column #blog-list").css({'display' : 'block'});
	var location_regex = /^\/connect-blog\/(.+)$/;
	var location_matches = window.location.pathname.match(location_regex);
	if (window.location.pathname != '/connect-blog' && (location_matches && location_matches.length > 0)) {
  	$("#content #main-column h3#blog-list-header").hide();
  	$("#content #main-column #blog-list").remove();
	};
	
	/* Show Video Slider */
	$("#content #main-column #video-list").css({'display' : 'block'});
	
	/* Video and Blog Scroll Feature */
	$(".video-container").hide();
	$(".video-container:first").show();
	$("#video-list li a").click(function() {
		var index = $("#video-list li a").index(this);
		$(".video-container").hide();
		$(".video-container").eq(index/2).show();
		return false;
	});

  $('#video-list').jcarousel({
  	scroll: 5
  });
  
  $('#blog-list').jcarousel({
  	scroll: 4
  });
    
  /* FAQ */
  $("#main-column .answer").hide();
  $("#main-column .answer a.button").css({'color' : '#5c5c5c'});
	$("#main-column .question a.button").toggle(function() {
			$("#main-column .question a.button").html("Answer &raquo;").css({'color' : '#65af38'});
			$(this).html("Close X").css({'color' : '#5c5c5c'});
			$("#main-column .answer").hide();
			$(this).parent().parent().next(".answer").show();
				}, function () {
			$("#main-column .question a.button").html("Answer &raquo;").css({'color' : '#65af38'});
			$("#main-column .answer").hide();
			return false;
	});
	$("#main-column .answer a.button").click(function() {
		$("#main-column .question a.button").html("Answer &raquo;").css({'color' : '#65af38'});
		$("#main-column .answer").hide();
		return false;
	});
	
	/* Team and More Expandable */
	/*setInterval(function() {
    $("#main-column .team-description").hide();
    $("#main-column .team-intro h4#" + document.location.hash).parent().next(".team-description").show();
  }, 300);*/
  
  $("#main-column .team-description").hide();
	$("#main-column .team-intro a.button").toggle(function() {
			$(this).html("Close &raquo;").css({'color' : '#5c5c5c'});
			$(this).parent().parent().next(".team-description").show();
				}, function () {
			$(this).html("Bio &raquo;").css({'color' : '#65af38'});
			$(this).parent().parent().next(".team-description").hide();
			return false;
	});
	
	$("#main-column .team-intro-small a.button").toggle(function() {
			$(this).html("Close &raquo;").css({'color' : '#5c5c5c'});
			$(this).parent().parent().next(".team-description").show();
				}, function () {
			$(this).html("Bio &raquo;").css({'color' : '#65af38'});
			$(this).parent().parent().next(".team-description").hide();
			return false;
	});
	$("#main-column .more-description").hide();
	$("#main-column .more-intro a.button").toggle(function() {
			$(this).html("Close &raquo;").css({'color' : '#5c5c5c'});
			$(this).parent().parent().next(".more-description").show();
				}, function () {
			$(this).html("More &raquo;").css({'color' : '#65af38'});
			$(this).parent().parent().next(".more-description").hide();
			return false;
	});
	
	$("#main-column .success-description").hide();
	$("#main-column .success-intro a.button").toggle(function() {
			$(this).html("Close &raquo;").css({'color' : '#5c5c5c'});
			$(this).parent().parent().next(".success-description").show();
				}, function () {
			$(this).html("More &raquo;").css({'color' : '#65af38'});
			$(this).parent().parent().next(".success-description").hide();
			return false;
	});
	
	/* Calculators Lightbox */
	$(".iframe").fancybox({
    'centerOnScroll': false,
		'frameWidth': 670,
    'frameHeight': 500
	});
	
	/* Connect Overview Map Lightbox */
	$("a#map").fancybox({
    'centerOnScroll': false,
		'frameWidth': 425,
    'frameHeight': 350
	});
	
	/* Survey Lightbox */
	$("a#survey").fancybox({
    'centerOnScroll': false,
		'frameWidth': 760,
    'frameHeight': 500
	});
	
	/* Flip Through */
	$("a.flipthrough").fancybox({
    'centerOnScroll': false,
		'frameWidth': 760,
    'frameHeight': 500
	});
	
	/* Investment Form Agreement */
	$("a#investment-form").hide();
	$("a.investment-form").hide();
	$("form#offering-circular-form input").change(function() {
		if ($(this).is(":checked")) {
			$("p#circular-agree").hide();
			$("p.circular-agree").hide();
			$("a#investment-form").show();
			$("a.investment-form").show();
		} else {
      $("p#circular-agree").show();
      $("p.circular-agree").show();
			$("a#investment-form").hide();
			$("a.investment-form").hide();
		}
	});
	
	/*SWFobject Variables*/
	var flashvars = {}
	var params = { 
		base: ".",
		allowfullscreen: "true",
		wmode: "opaque"
	}              
	var attributes = {}
	/*SWFObject Map*/
	swfobject.embedSWF("/media/map/usa_locator.swf?xmlfile1=church-loans.xml", "map-church-loans", "700", "410", "7.0.0", false, flashvars, params, attributes);
	swfobject.embedSWF("/media/map/usa_locator.swf?xmlfile1=retirement-planning.xml", "map-retirement-planning", "700", "410", "7.0.0", false, flashvars, params, attributes);
	swfobject.embedSWF("/media/map/usa_locator.swf?xmlfile1=planned-giving.xml", "map-planned-giving", "700", "410", "7.0.0", false, flashvars, params, attributes);
	
	/*Home Intro*/
	swfobject.embedSWF("/media/home-intro.swf", "home-intro", "580", "326", "9.0.0", false, flashvars, params, attributes);
	
});


// Navigation Script
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("navigation");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList

