function buildArray(){
	//factsArr = [1,2,3,4,5];
	factsArr = [];	
	factsArrLength = $('.factoid').length;
	for (i=0 ; i<factsArrLength ; i++)
		factsArr[i] = i+1;
}

function chooseRandomFactoid(){
	return Math.ceil(Math.random()*factsArr.length);
}

function changeFactoid(){

	$('.factoid').hide();

	randomFactoid = chooseRandomFactoid();
	
	$('#Fact'+factsArr[randomFactoid-1]).show();
	
	factsArr.splice(randomFactoid-1, 1);
	
	if (factsArr.length == 0) buildArray();
	
}


$(document).ready(function() {

	$('#factoid-controls').show();

	// Redirect to the URL of the selected profession in the dropdown when the 'Go' button is clicked
	$('#btnProfessionSelector').click(function(){	
		window.location = $('#selectProfessionList').val();
	});
	
	$('a#factoid-prev').hide();
	$('.factoid').hide();

	$('a#factoid-next').click(function(){
		changeFactoid();
		return false;
	});
	
	buildArray();
	changeFactoid();

	/* open external links in new window
	   add the 'external' class which adds an icon. don't do this for links 'ext'
	   which are used for things like images which don't need the icon */
	$('#Content a[href^="http"]').not('[href*="fairnesscommissioner.ca"]').attr('rel', 'external').attr('target', '_blank');
	$('#Content a[href^="http"]').not('[href*="fairnesscommissioner.ca"]').not('.ext').addClass('external');
	
	/* the icon is added by the class 'external', hide the image that appears in older pages */
	$('a.external img').css('display', 'none');
	
	/* open pdf links in a new window */
	$('a.pdf').attr('target', '_blank');

	/* top of page link */	
	$('a.top').click(function() {
		$('html').scrollTop(0);
		return false;
	});
	
	/* remove sep from first item in breadcrumb trail */
	//$('#breadcrumbs').find('li').css('background-image', 'none');
	$('#breadcrumbs li:first-child').css('background-image', 'none').css('padding-left', 0);
	
	/* add 'last' class to last element in ul / dl lists for styling */
	$('dl dd:last-child').addClass('last');
	
	/*
	 * Profession select dropdown
	 * submit onchange / hide submit
	 */
	$('form[name=selectProfession] input[type=submit]').hide();
	$('form[name=selectProfession] select').change(function() {
		$(this).parent().submit();
	});

	/*
   * Tables: add odd/even classes for styling
	 */
	/*$('table.alt').each(function() {
		$(this).find('tbody tr')
	});*/
	$('table.alt tbody tr:odd').addClass('even');
	$('table.alt tbody tr:even').addClass('odd');

	/*
	 * Scrolling Table Headers (jquery.fixedtableheader-1-0-2.min.js)
	 *
	 * IE6 is using the left boundary of the site, not the browser to determine
	 * the offset, so we need to set left to 0
	 *
	 * IE7/6 has problems with scrolling table headers whose width has
	 * been adjusted above to 'fixed-width'. The dimensions display all wonky.
	 * disable scrolling headers in this instance for now.
	 */
	//$('table.scroll').fixedtableheader({highlightrow:true});
	if ($.browser.msie && jQuery.browser.version < 8 && $('table.comparison').css('table-layout') === 'fixed') {
	} else {
		$('table.scroll').fixedtableheader({highlightrow:true});
	}

	/* IE6 left boundary fix */
	if ($.browser.msie && jQuery.browser.version == 6) {
		$(window).scroll(function() {
			$('table[id^="fixedtableheader"]').css('left', '0');
		});
	}

	/*
	 * Table sort
	 */
	$('table.tablesorter').tablesorter();

	/*
   * Tabs
	 */
	$('#tabs').tabs();
});