jQuery(function($){ //when DOM is ready

  $.translate(function(){  //when the Google Language API is loaded
  
    function translateTo( destLang ){ //this can be declared in the global scope too if you need it somewhere else
        $('body').translate( 'english', destLang, {   //translate from english to the selected language
          not: '.jq-translate-ui',  //by default the generated element has this className
          fromOriginal:true   //always translate from english (even after the page has been translated)
        });
    }
        
    //you can generate other controls as well, not just a dropdown:
    $.translate.ui('select', 'option')  
      .appendTo('#language')    //insert the element to the page
      .css({'color':'e3e3e3', 'background-color':'white', 'marginRight':'50px'})
      .change(function(){   //when selecting another language
      
        var lang = $("OPTION:selected", this).val();
        translateTo( lang );
        
        $.cookie('destLang', lang, { path: '/' } ); 
        // set a cookie to remember the selected language
        // see: http://plugins.jquery.com/project/Cookie
        
        return false; //prevent default browser action
      })
     
    var destLang = $.cookie('destLang'); //get previously translated language
    
    if( destLang )  //if it was set then
        translateTo( destLang );
    

  }); //end of Google Language API loaded

    function translateToCookie( destLang ){ 
        $('body').translate( 'english', destLang, {   
          not: '.jq-translate-ui',  
          fromOriginal:true   
        });
        $.cookie('destLang', destLang, { path: '/' } ); 
    }

$("#german").click(function(){
   translateToCookie( "german" );
});

$("#english").click(function(){
   translateToCookie( "english" );
});

$("#japanese").click(function(){
   translateToCookie( "japanese" );
});

$("#chinese").click(function(){
   translateToCookie( "chinese_simplified" );
});

}) //end of DOM ready
