$(document).ready(function(){

	if($.cookie('readLanguage')){
		var strSource = "en";
		translatePage($.cookie('readLanguage'),strSource);
	}

	$('#selectLanguages a').click(function(){
		var strSource = "en";
		if($.cookie('readLanguage')){
			strSource = $.cookie('readLanguage');
		}
		var languageToTranslate = $(this).attr('id').replace('translate-','');
		translatePage(languageToTranslate,strSource);
		$.cookie('readLanguage',languageToTranslate);
	});

	function translatePage(language,strSource){
		
		$('#homeRightColumn div p').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#homeRightColumn div li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#homeRightColumn div h5').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#homeRightColumn div h2').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#footerSitemap li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#header').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource			
			});
		});
		$('#menu li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	
			});
		});
		$('#main p').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h1').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h2').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h3').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h4').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h5').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main h6').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#main li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#subnavWrapper h2').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#subnavWrapper li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});

		$('#dateTime').sundayMorning({
		    destination:language,
			source:strSource	 
		});

		$('#breadcrumbs li').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});

		$('#latestNewsWrapper h2').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#latestNewsWrapper h3').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#latestNewsWrapper p').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#latestNewsWrapper span').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 
			});
		});
		$('#homeLatestNews').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 		   
			});
		});
		$('#footer p').each(function(){
			$(this).sundayMorning({
				destination:language,
				source:strSource	 		   
			});
		});

	}	
	
	$("#selectLang").change(function() { 
		var myLang = $("#selectLang").val();
		var strSource = "en";
		if($.cookie('readLanguage')){
			strSource = $.cookie('readLanguage');
		}
		translatePage(myLang,strSource);
		$.cookie('readLanguage',myLang);
	 });
});
