﻿function initLang ()
{
	var treeNavigationTitle = $('.treeNavigationTitle');
	var longestChainButton = $('.longestChainButton');
	var mostRepliesButton = $('.mostRepliesButton');
	var replyButton = $('.replyButtonCustom');
	var infoArrow = $('.infoArrow');
	var labelLinks =$('.labelLinks');
	var labelImages =$('.labelImages');
	var labelVideos =$('.labelVideos');
	var emailMessage =$('.emailMessage');
	var submitEmail =$('.submitEmail');
	var closeEmail =$('.closeEmail');
	var moto=$('.moto');
	var composeQuestion=$('.questionP');
	var aboutButton=$('.aboutButton');
	var transMessage=$('.transMessage');
	var moreNumberText=$('.moreNumberText');
	var inboxNumber=$('.inboxNumber');
	var votingDiv=$('.votingDiv');
	var showChainButton=$('.showChainButton');
	var labelAttach=$('.labelAttach');
	var buttonSend=$('.buttonSend');
	var iconVideo=$('.iconVideo');
	var iconPicture=$('.iconPicture');
	var iconLink=$('.iconLink');
	var buttonCancel=$('.buttonCancel');
	var labelSelectedAttach=$('.labelSelectedAttach');
	var buttonYoutubeSerachOpen=$('.buttonYoutubeSerachOpen');
	var spanServiceBackButton=$('.spanServiceBackButton');
	var aboutHeader=$('.aboutHeader');
	var headerP1=$('.headerP1');
	var headerP2=$('.headerP2');
	var headerP3=$('.headerP3');
	var arrowLeft=$('.arrowLeft');
	var arrowRight=$('.arrowRight');
	
	if (ln == 'en') {
		treeNavigationTitle.html('Conversation Tree:');
		longestChainButton.html('longest chain');
		mostRepliesButton.html('most replies');
		replyButton.html('<img class="postTopRightIcon replyIcon" src="pics/replyIcon.png">reply');		
		infoArrow.attr('title','number of clicks');
		labelLinks.html('Links');
		labelImages.html('Images:');
		labelVideos.html('Videos:');
		emailMessage.html('Where should an email be sent when someone replies to this post?');
		submitEmail.html('submit');
		closeEmail.html('close');
		tranEmailSubmitted = 'Email submitted!';
		langNoMorePosts = 'no posts to bring right now.. try again later.';
		moto.html('Dialogue about the Middle East');
		composeQuestion.html('What do you have to say about the Middle East?');
		aboutButton.html('about mailero');
		transMessage.html('Zoink!<br>Translate messages in other languages with &nbsp;<img src="./pics/tranIcon.png" class="tranIcon tranIconTran">');
		newMessagesPlural = 'new messages';
		newMessagesSingular = 'new message';
		inboxNumber.attr('title','messages in the conversation');
		votingDiv.attr('title','up vote');
		replyNumberNone = 'no replies yet';
		replyNumberOne = '1 reply';
		replyNumberMany = 'show replies';
		showChainButton.html('show chain');
		labelAttach.html('attachments:&nbsp;&nbsp;');
		buttonSend.html('send');
		iconVideo.attr('title','youtube video');
		iconPicture.attr('title','image');
		iconLink.attr('title','link');
		instVid = 'enter a youtube video link';
		instImg = 'link to an image online (enter a web address)';
		instLin = 'enter a web address';
		instVidLab = 'Video:&nbsp&nbsp';
		instImgLab = 'Or:&nbsp&nbsp';
		instLinLab = 'Link:&nbsp&nbsp';
		attachButtonSubmit='submit';
		buttonCancel.html('cancel');
		labelSelectedAttach.html('Or:&nbsp;&nbsp;');
		buttonYoutubeSerachOpen.html('search YouTube');
		spanServiceBackButton.html('<span class="spanServiceBackArrows">&#171;</span> back to conversation');
		aboutHeader.html('Welcome to mailero, the conversation engine!');
		headerP1.html('You can send opinions, links, videos and pictures to other mailero users.');
		headerP2.html('You\'re talking to people who don\'t necessarily speak your language. If you encounter messages in other languages, <br>use the <img class="aboutTranIcon" src="../pics/tranIcon.png"> to translate.');
		headerP3.html('Mailero is just starting out. If you have any feedback or questions, send an email to <a href="mailto:contact@mailero.com">contact@mailero.com</a>');
		arrowLeft.attr('title','step back');
		arrowRight.attr('title','step forward');
	}
	
	else if (ln == 'ar'){
		treeNavigationTitle.html('شجرة المحادثة:');
		longestChainButton.html('أطول سلسلة');
		mostRepliesButton.html('أكثر إجابات');
		replyButton.html('<img class="postTopRightIcon replyIcon" src="pics/replyIcon.png">الإجابة');
		infoArrow.attr('title','عدد النقرات');
		labelLinks.html('روابط:');
		labelImages.html('صور:');
		labelVideos.html('فيديوهات:');
		emailMessage.html('إلى أين تريد أن نرسل email عندما يجاوب شخص ما؟');
		submitEmail.html('ok');
		closeEmail.html('لا أريد');
		tranEmailSubmitted = 'تم استلام العنوان!';
		langNoMorePosts = 'لا توجد رسائل أخرى حالياً. حاول لاحقاً..';
		moto.html('محادثة عن الشرق الأوسط');
		composeQuestion.html('ألديك ما تقوله عن الشرق الأوسط؟');
		aboutButton.html('تفاصيل عن ميلرو');
		transMessage.html('ويلاه! وصلتك رسائل بلغة أخرى.<br>ترجمها بإستخدام &nbsp;<img src="./pics/tranIcon.png" class="tranIcon tranIconTran">');
		moreNumberText.html('');
		newMessagesPlural = 'رسائل جديدة';
		newMessagesSingular = 'رسالة جديدة';
		inboxNumber.attr('title','عدد الرسائل في شجرة المحادثة');
		votingDiv.attr('title','تصويت');
		replyNumberNone = 'لا إجابة بعد';
		replyNumberOne = 'إجابة واحدة';
		replyNumberMany = 'الإجابات';
		showChainButton.html('السلسلة');
		labelAttach.html('مرفقات:&nbsp;&nbsp;');
		buttonSend.html('أرسل');
		iconVideo.attr('title','فيديو من يوتيوب');
		iconPicture.attr('title','صورة');
		iconLink.attr('title','رابط');
		instVid = 'أدخل عنوان الفيديو على يوتيوب';
		instImg = 'أدخل عنوان الصورة على النت (أدخل رابط)';
		instLin = 'أدخل رابط';
		instVidLab = 'فيديو:&nbsp&nbsp';
		instImgLab = 'أو:&nbsp;&nbsp;';
		instLinLab = 'رابط:&nbsp&nbsp';
		attachButtonSubmit='ok';
		buttonCancel.html('إنسى');
		labelSelectedAttach.html('أو:&nbsp;&nbsp;');
		buttonYoutubeSerachOpen.html('ابحث في يوتيوب');
		spanServiceBackButton.html('<span class="spanServiceBackArrows">&#171;</span> عودة إلى المحادثة');
		aboutHeader.html('أهلاً وسهلاً بك في ميلرو، محرك المحادثة!');
		headerP1.html('يمكنك إرسال آراء، روابط، فيديوهات، وصور إلى مستخدمين آخرين.');
		headerP2.html('على موقع ميلرو أنت تتصل مع ناس قد لا يفهمون لغتك. إذا جاءتك رسالة بلغة اخرى، إستخدم&nbsp;<img class="aboutTranIcon" src="../pics/tranIcon.png"> حتى تترجمها.');
		headerP3.html('ميلرو مشروع جديد. فإذا كانت لديك ملاحظات أو اسئلة، يرجى إرسال بريد الكتروني إلى&nbsp;<a href="mailto:contact@mailero.com">contact@mailero.com</a>');
		arrowLeft.attr('title','خطوة إلى الخلف');
		arrowRight.attr('title','خطوة إلى الأمام');
	}
	
	if (checkDir(ln) == 'rtl') //if ln is rtl
	{		
		//special fixes		
		var marker = $('.clickedPostMarkerLTR');
		var rtlMarker = $('.clickedPostMarkerRTL');
		marker.after(rtlMarker);
		marker.remove();
		rtlMarker.addClass('clickedPostMarker');	
	}	
}

function checkDir (lan)
{
	var ltrArray = new Array ('en','tr','fr','zh','de','es','ja','sv','hi','da','pt','it','no');
	var rtlArray = new Array ('ar','fa','iw','ur');
	var dir = 'ltr';
	if (jQuery.inArray(lan, ltrArray) == -1)
	{
		dir = 'rtl';
	}
	return dir;
}

function trans (btn)
{
	var button = $(btn);
	var target = button.attr('lan');
	var transParent = button.parents('.transParent');
	var transChildren = transParent.find('.transChild');
	for (var i=0; i<transChildren.length; i++)
	{
		var currentField = transChildren[i];
		detectReplace(currentField,target);	
	}
}

/******
text enlarge Arabic:
treeNavigationTitle
longestChainButton
mostRepliesButton
replyButton

rtl List:
treeServiceArea

SPECIAL for rtl:
treeNavigationCell {direction: ltr; text-align: right;}

******/

/**** CONSTANTS  *******/
//translation constants
var tranEmailSubmitted;
var langNoMorePosts;
var newMessagesSingular;
var newMessagesPlural;
var replyNumberNone;
var replyNumberOne;
var replyNumberMany;
var instVid;
var instImg;
var instLin;
var instVidLab;
var instImgLab;
var instLinLab;
var attachButtonSubmit;

//other constants
var playReceiveAmount = 5;
var receiveDelayAmount = 4000;

/***RECORD OF CHANGES ltr TO rtl***/
/*
$('.dirChange').css('direction','rtl');
		
//special fixes
$('.treeNavigationCell').attr('style','direction: ltr; text-align: right;');
$('.postTopRightDiv').attr('style','float:left;');
$('.postTopRight').attr('style','float:left;');
$('.postTopRightIcon').attr('style','margin-left:6px; margin-right: 0px;');
$('.postsArea').attr('style','padding-left: 0px; padding-right: 15px; direction:rtl;');
$('.emailInput').attr('style','margin-left: 5px; margin-right: 35px;');
$('.postText').attr('style', 'margin-right: 50px; margin-left: 25px;');
$('.postAttachmentsTable').attr('style', 'margin-right: 50px; margin-left: 6px;');
var marker = $('.clickedPostMarkerLTR');
var rtlMarker = $('.clickedPostMarkerRTL');
marker.after(rtlMarker);
marker.remove();
rtlMarker.addClass('clickedPostMarker');
$('.logo').attr('style','margin-right: 30px; margin-left: 0px;');
$('.composeLeft').attr('style','padding: 10px 20px 15px 15px; border-radius: 4px 0 0 0; -moz-border-radius: 4px 0 0 0;');
$('.divFooterConv').attr('style','float:left; right: -10px;');
$('.divServiceArea').attr('style','border-left: 3px solid #CAD8F3; border-radius: 4px 0px 0px 0px; -moz-border-radius: 4px 0px 0px 0px;'); //border-right: none; 
$('.leftColumnStylesDiv').attr('style','border-left: 3px solid #CAD8F3; border-right:none; border-radius: 0 0 0 4px; -moz-border-radius: 0 0 0 4px;');
*/
