/*
$.fn.nextUntil = function(expr) {
    var match = [];
    if ( expr.jquery )
      expr = expr[0];
    // We need to figure out which elements to push onto the array
    this.each(function(){
        // Traverse through the sibling nodes
        for( var i = this.nextSibling; i; i = i.nextSibling ) {
            // Make sure that we're only dealing with elements
            if ( i.nodeType != 1 ) continue;

            // If we find a match then we need to stop
            if ( expr.nodeType ) {
                if ( i == expr ) break;
            } else if ( jQuery.multiFilter( expr, [i] ).length )
break;

            // Otherwise, add it on to the stack
            match.push( i );
        }
    });
    return this.pushStack( match, arguments );
};

*/



/*
$(document).ready(function(){
        $("#conteudo h3").each(function(){
        $(this).nextUntil("h3").wrap("<div class='expand'></div>");
        $(".expand").hide();
        $(".closed").click(function(event){
                $(this).parent().next().toggle();
                $(this).toggleClass("open");
                return false;
                });

        });

function prepararFaq() {
	$('#conteudo').children().hide();
	$('#conteudo h1').show();
	$('#conteudo h2').show();
	
	$('#conteudo h3').addClass('n5');
	$('#conteudo h4').addClass('n5');
	$('#conteudo h5').addClass('n5');

	$('#conteudo h3').addClass('n4');
	$('#conteudo h4').addClass('n4');

	$('#conteudo h3').addClass('n3');

	$('#conteudo .n3').show();

	$("#conteudo h3").click(function() {
       $(this).nextAll().each( function() {
           if ($(this).filter('.n3').length) {
              return false;
           }
           $(this).toggle();
       });
   });

	$("#conteudo h4").click(function() {
       $(this).nextAll().each( function() {
           if ($(this).filter('.n4').length) {
              return false;
           }
           $(this).toggle();
       });
   });

	$("#conteudo h5").click(function() {
       $(this).nextAll().each( function() {
           if ($(this).filter('.n5').length) {
              return false;
           }
           $(this).toggle();
       });
   });
}

*/

function prepararFaq() {
$('#faq').hide();

$("#faq > h3").addClass("secao-titulo");
$("#faq > h4").addClass("assunto-titulo");
$("#faq > h5").addClass("pergunta-titulo");

var i, secao=0, assunto=0, pergunta=0;

$("#faq").children().each (
	function () {
		if ( $(this).hasClass("secao-titulo") ) {

			$(this).attr('id', 'secao-titulo-' + ++secao);
			$(this).after('<div id="secao-' + secao + '" class="secao-conteudo"></div>');

		}

		else if ( $(this).hasClass("assunto-titulo") ) {

			$(this).attr('id', 'assunto-titulo-' + ++assunto);
			$(this).addClass('secao-' + secao);
			$(this).after('<div id="assunto-' + assunto + '" class="assunto-conteudo secao-'+secao+'"></div>');

		}
		else if ( $(this).hasClass("pergunta-titulo") ) {

			$(this).attr('id', 'pergunta-titulo-' + ++pergunta);
			$(this).addClass('assunto-' + assunto);
			$(this).after('<div id="pergunta-' + pergunta+ '" class="pergunta-conteudo assunto-' + assunto + '"></div>');

		}
		else {
			$(this).addClass('pergunta-' + pergunta);
		}
	}
);
for (i = 1; i <= pergunta; i++)
	$('#pergunta-'+i).append($('.pergunta-'+i));

for (i = 1; i <= assunto; i++)
	$('#assunto-'+i).append($('.assunto-'+i));

for (i = 1; i <= secao; i++)
	$('#secao-'+i).append($('.secao-'+i));

$('.secao-titulo').click( function () { $(this).next('.secao-conteudo').slideToggle('normal'); } );	
$('.assunto-titulo').click( function () { $(this).next('.assunto-conteudo').slideToggle('normal'); } );	
$('.pergunta-titulo').click( function () { $(this).next('.pergunta-conteudo').slideToggle('normal'); } );

$('.secao-conteudo').hide();
$('.assunto-conteudo').hide();
$('.pergunta-conteudo').hide();

$('#faq').show();
$('#carregando').hide();
	
}


$(document).ready( function() { 

prepararFaq();

} );

