$(function() {
	
	if ($('.featured-resources').length > 0) {
		var max_h = 0;
		$('.featured-resources > ul > li').each(function() {
			if (max_h < $(this).height()) {
				max_h = $(this).height();
			}
		});
		$('.featured-resources > ul > li').height(max_h + 50);
	}
	
	var frh_max = 0;
	$('ul#featured-resources-home > li').each(function() {
		if (frh_max < $(this).height()) {
			frh_max = $(this).height();
		}
	});
	
	$('#featured-resources-home-wrapper').height(frh_max + 30);
	$('#featured-resources-home').height(frh_max + 30);
	
	var rrh = $('#resources-right').height(), cah = $('#content-area').height();

	if (rrh > cah) {
		$('#content-area').height(rrh);
	} else {
		$('#resources-right').height(cah);
	}
	
	var cph = $('#content-panel').height(), rph = $('#right-panel').height(), ppt_h = $('#popular-prayer-topics').height();
	
	var height_increment = 30;
	if ($('#resource-topbar').length > 0) {
		height_increment = 0;
	}
	
	if (cph > rph) {
		$('#popular-prayer-topics').height(ppt_h + (cph - rph) + height_increment);
	} else {
		$('#content-panel').height(rph + height_increment);
	}
	
	var resource_topbar_h = 5;
	if (document.getElementById('resource-topbar')) {
		resource_topbar_h = 36;
	}
	
	$('#resources-right').height( $('#content-area').height() + resource_topbar_h);
	
	$('#ad-panel > ul').innerfade({ speed: 2000, timeout: 10 * 1000, type: 'sequence'});
	
	$('.message-close').click(function() {
		$('.message-close').parent().remove();
		return false;
	});
	
	$('a.lightbox').lightBox({fixedNavigation:true});
	
	$('input:submit,input:reset').addClass('btn');
	
	$('#inner-search-field').focus(function() {
		var value = $(this).val(), default_value = $(this).attr('default_value');
		
		if (value == default_value) {
			$(this).val('');
		}
	}).blur(function() {
		var value = $(this).val(), default_value = $(this).attr('default_value');
		
		if (value == '') {
			$(this).val( default_value );
		}
	});
	
	$('#query').focus(function() {
		var value = $(this).val();
		
		if (value == "Search") {
			$(this).val('');
		}
		
	}).blur(function() {
		var value = $(this).val();
		
		if (value == "") {
			$(this).val('Search');
		}
	});
	
	$('#customer_email,#customer_forgotpassword_email').focus(function() {
		var value = $(this).val();
		
		if (value == "Email Address") {
			$(this).val('');
		}
		
	}).blur(function() {
		var value = $(this).val();
		
		if (value == "") {
			$(this).val('Email Address');
		}
	});
	
	$('.validate-form').each(function() {
		$(this).validate();
	});
	
	$('#featured-article-images > li:gt(0)').hide();
	$('#featured-article-title-articles > li:gt(0)').hide();
	
	$('#featured-article-dots a').click(function() {
		//clearInterval(featured_articles_animation_interval);
		featured_articles_animation( $(this).parent().index('#featured-article-dots li') );
		return false;
	});
	
});


var featured_articles_animation_index = 0;
var featured_articles_animation_interval = setInterval('featured_articles_animation()', 5000);

function featured_articles_animation(overwrite_index)
{
	var total_images = $('#featured-article-images li').length;
	var visible_image_index = $('#featured-article-dots li').index( $('#featured-article-dots li.active') );
	var next_image_index;
	
	//alert( $('#featured-article-images li').index ( $('#featured-article-images li:visible') ) );
	
	$('#featured-article-images li:visible').siblings().hide();
	$('#featured-article-title-articles li:visible').siblings().hide();
	
	if ((visible_image_index + 1) < total_images) {
		next_image_index = visible_image_index + 1;
	} else {
		next_image_index = 0;
	}
	
	featured_articles_animation_index = !isNaN(overwrite_index) ? overwrite_index : next_image_index;
	
	$('#featured-article-title-articles > li:visible a').animate({
															 	'width': 0,
																'padding-right': 0
															 }, 1000, function() {
																 
																 $(this).parent().hide();
																 $('#featured-article-title-articles > li:eq('+ featured_articles_animation_index +') a').css({
																															'opacity': 0,
																															'width': 0
																														});
																 $('#featured-article-title-articles > li:eq('+ featured_articles_animation_index +')').show();
																 $('#featured-article-title-articles > li:eq('+ featured_articles_animation_index +') a').animate({
																															'opacity': 100,
																															'width': '100%',
																															'padding-right': 30
																														 }, 1000);
																 
															 });
	$('#featured-article-images li:visible').fadeOut(2000);
	$('#featured-article-images li:eq('+ featured_articles_animation_index +')').fadeIn(1000, function() {
		$('#featured-article-dots li').removeClass('active');
		$('#featured-article-dots li:eq('+ featured_articles_animation_index +')').addClass('active');
	});
	
	
	$('input:radio').css('border', 0);
}
