

	$(document).ready(function() {
		
		// global search INIT
		jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
		};
		$("a#search_pull").click(function () { $("#searches").slideFadeToggle(100); $("input#keywords_people").focus(); return false; });
		$("a#search_close").click(function () { $("#searches").slideFadeToggle(100); return false; });
		$("ul#search_options").tabs("div#searches > div");
		$("a#select_keywords_people").click(function () {$("input#keywords_people").focus();});
		$("a#select_keywords_articles").click(function () {$("input#keywords_articles").focus();});
		
		$("#member_matrix img[title]").tooltip({ effect: "fade"});
		$("#team_lists li").click(function(){ window.location=$(this).find("a").attr("href"); return false; });
		$("#memberlist li").click(function(){ window.location=$(this).find("a").attr("href"); return false; });
		$(".member_action").click(function(){ window.location=$(this).find("a").attr("href"); return false; });
		
		$("a#show_members").click(function() {
			$("ul#members_list").slideToggle("fast");
			return false;
		});
		
		var _date = new Date();
        _date.setMonth(0);
        _date.setDate(1);
        _date.setHours(0);
        _date.setMinutes(0);
        _date.setSeconds(0);
        $('#counter').countdown({
            startTime: _date,
            stepTime: 1,
            digitImages: 6,
            digitWidth: 53,
            digitHeight: 77,
            image: "images/countdown/digits_transparent.png"
        });
	    
		
		//places image map highlite
		$('img[usemap]').maphilight({stroke: false});
		
		// image map links to submenu on people and places landing page 
		$(".al").hover(function () {$(".al").addClass("on");},function () {$(".al").removeClass("on");});
		$(".hr").hover(function () {$(".hr").addClass("on");},function () {$(".hr").removeClass("on");});
		$(".cz").hover(function () {$(".cz").addClass("on");},function () {$(".cz").removeClass("on");});
		$(".ee").hover(function () {$(".ee").addClass("on");},function () {$(".ee").removeClass("on");});
		$(".lv").hover(function () {$(".lv").addClass("on");},function () {$(".lv").removeClass("on");});
		$(".pl").hover(function () {$(".pl").addClass("on");},function () {$(".pl").removeClass("on");});
		$(".ro").hover(function () {$(".ro").addClass("on");},function () {$(".ro").removeClass("on");});
		$(".rs").hover(function () {$(".rs").addClass("on");},function () {$(".rs").removeClass("on");});
		$(".sk").hover(function () {$(".sk").addClass("on");},function () {$(".sk").removeClass("on");});
		$(".si").hover(function () {$(".si").addClass("on");},function () {$(".si").removeClass("on");});
		$(".ua").hover(function () {$(".ua").addClass("on");},function () {$(".ua").removeClass("on");});

		//billboard slider init
		$("#slides_nav").tabs("#slides > div", { 
				effect: 'fade',
				fadeOutSpeed: "slow",
				rotate: true
		    }).slideshow({
				interval: 5000,
				autoplay: true
			});
		
		// Events slider on home page
		$("#event_nav").tabs("#event_slider > div", { 
				effect: 'fade',
				fadeOutSpeed: "slow",
				rotate: true
		    }).slideshow({
				interval: 5000,
				autoplay: true
				// clickable: false,
				// autopause: false
			});

		// Older Vimeo overlay

		// $("a#video1[rel]").overlay({
		// 		mask: {
		// 			color: '#111',
		// 			loadSpeed: 200,
		// 			opacity: 0.9
		// 		},
		// 		closeOnClick: false,
		// 		top: '25%'
		// 	});

		// New vimeo overlay with stop video after clicking close
			$('a#video1').click(function() {
				$('#overlay').prepend('<div id="video_hold"><iframe src="http://player.vimeo.com/video/2551268?title=0&amp;byline=0&amp;portrait=0&amp;color=ff9933" width="504" height="284" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen ></iframe></div>');
			});
			$("a#video1[rel]").overlay({
				top: '25%',
				mask: {
					color: '#111',
					loadSpeed: 200,
					opacity:0.9
				}, 
				onClose: function() {$('#video_hold').remove();}
			});
			
				$('#overlay a.close').click(function() {$('#video_hold').remove();});
		
		// form validation
		$("#program").validate();
		$("#creditcard").validate();
		
		// Primary action Lift subscription
		$("#subscribe input").labelify({text: "label", labelledClass: "labelinside"});
		$(function () {
	        $('#subForm').submit(function (e) {
	            e.preventDefault();
	            $.getJSON(
	            this.action + "?callback=?",
	            $(this).serialize(),
	            function (data) {
	                if (data.Status === 400) {
	                    alert("Error: " + data.Message);
	                } else { // 200
						html();
	                }
	            });
	        });
	    });

		function html (){
			$("#subscribe").hide(); // If successfully submitted hides the form
			$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
		}

		// labels inside fieldes
		$("#autocomplete input").labelify({text: "label", labelledClass: "labelinside"});

		// Autocomplete init for give page search on members
	    $("input#autocomplete_box").autocomplete("/give/autocomplete",{
			cacheLength: 10,
			minChars: 2,
			delay: 5,
			// matchContains: true,
			formatItem: function (row) { return row[0] },
			formatResult: function (row){ return row[1] }
		}).result(function(event, item) {
			//redirect to the URL in the string
			window.location.href = 'https://www.josiahventure.com/give/people/'+item[1];
			$(this).css("color","#fff");
	    });

		// Diasble the FIND button on autocomplete form
		$("form#autocomplete button").click(function(){ return false; });
	
		// tabs for giving options
		$("ul#tabs").tabs("div#panes > div");
		$("#campaign ul#tabs").tabs("div#panes > div", {initialIndex: null});
		$("#campaign div.first").hide();
		$("a#hide_panel").click(function () { $("div#panes > div").hide(); return false; });
		
		// open external links in new tab
		$('a[rel="external"]').click(function(){$(this).attr('target','_blank');});
	});

	// Enabling Clickback Analytics and other settings for AddThis
	var addthis_config = { 
		data_track_clickback: true,
		ui_use_addressbook: true,
		ui_click: true
	 	};	
