var isIE = ($.browser.msie != undefined && $.browser.msie == true);

function formatText(index, panel) {
	return index + "";
} 	

function clearText(field){ 
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
} 
	
$(document).ready(function() {

	var banner_change_interval = 5000;
	var banner_transition_interval = 1000;
	
	setInterval(function() {
		var $slides = $('ul.slides li');
		var total = $slides.length;
		var cur_index = $slides.filter('.current').index();
		var next_index = ((cur_index+1) % total);
	
		if (isIE) { 
			$slides.find('.ban_txt').hide(); 
		}
		
		$slides.find('.ban_img').fadeOut(banner_transition_interval).end()
			.find('.ban_txt').fadeOut(banner_transition_interval).end()
			.removeClass('current').filter(':eq('+next_index+')')
			.addClass('current').find('.ban_img').fadeIn(banner_transition_interval);
		
		if (isIE) { 
			$slides.filter('.current').find('.ban_txt').show(); 
		} else {
			$slides.filter('.current').find('.ban_txt').fadeIn(banner_transition_interval); 	
		}
	}, banner_change_interval);
	
	
	$('div.spry a.more, div.bio-spry a.more').click(function(e) {
		e.preventDefault();
		
		var isClose = ($(this).html() == 'Close');
		
		$('.more').html('Learn More');
		$('.rest').slideUp();
		$('.bio-spry img').fadeOut('fast');
		
		if (isClose) {
			$(this).html('Learn More').parents('.spry, .bio-spry').find('.rest').slideUp();
			return;
		} else {
			$(this).html('Close').parents('.spry, .bio-spry').find('.rest').slideDown(function() {
				$(this).parents('.spry, .bio-spry').scrollintoview('slow').find('img').fadeIn('slow').end();
			});
		}

	});


	$('a.single_image').click(function(e) {
			e.preventDefault();
			$.fancybox({
				title: '<a href="' + $(this).next('a.single_image_pdf').attr('href') + '" target="_blank">Download The Informed Decision Approach PDF</a>',
				href: $(this).attr('href')
			});
	});

	$('.rf-logo').parent().hover(
		function() { 
			var img = $(this).find('img');
			img.data('oldsrc', img.attr('src'));
			img.attr('src', 'http://www.thieltestsite.com/richardson-financial.com/wp-content/themes/richardson_financial/images/logo-hover.png');
		}, 
		function() {
			var img = $(this).find('img');
			img.attr('src', img.data('oldsrc'));
	});
	
	
	$("a[rel='external']").live('click', function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	});


});
