/* General functions */
function digitToText(digit){
	
	var digitsarray = new Array("zero","one","two","three","four","five","six","seven","eight","nine","ten"); // we do not expect more than ten items on a page	
	var result = (digit > digitsarray.length-1 || digit < 0) ? digit : digitsarray[digit];	
	return result;	
}


$(document).ready(function(){

		
	// Define height for each main text item background div (specially for IE6)
	if(ie == 6)
	{
		$('li.pagenum').each(function(){								
				var thisheight = $(this).css('height');
				$('div.listunder',this).css({height : thisheight})							
		});		
	}
	
	/* Navigation menu */
	
	$("ul.topnav li a").mouseover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			
			if (!($(this).hasClass("active"))){
				$(this).parent().find("ul.subnav:not(.active)").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			}
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	// Highlight thumbnail on hover
	if($('div.thumbs_box').length>0){
		$('img.thumbnum', this).each(function(){
			$(this).hover(function() {
				$(this).not('.active').addClass('hovered');				
			}, function(){
				$(this).removeClass('hovered');
			});									  
		});
	}
	
	// Underline download link on PDF icon hover
	if($('div.pdf_box').length>0){
		$('a#pdf_icon_1', this).hover(function() {
			$('a#link_text_1').addClass('hovered');				
		}, function(){
			$('a#link_text_1').removeClass('hovered');
		});									  
	}
	
	// Start carousel normally or go straight to map image
	var start = "1";	
	
	$('.comment_box').each(function(){
			if( $(this).hasClass('map_active_start')  ){
				start = 4; // 4 is the current position of the map image (change if needed)
			}
		}
	);
	
	
	// Load tinycarousel
	$('#slideshow_box').tinycarousel({start: start});	
	
});

