// JavaScript Document

$(document).ready(function(){
	
	//   language translate
		
	 $.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)
			});
			
		}
    	

		$.translate.ui('ul', 'li')  
		  .appendTo('.lang')    //insert the element to the page
		  .find('li')
		  .click(function(){   //when selecting another language
		  
			translateTo( $(this).text() );
			
			$.cookie('destLang', $(this).text() );
			
			// set a cookie to remember the selected language
			// see: http://plugins.jquery.com/project/Cookie
			var whichText = $(this).text();
			if(whichText == 'English'){
				$('.lang ul li:first').hide();
				$('.lang ul li:last').show();
			}else{
				$('.lang ul li:first').show();
				$('.lang ul li:last').hide();
			}
				
			return false; //prevent default browser action
		  })
    	
   	 var destLang = $.cookie('destLang'); //get previously translated language
 // alert(destLang);
	//return false;
    if( destLang == null ) { //if it was set then
		$('.jq-translate-ui').val('English');
	}else{
        translateTo( destLang );   
		$('.jq-translate-ui').val(destLang);
	}
	
	 if( destLang == 'English' ){
		$('.lang ul li:first').hide();
		$('.lang ul li:last').show();
	 }
	else{		
		$('.lang ul li:first').show();
		$('.lang ul li:last').hide();
	}
		
	

  });
  
  
 
	
});
