$(document).ready(function() {



	$('#homepagedl dt a').click(function() {
		$('#homepagedl dd').each(function() {
			$(this).hide();
		});
		$('a.dthover').each(function() {
			$(this).removeClass('dthover');
		});
		$(this).addClass('dthover');
		$(this).parent().next().show();
	});


	$('#resourcecategoryid').change(function() {
		$.ajax({
			url: "/ajax/page_ajax.php",
			data: 'q=last5&xhr=1&resourcecategoryid=' + $(this).val(),
			success: function(data, status, xhr) {
				$('#last5').html(data);
			}
			// do nothing on failure
		});
	});





	/* DYNAMIC TEXT RESIZE FOR SOME LANGUAGES */
	var lang = $('meta[http-equiv=Content-Language]').attr("content");
	var fontSize = 20;
	if(lang == 'ta') {
		fontSize = 17;
	}

	var lineWrap = 31;
	if(lang == 'bn') {
		lineWrap = 35;
	}
	if(lang == 'ta') {
		lineWrap = 20;
	}


	$('#homepagedl dt a').each(function() {

		// this all needs to be made properly generic
		if($(this).html().length > 25) {

			// 25 (at end of line) is a guess for roughly how many glyphs will fit on a line
			var newFontSize = fontSize - (2 * Math.floor($(this).html().length / 25));
			$(this).css('font-size',  newFontSize + 'px');
		}

		if($(this).html().length > lineWrap) {
			$(this).css({'height': '24px', 'line-height': '24px'});
		}

		// the recent projects dialog has overlaps in some languages, so fix it if needed
		if(findIntersectors('#anchor1 div:first h2 span', '#project-select-label').length > 0) {

			$('#anchor1 div:first h2').css('font-size', '90%');

			var h2str = $('#anchor1 div:first h2 span').html();

			// find the next occurence of space character
			for(var i = 20; h2str.charCodeAt(i) != 32 && i < 200; i ++) {}

			$('#anchor1 div:first h2 span').html(h2str.substr(0, i) + "<br>" + h2str.substr(i));

		}
	});



});


