/*
 * Caller Plugin - Creates a select list and does cookie work
 * 
 * Needs:
 * jquery.min.js
 * jquery.translate-1.2.5.min.js
 * jquery.cookie.pack.js
 * jquery.caller.js
 * 
 * Crafted by: Peter Rjabanedelia
 * http://dbt.sytes.net
 *
 */
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 id 
                                                      // but this will be a class in the next release
          fromOriginal:true                          // always translate from english (even after the page has been translated)
        });
    }
    $.translate().ui('select', 'option')  
    .val('English')                                  // select English as default
    .appendTo('#jq-primaryNavigation')               // insert the element to the page
    .change(function(){                            // when selecting another language
        translateTo( $(this).val() );
        $.cookie('destLang', $(this).val(), { path: '/', domain: 'esind.com' }); 
                                                     // 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
})                                                  // end of DOM ready
