$(function(){
	
    $('#gnav li a').each(function() {
		var liClass = $(this).parent().attr("class");
		$(this).hover(function() {
				$('#gnav').addClass(liClass);
		   }, function() {
				$('#gnav').removeClass(liClass);
		});
	});
});


$(function() {
	rollover('.rollover', '_ov');
//	rollover('.rollover2', '_ov', '_ov', '_ac');
	rollover('#gnav a img', '_ov', '_ov');
	rollover('.concept #ingre a img', '_ov', '_ov');
	rollover('.history #navArea a img', '_ov', '_ov');
	rollover('.msg #msg_nav a img', '_ov', '_ov');
});


function rollover(target, hover, current, focus) {
	$(target).each(function() {
		var isCurrent = current && this.src.match(current + '(\.gif|\.jpg|\.png)([\?].*|$)');
		this.src.match('(\.gif|\.jpg|\.png)([\?].*|$)');
		var ext = RegExp.$1;
		var search = (isCurrent) ? current + ext : ext;
		var replace_over = (isCurrent) ? current + ext : hover + ext;
		if(focus) var replace_down = (isCurrent) ? focus + ext : focus + ext;
		
		var out = this.src;
		var over = this.src.replace(search, replace_over);
		if(focus) var down = this.src.replace(search, replace_down);

		// preload
		new Image().src = over;
		if(focus) new Image().src = down;

		
		$(this).bind('mouseover', function() { this.src = over; })
			.bind('mouseout', function() { this.src = out; });
		
		if(focus) $(this).bind('mousedown', function() { this.src = down; });
			
	});
}
