// User interface library
cUI = function(){
	
	/*
		Size an array of elements to the max height
	*/
	this.sizeToTallest = function(elements){
		
		// For each element in array, store the largest height
		var maxHeight = 0;
		$(elements).each(function(){
			maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
		});

		// Size to tallest
		$(elements).each(function(){
			$this = $(this);
			$this.height(maxHeight - ($this.outerHeight(true) - $this.height()));
		});
	
		return this;
	} // this.sizeToTallest()
	
	/*
		Position under construction banner
		(Align top of viewport and make right width)
	*/
	this.positionUCBanner = function(){
		$('#uc-banner').width(($(window).width() - 6) + 'px')
			.css({'top': $(window).scrollTop() + 'px'});
	} // this.positionUCBanner()
	
	// Build an instructors list accordion
	this.buildInstructorsAccordion = function(o_data){
		var o_list = $('#instructors-list');
		var o_loader = $('.main .loading');
		
		// Build the accordion markup
		var v_country = ''; var v_ml_disp_ctr = ''; var v_ml_disp = ''; var o_content = null;
		for (var i = 0; i < o_data.length; i++){
			
			// Create a header?
			if (o_data[i].country != v_country){
				o_list.append('<h3><a href="#">' + o_data[i].country + '</a></h3>');
				o_content = $('<div/>').addClass('wrap');
				o_list.append(o_content);
				v_country = o_data[i].country;
			}
			
			// Create the row			
			if (o_data[i].member_level_disp != v_ml_disp_ctr){
				v_ml_disp = o_data[i].member_level_disp;
				v_ml_disp_ctr = v_ml_disp;
			} else {
				v_ml_disp = '&nbsp;';
			}
			var o_row = $('<div/>').addClass('listrow')
				.append($('<div/>').addClass('cell member_level').html(v_ml_disp))
				.append($('<div/>').addClass('cell picture').html('<img src="assets/images/' + 
					(o_data[i].gender == 'f' ? 'fe' : '') + 'male-avatar.png" alt="" />'))
				.append($('<div/>').addClass('cell member_level_full').html(o_data[i].member_level))
				.append($('<div/>').addClass('cell name').html($.trim(o_data[i].firstname + ' ' + o_data[i].lastname)));
			if (o_data[i].ttf_role.toLowerCase() != 'none'){
				o_row.append($('<div/>').addClass('cell ttf_role').html('<span class="highlight">TTF Role: ' + o_data[i].ttf_role + '</span>'));
			}
			if (o_data[i].pfs_rank.length > 0){
				o_row.append($('<div/>').addClass('cell pfs_rank').html('PFS Rank: ' + o_data[i].pfs_rank));
			}
			o_content.append(o_row);
		}
		
		// Init accordion
		o_list.accordion({
			"autoHeight"		: false
		});
		
		// Hide the loader and present the list
		o_loader.hide().remove();
		o_list.slideDown().fadeIn();
		
		return this;
	} // this.buildInstructorsAccordion()
	
} // cUI()
