/** Distribute menu items proportionally **/
function sg_menuSpread() {
	
	var w = 0;
	var links = $('ul#mainnav li');
	var width = links.parent('ul').width();
	
	links.each(function() {
		w += Math.round($(this).width());
	});
	
	if (w > width) return;
	
	var pad = Math.floor((width-w)/(links.length));
	var leftover = Math.floor(width - (w+(pad*links.length)));

	
	links.each(function(i) {
		if (i == (links.length-1)) pad = pad + leftover;
		$('a',$(this)).css('width',Math.round($(this).width() + pad) + 'px');
		
	});
	
	
}

/** News Ticker Sequence **/
function sgNewsTicker() {
	
	var items = $('#newsticker li');
	var timer = null;
	var len = items.length;
	var h = 32;
	
	if (len == 1) return;
	
	items.each(function(i) {
		$(this).attr("rel",i).hover(
			function() { clearInterval(timer); },
			function() { giddyup(); }
		);					
	});
	
	items.eq(0).addClass('current');
	items.not(":eq(0)").css('top', h + 'px');
	
	// Animate the slider
	var slide = function() {
		
		var current = $('#newsticker li[class="current"]');
		var next = (current.next('li').length > 0) ? current.next('li') : items.eq(0);
		
		current.removeClass('current').animate({ top: '-' + h + 'px' }, 1000, "swing", function() { $(this).css('top',h + 'px'); });
		next.addClass('current').animate({ top:'0' }, 1000, "swing");
		
	}
	
	// Startup the interval
	var giddyup = function() {
		timer = setInterval(function() { slide(); },4500);
	}
	
	giddyup();
}

function sg_last_child() {
	
	if ($.browser.msie) {
		$('#hp-triggers .trigger:last-child, ').addClass('last-kid');
	}
}

$(function() {
	
	// Side Nav Hide Non-active ul's
	var sidenav = $('ul.sideNav');
	$('ul', sidenav).removeClass('sideNav');
	$('li.active > ul', sidenav).show();
	$('li.active > a', sidenav).addClass('current');
	
});