var substart;

// run this script on every page
$(document).ready(function() {
	$("#nav").hide();
	
	$("#nav>ul>li").mouseenter(function() {
		li = this;
		$("img.navOver", this).stop().fadeTo(250, 1.0, function() {
			$('ul', li).stop().animate({opacity: 1.0, top: substart}, 350, "easeOutCubic");
		});
	})
	.mouseleave(function() {
		$("img.navOver", this).stop().fadeTo(500, 0);
		$ul = $('ul', this);
		$ul.stop().animate({opacity: 0.0, top: substart-$ul.height()/2}, 500);
	}).each(function() {
		$("img.navOver", this).css('opacity', 0);
	});
	
	$(".rollover").onedotRollover();
});



$(window).load(function() {
	$("#nav").show();

	$("#nav>ul>li").each(function() {
		var $ul = $('ul', this);
		var offset = $ul.offset();
		var width = 0;
		
		$('img', this).each(function() {
			width = Math.max(width, $(this).width());
		});
		
		$('a', this).each(function() {
			$(this).css('width', width);
			$(this).css('left', Math.round(($(this).width() - width)/2));
		});
		var height = $ul.height();
		
		
		
		var $letter = $('img.navOver', this);
		var lwidth = $letter.width();
		var lx = $letter.offset().left;
		
		var src = $letter.attr('src');

		if(src.indexOf('home') > 0) {
			substart = 185
		} else if(src.indexOf('t1') > 0) {
			substart = 75;
		} else {
			substart = 120;
		}

		if(lwidth < width) {
			$ul.css({'top': substart-height/2, 'left': Math.round((lwidth - width)/2)});
		} else {
			$ul.css({'top': substart-height/2, 'left': 0, 'width': lwidth});
		}
		
		$ul.css('opacity', 0);
	})
	.find('ul li a').onedotRollover({over_lbl: '-pink'});

});
