function showMenu(sender) {
	alert(sender);
}

var isMSIE = jQuery.browser['msie'];

function nextStep() {
	var matches = $(this).attr('id').match(/steps-(\d+)-(\d+)/);
	$('#steps-'+matches[1]+'-'+(parseInt(matches[2])+1)).animate({ opacity: 1.0 }, 100.0, nextStep);
}

function showSteps(e)
{
	var containerID = 'steps-'+e.parent().children().index(e);
	var container = $('#'+containerID);
	if (container.length == 0)
	{
		var container = $('<div></div>');
		container.css('position', 'absolute');
		container.css('height', e.offset().top);
		container.css('width', e.width());
		container.css('left', e.position().left);
		container.css('z-index', '0');
		container.attr('id', containerID);
		$('#main').append(container);
	}
	
	if (container.find('*:animated').length > 0) return;
	
	var menuNumber = 0;
	$.each(e.attr('class').split(' '), function(i, val) {
		var matches = val.match(/menu-(\d)/);
		if (matches.length == 2) menuNumber = matches[1];
	});
	
	for (var i=0; i<5; i++) {
		var step = $('<img />');
		if(i%2 == 0) {
			step.attr('src', '/wp-content/themes/feet.ie/images/step-'+menuNumber+'b.png');
			step.css('left', container.width() / 2);
		} else {
			step.attr('src', '/wp-content/themes/feet.ie/images/step-'+menuNumber+'a.png');
			step.css('right', container.width() / 2);
		}
		
		step.css('position', 'absolute');
		step.css('top', ((i*35))+'px');
		step.css('opacity', 0);
		step.attr('id', containerID+'-'+i)
		container.append(step);
	}
	
	$(container.children().get(0)).animate({ opacity: 1.0 }, 100.0, nextStep);
}

function hideSteps(e)
{
	var containerID = 'steps-'+e.parent().children().index(e);
	var container = $('#'+containerID);
	
	//if (container.find('*:animated').length > 0) return;
	
	container.children().stop();
	container.children().animate({ opacity: 0.0 }, 300.0);
}

$(document).ready(function() {
		var config = {    
		     sensitivity: 1,
		     interval: 80,
		     over: function() {
						showSteps($(this));
						
						var submenu = $('.submenu', this);

						var position = $(this).position();
						submenu.css('position', 'absolute');
						submenu.css('top', position.top + $(this).parent().height()+'px');
						submenu.css('left', position.left+'px');
						submenu.css('background-color', $(this).css('background-color'));

						if (isMSIE) {
							submenu.show();
						} else {
							submenu.css('opacity', 0.95);
							submenu.hide();
							submenu.fadeIn(125);
						}
					},
		     timeout: 200,
		     out: function() { 
						hideSteps($(this));
						if (isMSIE)
							$('.submenu', this).hide();
						else
							$('.submenu', this).fadeOut(250);
					}
		};
		
		$('#menu td').hoverIntent( config );
});

