//FF20110929: New Page Script
$(document).ready(function() {
	
    $('.widgetHandle img').css( 'cursor', 'pointer' );
	$('.widgetHandle img').attr('src', 'images2/handleOpened.png');
	
//    $('#compare').hide();
//	$('#regionalSpotlight').hide();
//	$('#countrySpotlight').hide();
//	$('#keyFindings').hide();

	// Init pretty photo for the video player
	$("a[rel^='prettyPhoto']").prettyPhoto({
			deeplinking: false
		});
	
	// Remove the empty rows from the ranking table on the home page
    $('#tableRanking tr').each(function () {
         if (!$.trim($(this).text())) $(this).remove();
    });
	
	
	
	$('#tableRanking tr .firstCol').each(function () {
		var val = $.trim($(this).text());
		if(val < 31) {
			$(this).css('background-color', '#b0c678');
		}
		if(val > 30 && val < 81) {
			$(this).css('background-color', '#ffe37d');
		}
		if(val > 80) {
			$(this).css('background-color', '#e85252');
		}
    });
    
	//$('.firstCol:lt(30)').css('background-color', '#b0c678');
	//$('.firstCol:gt(29):lt(80)').css('background-color', '#ffe37d');
	//$('.firstCol:gt(79)').css('background-color', '#e85252');
	
	//Filter section on the ranking table home page ****************************************************
	// get all tr tags in the current table
	var $table = $('#tableRanking tr td');
	// the "clear" function call
//	$('form a').click(function(){
//		$('#countrySearchInput').val('');
//		$table.parent('tr').removeAttr('class','hiddenTR');
//		return false;
//	});
	// the on keyDown event handler
	$('#countrySearchInput').keyup(function(){
		// get the current value of the text field
		var string = $(this).val().toUpperCase();
		// loop over each item in $table
		$table.each(function(){
			// set a string equal to the contents of the cell
			//var contents = $(this).html().toUpperCase();
			var contents = $(this).children('a').text().toUpperCase();
			if(contents)
			{
				var $row = $(this).parent('tr');
				// check the string against that cell
				var value = (!contents.match('^' + string)) ? $row.attr('class', 'hiddenTR') : $row.removeAttr('class', 'hiddenTR');
			}
		});
	});
    //************************************************************************************************
});

// Toggle the called widget
function ToggleWidget(value, src) {
	$('#' + value).is(":visible") ? $(src).attr('src', 'images2/handleClosed.png') : $(src).attr('src', 'images2/handleOpened.png');
	$('#' + value).toggle('fast');
}

function ToggleList(value, src) {
	$('#' + value).toggle('fast');
}

// Filter the ranking data table
function Filter(table, phrase) {
	var t = $(table);
	$.uiTableFilter(t, phrase);
}
