﻿$(document).ready(function() {
    google.language.getBranding('GoogTransBrand')
    $.translate(function() {
        var CurLang = '';
        if ($.cookie('GoogTran') == null) {
            CurLang = 'English';
        }
        else {
            CurLang = $.cookie('GoogTran');
        }

        $.translate().ui('select', 'option') //generate dropdown
                .change(function() { //when selecting another language
                    $('body').translate('english', $(this).val(), { //translate from english to the selected language
                        not: '.option, #demo, #source, pre, .jq-translate-ui', //exclude these elements
                        fromOriginal: true
                    })
                    pageTracker._trackEvent("Translation", $(this).val(), document.location.href);
                    $.cookie('GoogTran', $(this).val());
                })
                .val(CurLang)
                .appendTo('#GoogLang'); //insert the dropdown to the page
                
    });
    if ($.cookie('GoogTran') == null) {
        $('#GoogLang').val('English');
    }
    else {
        $('#GoogLang').val($.cookie('GoogTran'));
        $('body').translate('english', $.cookie('GoogTran'), { //translate from english to the selected language
            not: '.option, #demo, #source, pre, .jq-translate-ui', //exclude these elements
            fromOriginal: true
        });
        pageTracker._trackEvent("Translation", $(this).val(), document.location.href);
    }
});
