lastActiveItem = 0;

$(document).ready(function(){
     
   url = document.URL;
   if (url.indexOf('searchfor') == -1) {
   
       $(".tx-irfaq-answer").hide();
        
        $("ul.tx-irfaq-questions-list li a").each(function(i){
            
            $(this).attr("href", "javascript:void(0)");
            
            $(this).parent("li").css({listStyleImage:"url(fileadmin/templates/gfx2/plus.gif)"});       
            
            $(this).click(function(){
                
                $("#active-answer").remove();
                $(this).after('<div id="active-answer">' + $(".tx-irfaq-answer:eq("+ (i) +")").html() + '</div>');
                $("#active-answer h4").remove();
                $("#active-answer").hide().fadeIn("slow");
                
            });
            
        });
        
    } else {
        query = url.substring(url.indexOf('searchfor')+10);
        searchWords = query.split(",");
        searchText = $(".tx-irfaq-answer-wrap").html();
        
        for (i=0;i<=searchWords.length;i++) {
            if (searchText.indexOf(searchWords[i]) != -1) {
                if (searchWords[i] != '') {
                    searchText = str_replace(searchWords[i], '<span style="color:red;font-weight:bold;">' + escape(searchWords[i]) + '</span>', searchText);
                }
            }
        }
        $(".tx-irfaq-answer-wrap").html(searchText);        
    }
    
});

function showAnswer(i)
{
    $(".tx-irfaq-answer:eq("+ (i) +")").fadeIn("slow");
}

function str_replace(search, replace, subject) { 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}