$(function() {

//----written by Scott Darby scottdarby@redweb.com----//

	//main nav
	//see how many items there are in the menu
	var listItems = $('#nav li').length;

	//calcuate width of container
	var listContWidth = parseInt($('#nav').css('width'));

	var listItemWidth = (Math.round(listContWidth/listItems));

	//set width of each nav item
	$('#nav li').css('width', listItemWidth);

	//check if all widths fit equally into the container, if not resize last item to fit
	var totalWidths = listItemWidth*listItems;

	if (totalWidths < listContWidth){
		var diff = listContWidth-totalWidths;
		$('#nav li:last').css('width', listItemWidth+diff);
	}

	if (totalWidths > listContWidth){
		var diff = totalWidths-listContWidth;
		$('#nav li:last').css('width', listItemWidth-diff);
	}

	//set height of links
	//select links
	var $links = $('#nav li a');
		
	//create array for heights
	var heights = Array();
	
	//create function to numerically sort array in reverse order
	function sortArray(a,b) {
		return b - a;
	}
		
	//iterate through links
	for( var i = 0, n = $links.length;  i < n;  ++i ) {
		var link = $links[i];
		//add heights to array
		heights.push($(link).height());			
	}
	
	//sort array so highest number is at start
	var ordered = heights.sort(sortArray);
	var highest = ordered[0];
	
	//set all list items to the height of the highest
	$('#nav li a').css("height", highest);

	//sidenav
	var lNavLinks = $('ul#lNav li');
	var index = lNavLinks.index($('li.lNavSelected'));
	$('ul#lNav li a').eq(index-1).addClass('above');
	$('ul#lNav li a').eq(index+1).addClass('below');

	if ($('ul#lNav li:first').hasClass('lNavSelected')){
		$('#lNavContainer').addClass('top');
	}

	if ($('ul#lNav li:last').hasClass('lNavSelected')){
		$('#lNavContainer').addClass('bottom');
	}

	//last-child selector for IE
	if ( $.browser.msie ) {
		$('#nav li:last-child a').css('border-right','1px solid #d6d6d6');
	}

	//alternate colors
	$('.tag:odd').css('color','#538F35');
	$('.tag:even').css('color','#D17030');
	$('.serviceNewsImgContainer:odd').addClass('blueBox');

});
