var _languages = [
    ['العربية', 'arabic'],
    ['简体字', 'chineseSimplified'],
    ['簡體字', 'chineseTraditional'],
    ['Dansk', 'danish'],
    ['Nederlands', 'dutch'],
    ['English', 'english'],
    ['Suomi', 'finnish'],
    ['Français', 'french'],
    ['Deutsch', 'german'],
    ['हिन्दी', 'hindi'],
    ['Italiano', 'italian'],
    ['日本語', 'japanese'],
    ['한국어', 'korean'],
    ['Norsk', 'norwegian'],
    ['Polski', 'polish'],
    ['Português', 'portuguese'],
    ['Русский язык', 'russian'],
    ['Español', 'spanish'],
    ['Svenska', 'swedish']
];

/* DO NOT EDIT BELOW THIS LINE */
var _defaultId = 5;
var _defaultLanguage = 'English';

// gets called when page loads
$(function() {
    // these are the realtive paths when the html file is within the languages/[lang]/pages/ directory
    var langPrefix = '../../';
    var imagesPrefix = '../../../';

    // find out which language we are currently in by checking the URL
    var isRoot = false;
    var inPages = false;
    var regexp = /\/languages\/([a-z]+)\/(pages\/)?(.*\.html)?/i;
    var matches = regexp.exec(document.location.href);

    var curLangId = _defaultId;
    var curLangText = _defaultLanguage;
    var curHtmlPage = 'index.html';

    if (matches) {
        curLangText = matches[1];

        // are we in the pages directory or not
        if (matches[2]) {
            inPages = true; // add the pages/ directory to the link path
        }
        else {
            // not in the pages directory so we need to move the relative path up some
            langPrefix = '../';
            imagesPrefix = '../../';
        }

        if (matches.length > 3) {
            curHtmlPage = matches[3];
        }

        // find the lang id based on the url text
        var found = false;
        for (var i = 0; i < _languages.length; i++) {
            if (_languages[i][1] == curLangText) {
                curLangId = i;
                found = true;
                break;
            }
        }

        if (!found) {
            curLangText = _defaultLanguage;
            curLangId = _defaultId;
        }
    }
    else {
        // no match so they are on the main homepage of the site
        curHtmlPage = 'index.html';
        isRoot = true;
        langPrefix = 'languages/';
        imagesPrefix = '';
    }

    // change to always show index.html instead of current page they are on
    curHtmlPage = 'index.html';

    // build drop down list excluding the current selection
    var ddlistHtml = '<div class="langDrop"><a href="' + langPrefix + _languages[curLangId][1] + '/index.html" id="navServices" class="navLDLink">' + _languages[curLangId][0] + ' <img src="' + imagesPrefix + 'images/ld_topArrowDown.gif" width="9" height="8" alt="dropDown" /></a>' +
        '<div id="navServicesDrop" style="display: none;"><ul>';

    for (var j = 0; j < _languages.length; j++) {
        if (j != curLangId) {
            ddlistHtml = ddlistHtml + '<li><a href="' + langPrefix + _languages[j][1] + '/index.html">' + _languages[j][0] + '</a></li>';
        }
    }

    ddlistHtml = ddlistHtml + '<li class="navServicesDropBottom"><!-- --></li></ul>   ' +
        '</div></div>';

    // add the drop down HTML
    $('#langWrap').replaceWith(ddlistHtml);

    // hook up the mouseover and mouseout events to show/hide
    $('div.langDrop').mouseover(function() {
        $('a:first', this).removeClass('navLDLink');
        $('a:first', this).addClass('navLDLinkHover');
        $('div:first', this).show();
    }).mouseout(function() {
        $('a:first', this).removeClass('navLDLinkHover');
        $('a:first', this).addClass('navLDLink');
        $('div:first', this).hide();
    });
});
                