// JavaScript Document
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)
                              //unnecessary in v1.4, the default value is true
        });
    }
    
        
    //you can generate other controls as well, not just a dropdown:
    //there are new features in v1.4: http://code.google.com/p/jquery-translate/wiki/Extensions
    $('#testnav')
      .find('a')
      .click(function(){
         var lang = $(this).attr('id');
         //translateTo( lang );         
        $.cookie('destLang', lang,{path: '/'});  
        // set a cookie to remember the selected language 
        // see: http://plugins.jquery.com/project/Cookie 
         //return false;
		 window.location.reload();
      })        
    var destLang = $.cookie('destLang'); //get previously translated language 
   $.cookie('destLang', destLang,{path: '/'} );
	
   if( destLang )  //if it was set then 
   		if(destLang != "English"){  
			//alter the menu
			//menus
			var menueng = document.getElementById('list-eng');
			var menuspa = document.getElementById('list-spa');
						
			//now hide the chosen one in 
			if(destLang == "Spanish"){
				//hide the menu
				menueng.style.display = "block";
				menuspa.style.display = "none";
				//navigation
				var navother = document.getElementById('navigation');
				navother.className = "spa";
				//search
				var searchother = document.getElementById('searchform');
				searchother.className = "spa";
				//homepage
				//var moreinfo = document.getElementById('homebox');
				//moreinfo.className = "spa";
			}
			
			translateTo(destLang);
		}else{
			
			//change the menus to english
			//alter the menu
			var menueng = document.getElementById('list-eng');
			var menuspa = document.getElementById('list-spa');
			//hide the menu
			menueng.style.display = "none";
			menuspa.style.display = "block"; 				
		}


  }); //end of Google Language API loaded
}) //end of DOM ready
