function toggler(anchor, section) {
	$(section).hide();
	$(anchor).click(function(e) {
		e.preventDefault();
		$(section).slideUp();
		var next = $(this).next(section);
		if (! next.length) {
			next = $(this).parent().next(section);	
		}
		if (next.is(':hidden')) {
			next.slideDown();
		}
	});
}

$(document).ready(function() {

	$(document).pngFix(); 

	toggler('a.faq-q', 'div.faq-a');

	$('#categoryList').listnav();
	
	$('ul#categoryList li').quicksearch({
		attached: 'ul#categoryList',
		position: 'before',
		labelText: 'Quick Search',
		inputText: 'Keyword',
		loaderImg: 'loader.gif',
		loaderText: 'Searching...'
	});

	// Create tooltips effect for book descriptions
	$("#book1 a[href]").qtip({
		content: '<p><strong>The Aftermath of Greed: Get Ready for the Coming Inflationary Boom</strong><br />As the US and much of the world grapples with recession, H. L. Quist makes another bold forecast in <strong>GREED</strong>. The author builds a case for the possibility of an inflationary boom in the near future. A must read for anyone concerned about their future and their money.</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});
	$("#book2 a[href]").qtip({
		content: '<p><strong>The Truth About Money</strong><br />The Truth About Money covers the prerequisite fundamentals for financial intelligence. It delivers the information in a clear, concise fashion, and uses real-life examples to further explicate the matter. Highly recommended for those who want to better understand the financial world and create a foundation for future investments.</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});
	$("#book3 a[href]").qtip({
		content: '<p><strong>The Trick to Money is Having Some</strong><br />Stuart Wilde\'s book deals with the ESP of easy money and the metaphysics of being in the right place at the right time, with the right idea and the right attitude. Like his other highly successful books, this work is chock full of useful information. His breezy and comical style makes for effortless reading, as you plot your path to complete financial freedom.</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});
	$("#book4 a[href]").qtip({
		content: '<p><strong>Rich Dad, Poor Dad</strong><br />Anyone stuck in the rat-race of living paycheck to paycheck, enslaved by the house mortgage and bills, will appreciate this breath of fresh air. Learn about the methods that have created more than a few millionaires in Robert Kiyosaki&rsquo;s <strong>New York Times</strong> bestseller. Kiyosaki challenges you to change your thinking in order to influence your fortunes. Learn to think like a rich dad and let your money work for you!</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});
	$("#book5 a[href]").qtip({
		content: '<p><strong>The Roaring 2000s</strong><br />Having already predicted changes in our economy and workplace with uncanny precision, Harry Dent now turns his exceptionally accurate and visionary eye toward our changes in lifestyle. In this fascinating read, Dent will tell us the best places to live and work in the coming decades; he will identify the new boomtowns and reveal that real estate appreciation will concentrate in small towns and new growth cities. With <strong>The Roaring 2000\'s</strong>, he will secure his position as one of the world\'s most prominent and accurate forecasters of societal trends.</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});
	$("#book6 a[href]").qtip({
		content: '<p><strong>The Lies About Money</strong><br />Edelman warns that we have more to worry about than the ordinary fallibility of mutual fund managers. He explores basic concepts of portfolio management and retirement, and college and elder-care savings approaches. Edelman\'s clear writing and helpful advice are sure to win him a satisfied audience.</p>',
		style: { 
		tip: 'topLeft',
		name: 'light' } // Inherit from preset style
	});


	//Modal Windows
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	

});