var ie6 = $.browser.msie && $.browser.version.substring(0,1) == "6";
var heroCurrent = 0;
var heroInterval = 3000;
if(!ie6) { var heroTimer = setInterval(heroCycle, heroInterval); }

function heroCycle() {
	// increment counter
	heroCurrent++;
	// go back to beginning if we're at end
	if(heroCurrent == 6) { heroCurrent = 0; }
	// change
	heroChange(heroCurrent, true);
}

function heroChange(to, fade) {
	heroCurrent = to;
	// switch image
	if(fade) {
		$("#hero .images .on").fadeOut("slow", function() { $(this).removeClass("on"); });
		$("#hero .images img").eq(to).fadeIn("slow").addClass("on");
	} else {
		$("#hero .images .on").hide().removeClass("on");
		$("#hero .images img").eq(to).show().addClass("on");
	}
	// switch nav (ie6 doesn't always pickup classes and apply them to dd_belatedpng)
	if(ie6) { $("#food li a").css("background-position", "top left"); }
	$("#food li").removeClass("on").eq(heroCurrent).addClass("on");
	if(ie6) { $("#food li.on a").css("background-position", "0 -34px"); }
	
}

$(document).ready(function() {
	$("#food li:first").addClass("on");
	// homepage hero switching
	$("#food li").mouseenter(function() {
		if(!$(this).hasClass("on")) {
			if(!ie6) {
				// stop timer to prevent auto cycling
				clearInterval(heroTimer);
				// move to new
				index = $(this).prevAll("li").length;
				heroChange(index, false);
			} else {
				// ie6 has no auto cycling
				index = $(this).prevAll("li").length;
				heroChange(index, false);
			}
		}
	});
	$("#food li").mouseleave(function() {
		if(!ie6) {
			// start timer again
			clearInterval(heroTimer);
			heroTimer = setInterval(heroCycle, heroInterval);
		}
	});
});
