$(document).ready(function() {
    
    $('.faqSet').css({opacity : 0});
    
    titleHeight = 0;
    newHeight = 0;
    
    $('.faqItem').each(function(i) {
        titleHeight = $('.faqTitle', this).height();
        $(this).css({'height': titleHeight+'px'});
        if(i == ($('.faqItem').length - 1)) {
            $('.faqSet').animate({opacity: 1}, 200, "swing", function() {
                initFaq();
            });
        }
    });
    
    $('.faqTitle h2').click(function(e) {
        e.preventDefault();
        if($(this).hasClass('selected')) { } else {
            $('.faqTitle h2').parent().parent().stop(true, true);
            titleHeight = $('.faqTitle h2.selected').parent().height();    
            $('.faqTitle h2.selected').parent().parent().animate({height: titleHeight+'px'}, 300, "swing");
            $('.faqTitle h2').removeClass('selected');
            $(this).addClass('selected');
            newHeight = $(this).parent().next().height() + +$(this).parent().height() + 10;
            $(this).parent().parent().animate({height: newHeight+'px'}, 300, "swing");
        }
    });
    
    
    
});

function initFaq() {
    $('.faqTitle h2').css({'cursor': 'pointer'});    
}
