var url = location.pathname;
// check URL for language param
// swap language param and redirect
var language;

function langSelect(url){
    language = url.match('/en/');
    if (language != null) {
        language = "/en/";
    }
    else {
        language = "/fr/";
    }
};
// language select
langSelect(url);

if (language == "/en/") {
    var showAllText = '[+] Show All Answers';
    var hideAllText = '[-] Hide All Answers';
}
else {
    showAllText = '[+] VOIR TOUTES LES RÉPONSES';
    hideAllText = '[-] CACHER TOUTES LES RÉPONSES';
}



function toggleIndicator(checkThis){
    var imgSrc;
    imgIndicator = $(checkThis).children('img').attr('src');
    imgSrc = imgIndicator.match('plus');
    if (imgSrc == 'plus') {
        $(checkThis).children('img').attr({
            'src': imgIndicator.replace('plus', 'minus')
        })
    }
    else {
        $(checkThis).children('img').attr({
            'src': imgIndicator.replace('minus', 'plus')
        });
    }
}

function accordian(target, masterSwitch){
    var toggleState, indicator, resetHeight;
    indicator = $('<img>').attr({
        'src': '/en/ms/bluetooth/images/box_plus.gif'
    });
    
    $(indicator).prependTo(target);
    
    $(target).click(function(){
        $(this).siblings('div').slideToggle('fast');
        toggleIndicator(this);
        
    });
    $(masterSwitch).click(function(){
        toggleState = $(this).attr('toggleState');
        imgIndicator = $(target).children('img').attr('src');
        if (toggleState == 'closed' || toggleState == undefined) {
            $(masterSwitch).attr({
                'toggleState': 'open'
            }).text(hideAllText);
            $(target).siblings('div').slideDown('fast');
            $(target).children('img').attr({
                'src': imgIndicator.replace('plus', 'minus')
            });
        }
        else {
            $(masterSwitch).attr({
                'toggleState': 'closed'
            }).text(showAllText);
            ;
            $(target).siblings('div').slideUp('fast');
            $(target).children('img').attr({
                'src': imgIndicator.replace('minus', 'plus')
            });
            resetHeight = $('ul.accordian').height();
            $('div.bt_content').animate({
                'height': 600
            }, 300, 'swing', function(){
                $(this).css({
                    'height': 'auto'
                });
            })
        }
    })
};

$(document).ready(function(){
    accordian('a.toggler', 'a.toggleAll');
})

