$(document).ready(function() {									

$('div#quotes ul#listQuotes').innerfade({ animationtype: 'fade', speed: 2000, timeout: 6000, type: 'random', containerheight: '180' });
$('ul.menu').append('<img src="/images/bottomMenu.png"/>');
$('p.copyright').hide();

//login/register forms
$('#sl_submitbutton input').removeClass('button');
$('button').removeClass('button validate');

$('div a[href$=".pdf"]').each(function(){
	$(this).append(' (<abbr title="Portable Document File">pdf)</abbr>');
}); 

	$("#guts a:not(#book-front-display a)").addClass("dotted_link");
	$("#listQuotes").css("listStyleType","none");
	$("#guts #callBoxes li a").removeClass("dotted_link");

	$('#listQuotes').innerfade({
								animationtype: 'fade',
								speed: 'slow',
								timeout: 10000,
								type: 'random',
								});
						
	
$('#uac').tooltip({ 
    track: true, 
    delay: 0, 
    showURL: false, 
    showBody: " - ", 
    fade: 250 
});		


//newsletter stuff

	$('#guts #archive-container h1:eq(5)').hide();
	
	$('body#main div#newsletter-login input:text').focus(function(){
		$(this).val('');
		});

$('div.newsletter-subscribe-form br').remove();
$('div.newsletter-subscribe-form input:not(:hidden)').css("margin", ".5em").before('<span class="alert">*</span>');
$('div.newsletter-subscribe-form span.alert:eq(2)').remove();
$('div.newsletter-subscribe-form span.alert:eq(2)').remove();
$('span.footer').hide();




//form stuff
$("#submit").click(function(){
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

var emailFromVal = $("#emailFrom").val();
if(emailFromVal == '') {
$("#emailFrom").after('<span class="error">Please enter your email address</span>');
hasError = true;
} else if(!emailReg.test(emailFromVal)) {
$("#emailFrom").after('<span class="error">Please enter a valid email address</span>');
hasError = true;
}

if(hasError == false) {
$(this).hide();
$("#sendEmail li.buttons").append('<img src="images/ajax.gif" alt="Loading" id="loading" />');

$.post("includes/sendemail.php",
{ emailTo: emailToVal, emailFrom: emailFromVal, message: messageVal },
function(data){
$("#sendEmail").slideUp("normal", function() {

$("#sendEmail").before('<h1>Success</h1><p>Thank you for your interest, we will be in touch with you shortly.</p>');
});
}
);
}

return false;
});


// resources
								
	$("a[name^='resource-']").each(function() {
		$(this).click(function() {
			if( $("#" + this.name).is(':hidden') ) {
				$("#" + this.name).show('fast');
			} else {
				$("#" + this.name).hide('fast');
			}			
			return false;
		});
	});



// fees

$("a[name^='fee_type-']").each(function() {
		$(this).click(function() {
			if( $("#" + this.name).is(':hidden') ) {
				$("#" + this.name).show('fast');
			} else {
				$("#" + this.name).hide('fast');
			}			
			return false;
		});
	});

// faq

	$("a[name^='faq-']").each(function() {
		$(this).click(function() {
			if( $("#" + this.name).is(':hidden') ) {
				$("#" + this.name).show('fast');
			} else {
				$("#" + this.name).hide('fast');
			}			
			return false;
		});
	});

// menu

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}



initMenus();

$('div.expandable div.book-detail').expander({
  slicePoint: 290, 
  widow: 2,
  expandEffect: 'fadeIn', 
  userCollapseText: '[ Collapse this text ]',
});

$('div.expand-author div').expander({
  slicePoint: 290, 
  widow: 2,
  expandEffect: 'fadeIn', 
  userCollapseText: '[ Collapse this text ]',
});
	
});

