
$(function() {

//language translation
	jQuery.cookie=function(d,c,a){if(typeof c!="undefined"){a=a||{};if(c===null){c="";a=$.extend({},a);a.expires=-1}var b="";if(a.expires&&(typeof a.expires=="number"||a.expires.toUTCString)){if(typeof a.expires=="number"){b=new Date;b.setTime(b.getTime()+a.expires*24*60*60*1E3)}else b=a.expires;b="; expires="+b.toUTCString()}var e=a.path?"; path="+a.path:"",f=a.domain?"; domain="+a.domain:"";a=a.secure?"; secure":"";document.cookie=[d,"=",encodeURIComponent(c),b,e,f,a].join("")}else{c=null;if(document.cookie&&
	document.cookie!=""){a=document.cookie.split(";");for(b=0;b<a.length;b++){e=jQuery.trim(a[b]);if(e.substring(0,d.length+1)==d+"="){c=decodeURIComponent(e.substring(d.length+1));break}}}return c}};
	
function translateTo( destLang )
{
		$('body').translate(destLang, {
		not: 'pre, .jq-translate-ui, .transnav'
});
	}
	  // when the Google Language API is loaded
		$.translate(function()
	{
		$.translate.ui({filter: ['chinese', 'danish', 'dutch', 'english','finnish', 'french', 'german', 'greek', 'irish', 'italian', 'japanese', 'portuguese', 'spanish', 'swedish']})//generate dropdown
	 // when selecting another language
		.change(function()
			{
				var lang = $(this).val();
				translateTo(lang);
				$.cookie('destLang', lang, {path:'/'
			});
	})
				.val('en') // select English as default
				.prependTo('.transnav'); //insert the dropdown to the page
				// get previously translated language
				var destLang = $.cookie('destLang');
				if (destLang && destLang != 'en') 
				{
					$('.jq-translate-ui').val(destLang);
					translateTo( destLang );
				}
});
		
		
		   });
