/*
  $Id: translate.js,v 1.1 2009/05/14 17:32:22 eric Exp $

  Pro-Active Software
  http://www.pro-activesoftware.com
*/

function translate(transTo) {
	// set the cookie
	$.cookie('transTo', transTo, { expires: 7, path: '/' });
	
	// add the translation div to the page
	$('body').append('<div id="translation" style="z-index: 100; display: none; position: absolute; left: 35%; top: 40%; height: 20%; width: 30%; border: 1px black solid; background-color: white; text-align: center;"><h2 id="translating">Translating...</h2><div style="margin-left: 5%; width: 90%; border: 1px black solid; text-align: left;"><div id="progressbar" style="width: 0; height: 20px; background-color: #0A246A;"></div></div></div>');

	$('#translating').translate('en', transTo, { fromOriginal: true } );
	
	$('body').translate('en', transTo, {
			fromOriginal: true,

			each: function(){
				$('#progressbar').width(Math.floor(this.progress()) + '%');
			},
							
			start:    function(){ $('#translation').show(); },
			complete: function(){ $('#translation').hide(); },
			error:    function(){ $('#translation').hide(); }
		}
	);
}
	
function revertLanguage() {
	// delete the cookie
	$.cookie('transTo', null, { path: '/' });

	// refresh the page
	window.location.reload(true);
}

function translateOnBodyReady() {
	var transTo = $.cookie('transTo');

	if (transTo != null && transTo != "en" && transTo != "") {
		$(document).ready(function(){
				translate(transTo);
			}
		);
	}
}