/*
Author: Joe Tan (joetan54@gmail.com)
*/
jQuery(function($) {
	$('input[type=text]:not(.noclear), textarea:not(.noclear)').focus(function() {
		if ($(this).attr('defaultValue') == $(this).val()) $(this).val('')
	}).blur(function() {
		if ($(this).val() == '') { $(this).val($(this).attr('defaultValue'))}
	});
	
	$('blockquote p:has(img)').addClass('img');
	$('.wp-caption.alignleft + p').css({clear:'both'})
});

// add thickbox popup overlays
var tb_pathToImage = "/wp-includes/js/thickbox/loadingAnimation.gif";
var tb_closeImage = "/wp-includes/js/thickbox/tb-close.png";
jQuery(function($) { 
	if (typeof tb_init != 'function') return;


	tb_init(".popup");
	
	$('a[href*=integration.fellowshipone.com]:not(.thickbox)').each(function(i,obj) {
		if ($(this).attr('target')) return true;
		
		if (noPopUp($(this).attr('href'))) {
			$(this).attr('href', $(this).attr('href')+'&TB_iframe=true&height=600&width=800');
			tb_init(this);
		} else {
			$(this).attr('target', '_blank');
		}
	});
	
	// disable thickbox overlays if browser window is too small
	var dimensions = {width: 10000, height: 10000};
	if (window.innerWidth && window.innerHeight) {
		dimensions.width = window.innerWidth;
		dimensions.height = window.innerHeight;
	} 

	if ((dimensions.width < 800) || (dimensions.height < 600) ) {
		$('a.popup, a.thickbox').unbind('click').bind('click', function() {
			var w = window.open($(this).attr('href'), '_blank');
			w.focus();
			return false;
		});
		
	}
	
});
function noPopUp(href) {
	var list = ['activityfinder', 'smallgroup']
	
	for (var i=0;i<list.length;i++) {
		if (href.indexOf(list[i]) >= 0) return true;
	}
}


// header quick links
jQuery(function($) {
	$('.quicklinks').hover(function() {
		$('.quicklinks ul').slideDown(200);
	}, function() {
		$('.quicklinks ul').slideUp(100);
	})
});


// feedback widget
jQuery(function($) {
	$('#feedback label, #feedback a.close').click(function() {
		if ($('#feedback').width() > 30) {
			$('#feedback').animate({width:'30px'}, 100).find('.inner').animate({height:'85px'}, 100);;
		} else {
			$('#feedback').animate({width:'300px'}, 200).find('.inner').animate({height:'200px'}, 100);
		}
	})
	window.cforms_validate_orig = window.cforms_validate;
	window.cforms_validate = function(a,b) {
		setTimeout(checkFeedbackStatus, 5000);
		return window.cforms_validate_orig(a,b);
	}
	$('#feedback form').submit(function() {
		console.log('submitted');
		//return false;
	});
});
function checkFeedbackStatus() {
	var $ = jQuery;
	if ($('#feedback #usermessage2a').hasClass('success')) {
		$('#feedback label, #feedback a.close').click();
	}
}


// newsletter signup
jQuery(function($) {
	$('form.newsletter').submit(function() {
		var data = $(this).serialize();
		$(this).html('<div class="thankyou">Please wait...</div>');
		$.post('/wp-content/themes/newlife/mailchimp/store-address.php', data, function(data) {
			$('form.newsletter').html('<div class="thankyou">'+data+'</div>');
		}, 'html');

		return false;
	});
});


// expanding text widget
/*
jQuery(function($) {
	var curr = 0;
	$('#content > *').each(function(i, obj) {
		if ($(obj).hasClass('expand')) {
			if (curr > 0) $(obj).before('<p><a href="#" class="content-'+curr+' more expandable" contentID="'+curr+'">expand [+]</a></p>')

			if ($(obj).nextAll().length > 1) {
				curr = i;
				$(obj).attr('contentID', curr);
				$(obj).addClass('expandable');
			}
			$(obj).next().addClass('first');
		} else if ($(obj).hasClass('stop')) {
			if (curr > 0) $(obj).before('<p><a href="#" class="content-'+curr+' more expandable" contentID="'+curr+'">expand [+]</a></p>')

			curr = 0;
		} else if (curr > 0) {
			if (!$(obj).hasClass('first') ) $(obj).hide();
		}
		
		$(obj).addClass('content-'+curr);
		
	});
	if (curr > 0) {
		$('#content').append('<p><a href="#" class="content-'+curr+' more expandable" contentID="'+curr+'">expand [+]</a></p>')
	}
	$('#content .expandable').click(function() {
		var contentID = '.content-' + $(this).attr('contentID');
		$(this).toggleClass('expanded')
		if ($(this).hasClass('expanded')) {
			$(contentID+':not(.expand)').show(300);
			$(contentID+'.more').html('[hide]');
		} else {
			$(contentID+':not(.expand, .first, .more)').hide(300);
			$(contentID+'.more').html('expand [+]');
		}
		
		return false;
	});

});
*/