$(document).ready(function()
{
	//------------------------------------------------- Home Link in Main Menu - add 'index.htm' to href attr (for development use only)
	$('#nav .nav li a:contains("Home")').attr('href', 'index.htm');
	
	//------------------------------------------------- Content H2 Tag - No padding on first instance
	$('#content h2:first').addClass('noTopPadding');
	
	//------------------------------------------------- Content H1 Tag - Adjusted padding on pages that contain tables
	
	//Set the width of the first cell in the first table to be the same as the image  
	$('#content.tableLayout table:first td:first').each(function() {
		$(this).attr('width', $(this).find('img').attr('width'));
	});

	//Add 20px padding to the first (even) cell of every table row in the tableLayout section
	$('#content.tableLayout table td:even').css('padding-right', 20);
		
	//Get the width of the image in the first cell in the first table, add 40px to it to align it with the content body.
	//40px - 20px padding on the left of the table & 20 on the the table cell
	$('div.tableLayout h1').css('padding-left', parseInt( $('div.tableLayout table:first td:first img').attr('width') ) + 40 );
	
	if(window.console) {
		console.log( 'Width of image in first table cell: ' + $('#content.tableLayout table td:first').find('img').attr('width') + ' and src of this image: ' +  $('#content.tableLayout table td:first').find('img').attr('src') );
		console.log( 'Width of first table cell: ' + $('#content.tableLayout table:first td:first').attr('width') );
	}

	//------------------------------------------------- Search Box
	$('#search #ajaxSearch_input').fadeTo(0.1, 0.5).css('display', 'block');

	$('#search #ajaxSearch_input').focus(function() {
		$(this).fadeTo(300, 1);
	});
	$('#search #ajaxSearch_input').blur(function() {
		$(this).fadeTo(300, 0.5);
	});

	//------------------------------------------------- Nav
	
	//Suckerfish
	$('#nav li:has(ul)').hoverIntent(function() {
		$(this).children("ul").css("display", "none");
		$(this).children("ul").slideDown("normal");
	},
	function() {
		$(this).children("ul").slideUp("normal");
	});
	
	//Hover class for ul li ul li
	$('#nav ul li').hover(function() {
		$(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});
	
	//------------------------------------------------- Search Results Page - Strip the Query String to stop the highlight function on the target page
	$('.ajaxSearch_result').find('a[href*="ajaxSearch_highlight"]').each(function() {
		newHrefValue = $(this).attr('href').split('?');
		$(this).attr('href', newHrefValue[0]);
	});

	//------------------------------------------------- Active item in left sidebar
	
	var currentPage = window.location.href.split('/');
	if(window.console) {
		for (i = 0; i < currentPage.length; i++) {
			//console.log(currentPage[i]);
		}
	}
	currentPage = currentPage[currentPage.length -1];
	if (window.console) console.log('Current Page: ' + currentPage);
	
	//Find the a href of the the stories in the left sidebar that matches the current url and add a background color to its parent container
	$('#leftSidebar').find('a[href*="' + currentPage + '"]').parents('.news').css('background-color', '#e8e8e8');
	
	//If main news page set the first news story in the left sidebar to active
	if (currentPage == 'news.htm') $('#leftSidebar .news:first').css('background-color', '#e8e8e8');
	

}); //Close document.ready
