$(document).ready(function() {

	// Local Scroll
	function filterPath(string) {
		return string
			.replace(/^\//,'')  
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')  
			.replace(/\/$/,'');
		}
		$('a[href*=#]').each(function() {
			if ( filterPath(location.pathname) == filterPath(this.pathname)
			&& location.hostname == this.hostname
			&& this.hash.replace(/#/,'') ) {
			var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
			var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top;
				$(this).click(function() {
					$('html, body').animate({scrollTop: targetOffset}, 400);
					return false;
				});
			}
		}
	});
	
	// Open links in a new window if rel is set to external
	$('a[rel="external"]').click( function() { window.open( $(this).attr('href') ); return false; });
	
	// Initialises Make Nice Inputs
	//$('.isMNice').makeNiceInput();
	
	// Adjust the width of the menu
	var menu_width = $('#menu').width() - 1;
	var total_items = $('#menu li').length;
	var item_width = 0;
	$('#menu li').each(function(){
		item_width += parseInt($(this).width());
	});
	var npl = parseInt((menu_width - item_width) / (total_items * 2)-1);
	var npr = parseInt(npl - 1);
	$('#menu li').each(function(){
		$(this).css('padding-left',npl);
		$(this).css('padding-right',npr);
	});
	
	// Sub Menu hover for the awesomeness that is IE7 :S
	$("#submenu li").hover(function () {$(this).addClass("over");},function () {$(this).removeClass("over");});
	
	// Add class to last item in footer
	$('#footer div.grid_4:last').addClass('last');
	
	// Add class to last item in footer
	$('#submenu li:last').addClass('last');
	$('#submenu li.current_page_item').addClass('active').parent().parent().addClass('active');
	//$('#submenu li.current_page_item').parent().parent().addClass('active');
	
	if( $('table').length > 0 ) {
		$('table tr').has('th').addClass('headerbar');
	}
});
